1 #include "std-c-library-functions.h" 2 3 typedef int off_t; 4 typedef unsigned int mode_t; 5 typedef __WCHAR_TYPE__ wchar_t; 6 typedef unsigned int dev_t; 7 typedef unsigned int uid_t; 8 typedef unsigned int gid_t; 9 typedef unsigned long socklen_t; 10 typedef unsigned long int pthread_t; 11 typedef unsigned long time_t; 12 typedef unsigned long clockid_t; 13 typedef __INT64_TYPE__ off64_t; 14 typedef __INT64_TYPE__ fpos_t; 15 16 typedef struct { 17 int a; 18 } DIR; 19 struct stat { 20 int a; 21 }; 22 struct timespec { int x; }; 23 struct timeval { int x; }; 24 struct sockaddr; 25 struct sockaddr_at; 26 struct msghdr; 27 struct utimbuf; 28 struct itimerval; 29 typedef union { 30 int x; 31 } pthread_cond_t; 32 typedef union { 33 int x; 34 } pthread_attr_t; 35 typedef union { 36 int x; 37 } pthread_mutex_t; 38 typedef union { 39 int x; 40 } pthread_mutexattr_t; 41 42 FILE *fopen(const char *restrict pathname, const char *restrict mode); 43 FILE *tmpfile(void); 44 FILE *freopen(const char *restrict pathname, const char *restrict mode, 45 FILE *restrict stream); 46 FILE *fdopen(int fd, const char *mode); 47 int fclose(FILE *stream); 48 int putc(int c, FILE *stream); 49 int fputc(int c, FILE *stream); 50 char *fgets(char *restrict s, int n, FILE *restrict stream); 51 int fputs(const char *restrict s, FILE *restrict stream); 52 int fseek(FILE *stream, long offset, int whence); 53 int fgetpos(FILE *restrict stream, fpos_t *restrict pos); 54 int fsetpos(FILE *stream, const fpos_t *pos); 55 int fflush(FILE *stream); 56 long ftell(FILE *stream); 57 int fileno(FILE *stream); 58 void rewind(FILE *stream); 59 void clearerr(FILE *stream); 60 int feof(FILE *stream); 61 int ferror(FILE *stream); 62 long a64l(const char *str64); 63 char *l64a(long value); 64 int open(const char *path, int oflag, ...); 65 int openat(int fd, const char *path, int oflag, ...); 66 int access(const char *pathname, int amode); 67 int faccessat(int dirfd, const char *pathname, int mode, int flags); 68 int dup(int fildes); 69 int dup2(int fildes1, int filedes2); 70 int fdatasync(int fildes); 71 int fnmatch(const char *pattern, const char *string, int flags); 72 int fsync(int fildes); 73 int truncate(const char *path, off_t length); 74 int symlink(const char *oldpath, const char *newpath); 75 int symlinkat(const char *oldpath, int newdirfd, const char *newpath); 76 int lockf(int fd, int cmd, off_t len); 77 int creat(const char *pathname, mode_t mode); 78 unsigned int sleep(unsigned int seconds); 79 int dirfd(DIR *dirp); 80 unsigned int alarm(unsigned int seconds); 81 int closedir(DIR *dir); 82 char *strdup(const char *s); 83 char *strndup(const char *s, size_t n); 84 wchar_t *wcsdup(const wchar_t *s); 85 int mkstemp(char *template); 86 char *mkdtemp(char *template); 87 char *getcwd(char *buf, size_t size); 88 int mkdir(const char *pathname, mode_t mode); 89 int mkdirat(int dirfd, const char *pathname, mode_t mode); 90 int mknod(const char *pathname, mode_t mode, dev_t dev); 91 int mknodat(int dirfd, const char *pathname, mode_t mode, dev_t dev); 92 int chmod(const char *path, mode_t mode); 93 int fchmodat(int dirfd, const char *pathname, mode_t mode, int flags); 94 int fchmod(int fildes, mode_t mode); 95 int fchownat(int dirfd, const char *pathname, uid_t owner, gid_t group, int flags); 96 int chown(const char *path, uid_t owner, gid_t group); 97 int lchown(const char *path, uid_t owner, gid_t group); 98 int fchown(int fildes, uid_t owner, gid_t group); 99 int rmdir(const char *pathname); 100 int chdir(const char *path); 101 int link(const char *oldpath, const char *newpath); 102 int linkat(int fd1, const char *path1, int fd2, const char *path2, int flag); 103 int unlink(const char *pathname); 104 int unlinkat(int fd, const char *path, int flag); 105 int fstat(int fd, struct stat *statbuf); 106 int stat(const char *restrict path, struct stat *restrict buf); 107 int lstat(const char *restrict path, struct stat *restrict buf); 108 int fstatat(int fd, const char *restrict path, struct stat *restrict buf, int flag); 109 DIR *opendir(const char *name); 110 DIR *fdopendir(int fd); 111 int isatty(int fildes); 112 FILE *popen(const char *command, const char *type); 113 int pclose(FILE *stream); 114 int close(int fildes); 115 long fpathconf(int fildes, int name); 116 long pathconf(const char *path, int name); 117 void rewinddir(DIR *dir); 118 void seekdir(DIR *dirp, long loc); 119 int rand_r(unsigned int *seedp); 120 int fileno(FILE *stream); 121 int fseeko(FILE *stream, off_t offset, int whence); 122 off_t ftello(FILE *stream); 123 void *mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset); 124 void *mmap64(void *addr, size_t length, int prot, int flags, int fd, off64_t offset); 125 int pipe(int fildes[2]); 126 off_t lseek(int fildes, off_t offset, int whence); 127 ssize_t readlink(const char *restrict path, char *restrict buf, size_t bufsize); 128 ssize_t readlinkat(int fd, const char *restrict path, char *restrict buf, size_t bufsize); 129 int renameat(int olddirfd, const char *oldpath, int newdirfd, const char *newpath); 130 char *realpath(const char *restrict file_name, char *restrict resolved_name); 131 int execv(const char *path, char *const argv[]); 132 int execvp(const char *file, char *const argv[]); 133 int getopt(int argc, char *const argv[], const char *optstring); 134 135 // In some libc implementations, sockaddr parameter is a transparent 136 // union of the underlying sockaddr_ pointers instead of being a 137 // pointer to struct sockaddr. 138 // We match that with the joker Irrelevant type. 139 #define __SOCKADDR_ALLTYPES \ 140 __SOCKADDR_ONETYPE(sockaddr) \ 141 __SOCKADDR_ONETYPE(sockaddr_at) 142 #define __SOCKADDR_ONETYPE(type) struct type *restrict __##type##__; 143 typedef union { 144 __SOCKADDR_ALLTYPES 145 } __SOCKADDR_ARG __attribute__((__transparent_union__)); 146 #undef __SOCKADDR_ONETYPE 147 #define __SOCKADDR_ONETYPE(type) const struct type *restrict __##type##__; 148 typedef union { 149 __SOCKADDR_ALLTYPES 150 } __CONST_SOCKADDR_ARG __attribute__((__transparent_union__)); 151 #undef __SOCKADDR_ONETYPE 152 153 int socket(int domain, int type, int protocol); 154 int accept(int socket, __SOCKADDR_ARG address, socklen_t *restrict address_len); 155 int bind(int socket, __CONST_SOCKADDR_ARG address, socklen_t address_len); 156 int getpeername(int socket, __SOCKADDR_ARG address, socklen_t *restrict address_len); 157 int getsockname(int socket, __SOCKADDR_ARG address, socklen_t *restrict address_len); 158 int connect(int socket, __CONST_SOCKADDR_ARG address, socklen_t address_len); 159 ssize_t recvfrom(int socket, void *restrict buffer, size_t length, int flags, __SOCKADDR_ARG address, socklen_t *restrict address_len); 160 ssize_t sendto(int socket, const void *message, size_t length, int flags, __CONST_SOCKADDR_ARG dest_addr, socklen_t dest_len); 161 int listen(int sockfd, int backlog); 162 ssize_t recv(int sockfd, void *buf, size_t len, int flags); 163 ssize_t recvmsg(int sockfd, struct msghdr *msg, int flags); 164 ssize_t sendmsg(int sockfd, const struct msghdr *msg, int flags); 165 int setsockopt(int socket, int level, int option_name, const void *option_value, socklen_t option_len); 166 int getsockopt(int socket, int level, int option_name, void *restrict option_value, socklen_t *restrict option_len); 167 ssize_t send(int sockfd, const void *buf, size_t len, int flags); 168 int socketpair(int domain, int type, int protocol, int sv[2]); 169 int shutdown(int socket, int how); 170 int getnameinfo(const struct sockaddr *restrict sa, socklen_t salen, char *restrict node, socklen_t nodelen, char *restrict service, socklen_t servicelen, int flags); 171 int utime(const char *filename, struct utimbuf *buf); 172 int futimens(int fd, const struct timespec times[2]); 173 int utimensat(int dirfd, const char *pathname, const struct timespec times[2], int flags); 174 int utimes(const char *filename, const struct timeval times[2]); 175 int nanosleep(const struct timespec *rqtp, struct timespec *rmtp); 176 struct tm *localtime(const time_t *tp); 177 struct tm *localtime_r(const time_t *restrict timer, struct tm *restrict result); 178 char *asctime_r(const struct tm *restrict tm, char *restrict buf); 179 char *ctime_r(const time_t *timep, char *buf); 180 struct tm *gmtime_r(const time_t *restrict timer, struct tm *restrict result); 181 struct tm *gmtime(const time_t *tp); 182 int clock_gettime(clockid_t clock_id, struct timespec *tp); 183 int getitimer(int which, struct itimerval *curr_value); 184 185 int pthread_cond_signal(pthread_cond_t *cond); 186 int pthread_cond_broadcast(pthread_cond_t *cond); 187 int pthread_create(pthread_t *restrict thread, const pthread_attr_t *restrict attr, void *(*start_routine)(void *), void *restrict arg); 188 int pthread_attr_destroy(pthread_attr_t *attr); 189 int pthread_attr_init(pthread_attr_t *attr); 190 int pthread_attr_getstacksize(const pthread_attr_t *restrict attr, size_t *restrict stacksize); 191 int pthread_attr_getguardsize(const pthread_attr_t *restrict attr, size_t *restrict guardsize); 192 int pthread_attr_setstacksize(pthread_attr_t *attr, size_t stacksize); 193 int pthread_attr_setguardsize(pthread_attr_t *attr, size_t guardsize); 194 int pthread_mutex_init(pthread_mutex_t *restrict mutex, const pthread_mutexattr_t *restrict attr); 195 int pthread_mutex_destroy(pthread_mutex_t *mutex); 196 int pthread_mutex_lock(pthread_mutex_t *mutex); 197 int pthread_mutex_trylock(pthread_mutex_t *mutex); 198 int pthread_mutex_unlock(pthread_mutex_t *mutex); 199