50 cmd->shouldCloseStdin =
false;
51 cmd->shouldCloseStdout =
false;
52 cmd->shouldCloseStderr =
false;
72 printf(
"shell: empty command in pipeline\n");
95 cmd->shouldCloseStdout =
true;
102 printf(
"shell: out of memory\n");
108 nextCmd->shouldCloseStdin =
true;
114 printf(
"shell: missing filename after <\n");
126 if (
cmd->shouldCloseStdin)
131 cmd->shouldCloseStdin =
true;
139 printf(
"shell: missing filename after >\n");
151 if (
cmd->shouldCloseStdout)
156 cmd->shouldCloseStdout =
true;
164 printf(
"shell: missing filename after 2>\n");
176 if (
cmd->shouldCloseStderr)
181 cmd->shouldCloseStderr =
true;
190 printf(
"shell: out of memory\n");
209 printf(
"shell: pipeline ends with empty command\n");
328 const char** argv =
cmd->argv;
350 printf(
"shell: %s not found\n", argv[0]);
408 if (
cmd->shouldCloseStdin)
411 cmd->shouldCloseStdin =
false;
413 if (
cmd->shouldCloseStdout)
416 cmd->shouldCloseStdout =
false;
418 if (
cmd->shouldCloseStderr)
421 cmd->shouldCloseStderr =
false;
#define MAX_PATH
Maximum length of filepaths.
uint64_t builtin_execute(uint64_t argc, const char **argv)
bool builtin_exists(const char *name)
#define errno
Error number variable.
const char ** argsplit(const char *str, uint64_t maxLen, uint64_t *count)
Standardized argument parsing function.
fd_t dup2(fd_t oldFd, fd_t newFd)
System call for duplicating file descriptors, with a destination.
uint64_t stat(const char *path, stat_t *stat)
System call for retrieving info about a file or directory.
fd_t open(const char *path)
System call for opening files.
#define PIPE_READ
Pipe read end.
uint64_t close(fd_t fd)
System call for closing files.
fd_t dup(fd_t oldFd)
System call for duplicating file descriptors.
#define F(format,...)
Allocates a formatted string on the stack.
size_t read(fd_t fd, void *buffer, size_t count)
System call for reading from files.
#define PIPE_WRITE
Pipe write end.
#define STDOUT_FILENO
Standard output file descriptor.
char * sreadfile(const char *path)
Wrapper for reading an entire file directly into a null-terminated string.
uint64_t open2(const char *path, fd_t fd[2])
System call for opening 2 file descriptors from one file.
#define STDERR_FILENO
Standard error file descriptor.
#define RETRY_EINTR(expr)
Macro to automatically retry a function that returns an integer if it errors and errno == EINTR.
#define STDIN_FILENO
Standard input file descriptor.
@ INODE_DIR
Is a directory.
pid_t spawn(const char **argv, spawn_flags_t flags)
System call for spawning new processes.
@ SPAWN_STDIO_FDS
Only inherit stdin, stdout and stderr from the parent process.
#define NULL
Pointer error value.
#define ERR
Integer error value.
__UINT64_TYPE__ fd_t
A file descriptor.
__UINT64_TYPE__ pid_t
Process Identifier.
static pid_t pipeline_execute_cmd(cmd_t *cmd)
void pipeline_deinit(pipeline_t *pipeline)
void pipeline_wait(pipeline_t *pipeline)
uint64_t pipeline_init(pipeline_t *pipeline, const char *cmdline, fd_t stdin, fd_t stdout, fd_t stderr)
void pipeline_execute(pipeline_t *pipeline)
_PUBLIC int printf(const char *_RESTRICT format,...)
_PUBLIC int fprintf(FILE *_RESTRICT stream, const char *_RESTRICT format,...)
_PUBLIC int snprintf(char *_RESTRICT s, size_t n, const char *_RESTRICT format,...)
_PUBLIC void * malloc(size_t size)
_PUBLIC void free(void *ptr)
_PUBLIC char * strerror(int errnum)
_PUBLIC char * strtok(char *_RESTRICT s1, const char *_RESTRICT s2)
char * strdup(const char *src)
_PUBLIC char * strcpy(char *_RESTRICT s1, const char *_RESTRICT s2)
_PUBLIC int strcmp(const char *s1, const char *s2)
_PUBLIC void * memset(void *s, int c, size_t n)
_PUBLIC char * strchr(const char *s, int c)
itype_t type
The type of the entries inode.