made a clear description of allowed functions in the README.md file

This commit is contained in:
whaffman 2025-02-01 00:57:35 +01:00
parent 8aed9ed592
commit 3e3db88080
2 changed files with 188 additions and 111 deletions

193
README.md
View File

@ -1,61 +1,138 @@
# Minishell # Minishell
## Allowed Functions ## Allowed Functions
/* ### `<fcntl.h>`
* This file lists the functions and system calls used in the minishell project. * `open`
* * `int open(const char *pathname, int flags, ...);`
* Functions and system calls: * Opens a file specified by pathname. The flags argument determines the file access mode and file status flags.
* `char *readline(const char *prompt);` - Reads a line from the terminal. (Header: `<readline/readline.h>`)
* `void rl_clear_history(void);` - Clears the history of lines read. (Header: `<readline/readline.h>`) ### `<dirent.h>`
* `int rl_on_new_line(void);` - Prepares for a new line of input. (Header: `<readline/readline.h>`) * `opendir`
* `int rl_replace_line(const char *text, int clear_undo);` - Replaces the current line with a new one. (Header: `<readline/readline.h>`) * `DIR *opendir(const char *name);`
* `int rl_redisplay(void);` - Redisplays the current input line. (Header: `<readline/readline.h>`) * Opens a directory stream corresponding to the directory name, and returns a pointer to the directory stream.
* `void add_history(const char *line);` - Adds a line to the history. (Header: `<readline/readline.h>`) * `readdir`
* `int printf(const char *format, ...);` - Prints formatted output to stdout. (Header: `<stdio.h>`) * `struct dirent *readdir(DIR *dirp);`
* `void *malloc(size_t size);` - Allocates memory dynamically. (Header: `<stdlib.h>`) * Reads the next directory entry from the directory stream pointed to by dirp.
* `void free(void *ptr);` - Frees dynamically allocated memory. (Header: `<stdlib.h>`) * `closedir`
* `ssize_t write(int fd, const void *buf, size_t count);` - Writes data to a file descriptor. (Header: `<unistd.h>`) * `int closedir(DIR *dirp);`
* `int access(const char *pathname, int mode);` - Checks a file's accessibility. (Header: `<unistd.h>`) * Closes the directory stream associated with dirp.
* `int open(const char *pathname, int flags, ...);` - Opens a file. (Header: `<fcntl.h>`)
* `ssize_t read(int fd, void *buf, size_t count);` - Reads data from a file descriptor. (Header: `<unistd.h>`) ### `<stdlib.h>`
* `int close(int fd);` - Closes a file descriptor. (Header: `<unistd.h>`) * `malloc`
* `pid_t fork(void);` - Creates a new process. (Header: `<unistd.h>`) * `void *malloc(size_t size);`
* `pid_t wait(int *wstatus);` - Waits for a child process to change state. (Header: `<sys/wait.h>`) * Allocates size bytes of memory and returns a pointer to the allocated memory.
* `pid_t waitpid(pid_t pid, int *wstatus, int options);` - Waits for a specific child process to change state. (Header: `<sys/wait.h>`) * `free`
* `pid_t wait3(int *wstatus, int options, struct rusage *rusage);` - Waits for a child process to change state with resource usage statistics. (Header: `<sys/wait.h>`) * `void free(void *ptr);`
* `pid_t wait4(pid_t pid, int *wstatus, int options, struct rusage *rusage);` - Waits for a specific child process to change state with resource usage statistics. (Header: `<sys/wait.h>`) * Frees the memory space pointed to by ptr, which must have been returned by a previous call to malloc.
* `void (*signal(int signum, void (*handler)(int)))(int);` - Sets a signal handler. (Header: `<signal.h>`)
* `int sigaction(int signum, const struct sigaction *act, struct sigaction *oldact);` - Examines and changes a signal action. (Header: `<signal.h>`) ### `<stdio.h>`
* `int sigemptyset(sigset_t *set);` - Initializes an empty signal set. (Header: `<signal.h>`) * `printf`
* `int sigaddset(sigset_t *set, int signum);` - Adds a signal to a signal set. (Header: `<signal.h>`) * `int printf(const char *format, ...);`
* `int kill(pid_t pid, int sig);` - Sends a signal to a process. (Header: `<signal.h>`) * Sends formatted output to stdout.
* `void exit(int status);` - Terminates the calling process. (Header: `<stdlib.h>`)
* `char *getcwd(char *buf, size_t size);` - Gets the current working directory. (Header: `<unistd.h>`) ### `<sys/stat.h>`
* `int chdir(const char *path);` - Changes the current working directory. (Header: `<unistd.h>`) * `stat`
* `int stat(const char *pathname, struct stat *statbuf);` - Gets file status. (Header: `<sys/stat.h>`) * `int stat(const char *pathname, struct stat *statbuf);`
* `int lstat(const char *pathname, struct stat *statbuf);` - Gets file status, not following symbolic links. (Header: `<sys/stat.h>`) * Retrieves information about the file pointed to by pathname and fills in the stat structure.
* `int fstat(int fd, struct stat *statbuf);` - Gets file status of an open file descriptor. (Header: `<sys/stat.h>`) * `lstat`
* `int unlink(const char *pathname);` - Deletes a name from the filesystem. (Header: `<unistd.h>`) * `int lstat(const char *pathname, struct stat *statbuf);`
* `int execve(const char *pathname, char *const argv[], char *const envp[]);` - Executes a program. (Header: `<unistd.h>`) * Similar to stat, but does not follow symbolic links.
* `int dup(int oldfd);` - Duplicates a file descriptor. (Header: `<unistd.h>`) * `fstat`
* `int dup2(int oldfd, int newfd);` - Duplicates a file descriptor to a specific value. (Header: `<unistd.h>`) * `int fstat(int fd, struct stat *statbuf);`
* `int pipe(int pipefd[2]);` - Creates a pipe. (Header: `<unistd.h>`) * Retrieves information about the file referred to by the open file descriptor fd.
* `DIR *opendir(const char *name);` - Opens a directory stream. (Header: `<dirent.h>`)
* `struct dirent *readdir(DIR *dirp);` - Reads a directory entry. (Header: `<dirent.h>`) ### `<sys/wait.h>`
* `int closedir(DIR *dirp);` - Closes a directory stream. (Header: `<dirent.h>`) * `wait`
* `char *strerror(int errnum);` - Returns a string describing an error number. (Header: `<string.h>`) * `pid_t wait(int *wstatus);`
* `void perror(const char *s);` - Prints a description of the last error. (Header: `<stdio.h>`) * Suspends execution of the calling process until one of its children terminates.
* `int isatty(int fd);` - Tests if a file descriptor refers to a terminal. (Header: `<unistd.h>`) * `waitpid`
* `char *ttyname(int fd);` - Returns the name of the terminal associated with a file descriptor. (Header: `<unistd.h>`) * `pid_t waitpid(pid_t pid, int *wstatus, int options);`
* `int ttyslot(void);` - Returns the index of the current user's terminal. (Header: `<unistd.h>`) * Suspends execution of the calling process until the child specified by pid changes state.
* `int ioctl(int fd, unsigned long request, ...);` - Manipulates the underlying device parameters of special files. (Header: `<sys/ioctl.h>`) * `wait3`
* `char *getenv(const char *name);` - Gets an environment variable. (Header: `<stdlib.h>`) * `pid_t wait3(int *wstatus, int options, struct rusage *rusage);`
* `int tcsetattr(int fd, int optional_actions, const struct termios *termios_p);` - Sets the parameters associated with the terminal. (Header: `<termios.h>`) * Similar to wait, but also returns resource usage information.
* `int tcgetattr(int fd, struct termios *termios_p);` - Gets the parameters associated with the terminal. (Header: `<termios.h>`) * `wait4`
* `int tgetent(char *bp, const char *name);` - Loads a terminal entry from the termcap database. (Header: `<term.h>`) * `pid_t wait4(pid_t pid, int *wstatus, int options, struct rusage *rusage);`
* `int tgetflag(const char *id);` - Gets a boolean entry from the termcap database. (Header: `<term.h>`) * Similar to waitpid, but also returns resource usage information.
* `int tgetnum(const char *id);` - Gets a numeric entry from the termcap database. (Header: `<term.h>`)
* `char *tgetstr(const char *id, char **area);` - Gets a string entry from the termcap database. (Header: `<term.h>`) ### `<signal.h>`
* `char *tgoto(const char *cap, int col, int row);` - Computes a cursor movement string. (Header: `<term.h>`) * `signal`
* `int tputs(const char *str, int affcnt, int (*putc)(int));` - Outputs a string with padding. (Header: `<term.h>`) * `void (*signal(int signum, void (*handler)(int)))(int);`
* Sets a function to handle signal signum.
* `sigaction`
* `int sigaction(int signum, const struct sigaction *act, struct sigaction *oldact);`
* Examines and changes the action associated with a specific signal.
* `sigemptyset`
* `int sigemptyset(sigset_t *set);`
* Initializes the signal set pointed to by set to exclude all signals.
* `sigaddset`
* `int sigaddset(sigset_t *set, int signum);`
* Adds the individual signal specified by signum to the signal set pointed to by set.
* `kill`
* `int kill(pid_t pid, int sig);`
* Sends the signal sig to the process specified by pid.
### `<unistd.h>`
* `write`
* `ssize_t write(int fd, const void *buf, size_t count);`
* Writes up to count bytes from the buffer starting at buf to the file referred to by the file descriptor fd.
* `access`
* `int access(const char *pathname, int mode);`
* Checks the file named by pathname for accessibility according to the bit pattern contained in mode.
* `read`
* `ssize_t read(int fd, void *buf, size_t count);`
* Reads up to count bytes from file descriptor fd into the buffer starting at buf.
* `close`
* `int close(int fd);`
* Closes the file descriptor fd.
* `fork`
* `pid_t fork(void);`
* Creates a new process by duplicating the calling process.
### `<readline/readline.h>`
* `readline`
* `char *readline(const char *prompt);`
* Reads a line from the terminal with editing capabilities.
* `rl_clear_history`
* `void rl_clear_history(void);`
* Clears the history of lines read by readline.
* `rl_on_new_line`
* `int rl_on_new_line(void);`
* Resets the state to indicate that a new line of input is being read.
* `rl_replace_line`
* `int rl_replace_line(const char *text, int clear_undo);`
* Replaces the contents of the current line with text.
* `rl_redisplay`
* `int rl_redisplay(void);`
* Redisplays the current input line.
* `add_history`
* `void add_history(const char *line);`
* Adds the line to the history list.
### `<termios.h>`
* `tcsetattr`
* `int tcsetattr(int fd, int optional_actions, const struct termios *termios_p);`
* Sets the parameters associated with the terminal referred to by fd.
* `tcgetattr`
* `int tcgetattr(int fd, struct termios *termios_p);`
* Gets the parameters associated with the terminal referred to by fd.
### `<term.h>`
* `tgetent`
* `int tgetent(char *bp, const char *name);`
* Loads the entry for name from the termcap database.
* `tgetflag`
* `int tgetflag(const char *id);`
* Gets the boolean entry for id from the termcap database.
* `tgetnum`
* `int tgetnum(const char *id);`
* Gets the numeric entry for id from the termcap database.
* `tgetstr`
* `char *tgetstr(const char *id, char **area);`
* Gets the string entry for id from the termcap database.
* `tgoto`
* `char *tgoto(const char *cap, int col, int row);`
* Returns a cursor addressing string for the given capability cap.
* `tputs`
* `int tputs(const char *str, int affcnt, int (*putc)(int));`
* Outputs the string str with padding.

View File

@ -7,141 +7,141 @@
* The following is a list of included headers and the functions or system calls they provide: * The following is a list of included headers and the functions or system calls they provide:
* *
* @headerfile <stdio.h> * @headerfile <stdio.h>
* - printf(const char *format, ...); * - int printf(const char *format, ...);
* - Prints formatted data to stdout. * - Prints formatted data to stdout.
* - perror(const char *s); * - void perror(const char *s);
* - Prints a descriptive error message to stderr. * - Prints a descriptive error message to stderr.
* *
* @headerfile <stdlib.h> * @headerfile <stdlib.h>
* - malloc(size_t size); * - void* malloc(size_t size);
* - Allocates memory dynamically. * - Allocates memory dynamically.
* - free(void *ptr); * - void free(void *ptr);
* - Frees dynamically allocated memory. * - Frees dynamically allocated memory.
* - exit(int status); * - void exit(int status);
* - Terminates the calling process. * - Terminates the calling process.
* - getenv(const char *name); * - char* getenv(const char *name);
* - Retrieves the value of an environment variable. * - Retrieves the value of an environment variable.
* *
* @headerfile <unistd.h> * @headerfile <unistd.h>
* - write(int fd, const void *buf, size_t count); * - ssize_t write(int fd, const void *buf, size_t count);
* - Writes data to a file descriptor. * - Writes data to a file descriptor.
* - access(const char *pathname, int mode); * - int access(const char *pathname, int mode);
* - Checks user's permissions for a file. * - Checks user's permissions for a file.
* - read(int fd, void *buf, size_t count); * - ssize_t read(int fd, void *buf, size_t count);
* - Reads data from a file descriptor. * - Reads data from a file descriptor.
* - close(int fd); * - int close(int fd);
* - Closes a file descriptor. * - Closes a file descriptor.
* - fork(void); * - pid_t fork(void);
* - Creates a new process. * - Creates a new process.
* - getcwd(char *buf, size_t size); * - char* getcwd(char *buf, size_t size);
* - Gets the current working directory. * - Gets the current working directory.
* - chdir(const char *path); * - int chdir(const char *path);
* - Changes the current working directory. * - Changes the current working directory.
* - unlink(const char *pathname); * - int unlink(const char *pathname);
* - Deletes a name from the filesystem. * - Deletes a name from the filesystem.
* - execve(const char *pathname, char *const argv[], char *const envp[]); * - int execve(const char *pathname, char *const argv[], char *const envp[]);
* - Executes a program. * - Executes a program.
* - dup(int oldfd); * - int dup(int oldfd);
* - Duplicates a file descriptor. * - Duplicates a file descriptor.
* - dup2(int oldfd, int newfd); * - int dup2(int oldfd, int newfd);
* - Duplicates a file descriptor to a specific descriptor number. * - Duplicates a file descriptor to a specific descriptor number.
* - pipe(int pipefd[2]); * - int pipe(int pipefd[2]);
* - Creates a pipe. * - Creates a pipe.
* - isatty(int fd); * - int isatty(int fd);
* - Checks if a file descriptor refers to a terminal. * - Checks if a file descriptor refers to a terminal.
* - ttyname(int fd); * - char* ttyname(int fd);
* - Returns the name of the terminal associated with a file descriptor. * - Returns the name of the terminal associated with a file descriptor.
* - ttyslot(void); * - int ttyslot(void);
* - Returns the index of the current terminal. * - Returns the index of the current terminal.
* *
* @headerfile <string.h> * @headerfile <string.h>
* - strerror(int errnum); * - char* strerror(int errnum);
* - Returns a string describing the error number. * - Returns a string describing the error number.
* *
* @headerfile <sys/types.h> * @headerfile <sys/types.h>
* - Required for various system calls and data types. * - Required for various system calls and data types.
* *
* @headerfile <sys/wait.h> * @headerfile <sys/wait.h>
* - wait(int *wstatus); * - pid_t wait(int *wstatus);
* - Waits for a child process to change state. * - Waits for a child process to change state.
* - waitpid(pid_t pid, int *wstatus, int options); * - pid_t waitpid(pid_t pid, int *wstatus, int options);
* - Waits for a specific child process to change state. * - Waits for a specific child process to change state.
* - wait3(int *wstatus, int options, struct rusage *rusage); * - pid_t wait3(int *wstatus, int options, struct rusage *rusage);
* - Waits for a child process to change state with resource usage information. * - Waits for a child process to change state with resource usage information.
* - wait4(pid_t pid, int *wstatus, int options, struct rusage *rusage); * - pid_t wait4(pid_t pid, int *wstatus, int options, struct rusage *rusage);
* - Waits for a specific child process to change state with resource usage information. * - Waits for a specific child process to change state with resource usage information.
* *
* @headerfile <fcntl.h> * @headerfile <fcntl.h>
* - open(const char *pathname, int flags, ...); * - int open(const char *pathname, int flags, ...);
* - Opens a file. * - Opens a file.
* *
* @headerfile <errno.h> * @headerfile <errno.h>
* - Provides access to the errno variable. * - Provides access to the errno variable.
* *
* @headerfile <signal.h> * @headerfile <signal.h>
* - signal(int signum, void (*handler)(int)); * - void (*signal(int signum, void (*handler)(int)))(int);
* - Sets a signal handler. * - Sets a signal handler.
* - sigaction(int signum, const struct sigaction *act, struct sigaction *oldact); * - int sigaction(int signum, const struct sigaction *act, struct sigaction *oldact);
* - Examines and changes a signal action. * - Examines and changes a signal action.
* - sigemptyset(sigset_t *set); * - int sigemptyset(sigset_t *set);
* - Initializes a signal set to empty. * - Initializes a signal set to empty.
* - sigaddset(sigset_t *set, int signum); * - int sigaddset(sigset_t *set, int signum);
* - Adds a signal to a signal set. * - Adds a signal to a signal set.
* - kill(pid_t pid, int sig); * - int kill(pid_t pid, int sig);
* - Sends a signal to a process. * - Sends a signal to a process.
* *
* @headerfile <readline/readline.h> * @headerfile <readline/readline.h>
* - readline(const char *prompt); * - char* readline(const char *prompt);
* - Reads a line of input from the user. * - Reads a line of input from the user.
* - rl_clear_history(void); * - void rl_clear_history(void);
* - Clears the history list. * - Clears the history list.
* - rl_on_new_line(void); * - void rl_on_new_line(void);
* - Informs the readline library that the cursor is on a new line. * - Informs the readline library that the cursor is on a new line.
* - rl_replace_line(const char *text, int clear_undo); * - void rl_replace_line(const char *text, int clear_undo);
* - Replaces the contents of the current line. * - Replaces the contents of the current line.
* - rl_redisplay(void); * - void rl_redisplay(void);
* - Redisplays the current line. * - Redisplays the current line.
* - add_history(const char *line); * - void add_history(const char *line);
* - Adds a line to the history list. * - Adds a line to the history list.
* *
* @headerfile <dirent.h> * @headerfile <dirent.h>
* - opendir(const char *name); * - DIR* opendir(const char *name);
* - Opens a directory stream. * - Opens a directory stream.
* - readdir(DIR *dirp); * - struct dirent* readdir(DIR *dirp);
* - Reads a directory entry. * - Reads a directory entry.
* - closedir(DIR *dirp); * - int closedir(DIR *dirp);
* - Closes a directory stream. * - Closes a directory stream.
* *
* @headerfile <sys/stat.h> * @headerfile <sys/stat.h>
* - stat(const char *pathname, struct stat *statbuf); * - int stat(const char *pathname, struct stat *statbuf);
* - Gets file status. * - Gets file status.
* - lstat(const char *pathname, struct stat *statbuf); * - int lstat(const char *pathname, struct stat *statbuf);
* - Gets file status, not following symbolic links. * - Gets file status, not following symbolic links.
* - fstat(int fd, struct stat *statbuf); * - int fstat(int fd, struct stat *statbuf);
* - Gets file status for an open file descriptor. * - Gets file status for an open file descriptor.
* *
* @headerfile <sys/ioctl.h> * @headerfile <sys/ioctl.h>
* - ioctl(int fd, unsigned long request, ...); * - int ioctl(int fd, unsigned long request, ...);
* - Manipulates the underlying device parameters of special files. * - Manipulates the underlying device parameters of special files.
* *
* @headerfile <termios.h> * @headerfile <termios.h>
* - tcsetattr(int fd, int optional_actions, const struct termios *termios_p); * - int tcsetattr(int fd, int optional_actions, const struct termios *termios_p);
* - Sets the parameters associated with the terminal. * - Sets the parameters associated with the terminal.
* - tcgetattr(int fd, struct termios *termios_p); * - int tcgetattr(int fd, struct termios *termios_p);
* - Gets the parameters associated with the terminal. * - Gets the parameters associated with the terminal.
* *
* @headerfile <term.h> * @headerfile <term.h>
* - tgetent(char *bp, const char *name); * - int tgetent(char *bp, const char *name);
* - Loads the terminal entry for a given terminal name. * - Loads the terminal entry for a given terminal name.
* - tgetflag(const char *id); * - int tgetflag(const char *id);
* - Gets the boolean value of a terminal capability. * - Gets the boolean value of a terminal capability.
* - tgetnum(const char *id); * - int tgetnum(const char *id);
* - Gets the numeric value of a terminal capability. * - Gets the numeric value of a terminal capability.
* - tgetstr(const char *id, char **area); * - char* tgetstr(const char *id, char **area);
* - Gets the string value of a terminal capability. * - Gets the string value of a terminal capability.
* - tgoto(const char *cap, int col, int row); * - char* tgoto(const char *cap, int col, int row);
* - Computes a cursor movement string. * - Computes a cursor movement string.
* - tputs(const char *str, int affcnt, int (*putc)(int)); * - int tputs(const char *str, int affcnt, int (*putc)(int));
* - Outputs a string with padding. * - Outputs a string with padding.
*/ */
#ifndef MINISHELL_H #ifndef MINISHELL_H