summaryrefslogtreecommitdiff
path: root/include/unistd.h
diff options
context:
space:
mode:
authorDanny Holman <dholman@gymli.org>2024-06-05 13:47:01 -0500
committerDanny Holman <dholman@gymli.org>2024-06-05 13:47:01 -0500
commit5db066eb5184cc45e7634838b5b0b8c67cb2ae25 (patch)
tree9201570bb47cf57cd41f7efc8bf764b3ec70b802 /include/unistd.h
parente5aff92e72a0d0e1c18ddaab80b2efe370f04588 (diff)
libc: create a skeleton libc and build targetsHEADmaster
Create build targets for a skeleton libc that only includes enough functionality to get a cross compiler running. Signed-off-by: Danny Holman <dholman@gymli.org>
Diffstat (limited to 'include/unistd.h')
-rw-r--r--include/unistd.h143
1 files changed, 143 insertions, 0 deletions
diff --git a/include/unistd.h b/include/unistd.h
new file mode 100644
index 0000000..8c7eae4
--- /dev/null
+++ b/include/unistd.h
@@ -0,0 +1,143 @@
+#ifndef UNISTD_H
+#define UNISTD_H
+
+#include <sys/types.h>
+#include <stdint.h>
+#include <stddef.h>
+
+#define STDIN_FILENO 0
+#define STDOUT_FILENO 1
+#define STDERR_FILENO 2
+
+#define SEEK_SET 0
+#define SEEK_CUR 1
+#define SEEK_END 2
+#define SEEK_DATA 3
+#define SEEK_HOLE 4
+
+#define NULL ((void*)0)
+
+#define F_OK 0
+#define R_OK 4
+#define W_OK 2
+#define X_OK 1
+
+int pipe();
+int pipe2();
+int close(int fildes);
+int dup(int fildes);
+int dup2();
+int dup3();
+off_t lseek();
+int fsync();
+int fdatasync();
+
+ssize_t read(int fildes, void *buf, size_t nbyte);
+ssize_t write(int fildes, const void *buf, size_t nbyte);
+ssize_t pread(int fildes, void *buf, size_t nbyte, off_t offset);
+ssize_t pwrite(int fildes, const void *buf, size_t nbyte, off_t offset);
+
+int chown(const char *path, uid_t owner, gid_t group);
+int fchown(int fildes, uid_t owner, gid_t group);
+int lchown(const char *path, uid_t owner, gid_t group);
+int fchownat(int fildes, const char *path, uid_t owner, gid_t group);
+
+int link(const char *target, const char *lpath);
+int linkat(int target_fd, const char *tpath, int link_fd, const char *lpath);
+int symlink(const char *target, const char *lpath);
+int symlinkat(const char *target, int fildes, const char *lpath);
+ssize_t readlink(const char* __restrict path, char* __restrict buf, size_t bufsz);
+ssize_t readlinkat(int fildes, const char* __restrict path, char* __restrict buf, size_t bufsz);
+int unlink(const char *lpath);
+int unlinkat(int fildes, const char *lpath, int flag);
+int rmdir(const char *path);
+int truncate(const char *path, off_t length);
+int ftruncate(int fildes, off_t length);
+
+int access(const char *path, int amode);
+int faccessat(int fildes, const char *path, int amode, int flag);
+
+int chdir(const char *path);
+int fchdir(int fildes);
+char* getcwd(char *buf, size_t bufsz);
+
+unsigned int alarm(unsigned int seconds);
+unsigned int sleep(unsigned int seconds);
+unsigned int ualarm(useconds_t usec);
+unsigned int usleep(useconds_t usec);
+int pause(void);
+
+pid_t fork(void);
+pid_t vfork(void);
+void _exit(int status);
+int execve(const char *pathname, char* const argv[], char* const envp[]);
+int execv(const char *pathname, char* const argv[]);
+int execle(const char *pathname, const char *argv, ...);
+int execl(const char *pathname, const char *argv, ...);
+int execvp(const char *pathname, char* const argv[]);
+int execvpe(const char *pathname, char* const argv[], char* const envp[]);
+int execlp(const char *pathname, char* const argv[], ...);
+int fexecve(int fildes, char* const argv[], char* const envp[]);
+
+pid_t getpid(void);
+pid_t getppid(void);
+pid_t getpgrp(void);
+pid_t getpgid(pid_t);
+int setpgid(pid_t pid, pid_t pgid);
+pid_t setsid(void);
+pid_t getsid(pid_t pid);
+char* ttyname(int fildes);
+int ttyname_r(int fildes, char *buf, size_t bufsz);
+int isatty(int fildes);
+pid_t tcgetpgrp(int fildes);
+
+uid_t getuid(void);
+uid_t geteuid(void);
+gid_t getgid(void);
+gid_t getegid(void);
+int getgroups(int gidsetsize, gid_t grouplist[]);
+int setuid(uid_t uid);
+int seteuid(uid_t euid);
+int setgid(gid_t gid);
+int setegid(gid_t egid);
+
+char* getlogin(void);
+int getlogin_r(char *buf, size_t bufsz);
+char* ctermid(char *buf);
+
+long int pathconf(const char *path, int name);
+long int fpathconf(int fildes, int name);
+long int sysconf(int name);
+size_t confstr(int name, char *buf, size_t bufsz);
+
+int setreuid(uid_t ruid, uid_t euid);
+int setregid(gid_t rgid, gid_t egid);
+int lockf(int fildes, int op, off_t length);
+
+int nice(int incr);
+void sync(void);
+pid_t setpgrp(void);
+void swab(const void* __restrict from, void* __restrict to, ssize_t n);
+
+int brk(void *addr);
+void* sbrk(intptr_t incr);
+
+int vhangup(void);
+int chroot(const char *path);
+int getpagesize(void);
+int getdtablesize(void);
+
+int gethostname(char *buf, size_t bufsz);
+int sethostname(const char *name, size_t len);
+int getdomainname(char *buf, size_t bufsz);
+int setdomainname(const char *name, size_t len);
+int daemon(int nochdir, int noclose);
+
+char* getusershell(void);
+void setusershell(void);
+void endusershell(void);
+
+int acct(const char *path);
+int getentropy(void *buffer, size_t bufsz);
+
+#endif