1 /* $NetBSD: llib-lposix,v 1.3 2025/03/14 06:40:51 rillig Exp $ */ 2 3 /* 4 * Copyright (c) 1994, 1995 Jochen Pohl 5 * All Rights Reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 3. All advertising materials mentioning features or use of this software 16 * must display the following acknowledgement: 17 * This product includes software developed by Jochen Pohl for 18 * The NetBSD Project. 19 * 4. The name of the author may not be used to endorse or promote products 20 * derived from this software without specific prior written permission. 21 * 22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 25 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 */ 33 34 /* LINTLIBRARY */ 35 36 #define _POSIX_SOURCE 37 38 #include <sys/types.h> 39 #include <sys/stat.h> 40 #include <sys/utsname.h> 41 #include <sys/times.h> 42 #include <assert.h> 43 #include <ctype.h> 44 #include <dirent.h> 45 #include <errno.h> 46 #include <fcntl.h> 47 #include <grp.h> 48 #include <locale.h> 49 #include <math.h> 50 #include <pwd.h> 51 #include <setjmp.h> 52 #include <signal.h> 53 #include <stdarg.h> 54 #include <stdio.h> 55 #include <stdlib.h> 56 #include <string.h> 57 #include <termios.h> 58 #include <time.h> 59 #include <unistd.h> 60 #include <utime.h> 61 62 63 /* PROTOLIB1 */ 64 65 66 void (abort)(void); 67 int (abs)(int j); 68 int (access)(const char *path, int amode); 69 double (acos)(double x); 70 unsigned (alarm)(unsigned seconds); 71 char *(asctime)(const struct tm *timeptr); 72 double (asin)(double x); 73 void (__assert)(const char *expression, int line, const char *file); 74 double (atan)(double x); 75 double (atan2)(double y, double x); 76 int (atexit)(void (*func)(void)); 77 double (atof)(const char *nptr); 78 int (atoi)(const char *nptr); 79 long (atol)(const char *nptr); 80 void *(bsearch)(const void *key, const void *base, size_t nmemb, 81 size_t size, int (*compar)(const void *, const void *)); 82 void *(calloc)(size_t nmemb, size_t size); 83 double (ceil)(double x); 84 speed_t (cfgetispeed)(const struct termios *p); 85 speed_t (cfgetospeed)(const struct termios *p); 86 int (cfsetispeed)(struct termios *p, speed_t speed); 87 int (cfsetospeed)(struct termios *p, speed_t speed); 88 int (chdir)(const char *path); 89 int (chmod)(const char *path, mode_t mode); 90 int (chown)(const char *path, uid_t owner, gid_t group); 91 void (clearerr)(FILE *stream); 92 clock_t (clock)(void); 93 int (close)(int fildes); 94 int (closedir)(DIR *dirp); 95 double (cos)(double x); 96 double (cosh)(double x); 97 int (creat)(const char *path, mode_t mode); 98 char *(ctermid)(char *s); 99 char *(ctime)(const time_t *timer); 100 char *(cuserid)(char *s); 101 double (difftime)(time_t time1, time_t time0); 102 div_t (div)(int numer, int denom); 103 int (dup)(int fildes); 104 int (dup2)(int fildes, int fildes2); 105 #ifndef errno 106 int (errno); 107 #endif 108 int (execl)(const char *path, const char *arg, ...); 109 int (execle)(const char *path, const char *arg, ...); 110 int (execlp)(const char *file, const char *arg, ...); 111 int (execv)(const char *path, char *const argv[]); 112 int (execve)(const char *path, char *const argv[], char *const *envp); 113 int (execvp)(const char *file, char *const argv[]); 114 void (exit)(int status); 115 void (_exit)(int status); 116 double (exp)(double x); 117 double (fabs)(double x); 118 int (fclose)(FILE *stream); 119 int (fcntl)(int fildes, int cmd, ...); 120 FILE *(fdopen)(int fildes, const char *type); 121 int (feof)(FILE *stream); 122 int (ferror)(FILE *stream); 123 int (fflush)(FILE *stream); 124 int (fgetc)(FILE *stream); 125 int (fgetpos)(FILE *stream, fpos_t *pos); 126 char *(fgets)(char *s, int n, FILE *stream); 127 int (fileno)(FILE *stream); 128 double (floor)(double x); 129 double (fmod)(double x, double y); 130 FILE *(fopen)(const char *filename, const char *mode); 131 pid_t (fork)(void); 132 long (fpathconf)(int fildes, int name); 133 /* PRINTFLIKE2 */ 134 int (fprintf)(FILE *stream, const char *format, ...); 135 int (fputc)(int c, FILE *stream); 136 int (fputs)(const char *s, FILE *stream); 137 size_t (fread)(void *ptr, size_t size, size_t nmemb, FILE *stream); 138 void (free)(void *ptr); 139 FILE *(freopen)(const char *filename, const char *mode, FILE *stream); 140 double (frepx)(double value, int *exp); 141 /* SCANFLIKE2 */ 142 int (fscanf)(FILE *stream, const char *format, ...); 143 int (fseek)(FILE *stream, long int offset, int whence); 144 int (fsetpos)(FILE *stream, const fpos_t *pos); 145 int (fstat)(int fildes, struct stat *buf); 146 long (ftell)(FILE *stream); 147 size_t (fwrite)(const void *ptr, size_t size, size_t nmemb, FILE *stream); 148 int (getc)(FILE *stream); 149 int (getchar)(void); 150 char *(getcwd)(char *buf, size_t size); 151 gid_t (getegid)(void); 152 char *(getenv)(const char *name); 153 uid_t (geteuid)(void); 154 gid_t (getgid)(void); 155 struct group *(getgrgid)(gid_t gid); 156 struct group *(getgrnam)(const char *name); 157 int (getgroups)(int gidsetsize, gid_t grouplist[]); 158 char *(getlogin)(void); 159 pid_t (getpgrp)(void); 160 pid_t (getpid)(void); 161 pid_t (getppid)(void); 162 struct passwd *(getpwnam)(const char *name); 163 struct passwd *(getpwuid)(uid_t uid); 164 char *(gets)(char *s); 165 uid_t (getuid)(void); 166 struct tm *(gmtime)(const time_t *timer); 167 int (isalnum)(int c); 168 int (isalpha)(int c); 169 int (isatty)(int fildes); 170 int (iscntrl)(int c); 171 int (isdigit)(int c); 172 int (isgraph)(int c); 173 int (islower)(int c); 174 int (isprint)(int c); 175 int (ispunct)(int c); 176 int (isspace)(int c); 177 int (isupper)(int c); 178 int (isxdigit)(int c); 179 int (kill)(pid_t pid, int sig); 180 long (labs)(long j); 181 double (ldexp)(double x, int exp); 182 ldiv_t (ldiv)(long numer, long denom); 183 int (link)(const char *existing, const char *new); 184 struct lconv *(localeconv)(void); 185 struct tm *(localtime)(const time_t *timer); 186 double (log)(double x); 187 double (log10)(double x); 188 void (longjmp)(jmp_buf env, int val); 189 off_t (lseek)(int fildes, off_t offset, int whence); 190 void *(malloc)(size_t size); 191 int (mblen)(const char *s, size_t n); 192 size_t (mbstowcs)(wchar_t *pwcs, const char *s, size_t n); 193 int (mbtowc)(wchar_t *pwc, const char *s, size_t n); 194 void *(memchr)(const void *s, int c, size_t n); 195 int (memcmp)(const void *s1, const void *s2, size_t n); 196 void *(memcpy)(void *s1, const void *s2, size_t n); 197 void *(memmove)(void *s1, const void *s2, size_t n); 198 void *(memset)(void *s, int c, size_t n); 199 int (mkdir)(const char *path, mode_t mode); 200 int (mkfifo)(const char *path, mode_t mode); 201 time_t (mktime)(struct tm *timeptr); 202 double (modf)(double value, double *iptr); 203 int (open)(const char *path, int oflag, ...); 204 DIR *(opendir)(const char *dirname); 205 long (pathconf)(const char *path, int name); 206 int (pause)(void); 207 void (perror)(const char *s); 208 int (pipe)(int fildes[2]); 209 double (pow)(double x, double y); 210 /* PRINTFLIKE1 */ 211 int (printf)(const char *format, ...); 212 int (putc)(int c, FILE *stream); 213 int (putchar)(int c); 214 int (puts)(const char *s); 215 void (qsort)(void *base, size_t nmemb, size_t size, 216 int (*compar)(const void *, const void *)); 217 int (raise)(int sig); 218 int (rand)(void); 219 ssize_t (read)(int fildes, void *buf, size_t nbyte); 220 struct dirent *(readdir)(DIR *dirp); 221 void *(realloc)(void *ptr, size_t size); 222 int (remove)(const char *filename); 223 int (rename)(const char *old, const char *new); 224 void (rewind)(FILE *stream); 225 void (rewinddir)(DIR *dirp); 226 int (rmdir)(const char *path); 227 /* SCANFLIKE1 */ 228 int (scanf)(const char *format, ...); 229 void (setbuf)(FILE *stream, char *buf); 230 int (setgid)(gid_t gid); 231 int (setjmp)(jmp_buf env); 232 char *(setlocale)(int category, const char *locale); 233 int (setpgid)(pid_t pid, pid_t pgid); 234 pid_t (setsid)(void); 235 int (setuid)(uid_t uid); 236 int (setvbuf)(FILE *stream, char *buf, int mode, size_t size); 237 int (sigaction)(int sig, const struct sigaction *act, 238 struct sigaction *oact); 239 int (sigaddset)(sigset_t *set, int signo); 240 int (sigdelset)(sigset_t *set, int signo); 241 int (sigemptyset)(sigset_t *set); 242 int (sigfillset)(sigset_t *set); 243 int (sigismember)(const sigset_t *set, int signo); 244 void (siglongjmp)(sigjmp_buf env, int val); 245 void (*(signal)(int sig, void (*func)(int)))(int); 246 int (sigpending)(sigset_t *set); 247 int (sigprocmask)(int how, const sigset_t *set, sigset_t *oset); 248 int (sigsetjmp)(sigjmp_buf env, int savemask); 249 int (sigsuspend)(const sigset_t *sigmask); 250 double (sin)(double x); 251 double (sinh)(double x); 252 unsigned (sleep)(unsigned seconds); 253 /* PRINTFLIKE2 */ 254 int (sprintf)(char *s, const char *format, ...); 255 double (sqrt)(double x); 256 void (srand)(unsigned seed); 257 /* SCANFLIKE2 */ 258 int (sscanf)(const char *s, const char *format, ...); 259 int (stat)(const char *path, struct stat *buf); 260 char *(strcat)(char *s1, const char *s2); 261 char *(strchr)(const char *s, int c); 262 int (strcmp)(const char *s1, const char *s2); 263 int (strcoll)(const char *s1, const char *s2); 264 char *(strcpy)(char *s1, const char *s2); 265 size_t (strcspn)(const char *s1, const char *s2); 266 char *(strerror)(int errnum); 267 size_t (strftime)(char *s, size_t maxsize, const char *format, 268 const struct tm *timeptr); 269 size_t (strlen)(const char *s); 270 char *(strncat)(char *s1, const char *s2, size_t n); 271 int (strncmp)(const char *s1, const char *s2, size_t n); 272 char *(strncpy)(char *s1, const char *s2, size_t n); 273 char *(strpbrk)(const char *s1, const char *s2); 274 char *(strrchr)(const char *s, int c); 275 size_t (strspn)(const char *s1, const char *s2); 276 char *(strstr)(const char *s1, const char *s2); 277 double (strtod)(const char *nptr, char **endptr); 278 char *(strtok)(char *s1, const char *s2); 279 long (strtol)(const char *nptr, char **endptr, int base); 280 unsigned long (strtoul)(const char *nptr, char **endptr, int base); 281 size_t (strxfrm)(char *s1, const char *s2, size_t n); 282 long (sysconf)(int name); 283 int (system)(const char *string); 284 double (tan)(double x); 285 double (tanh)(double x); 286 int (tcdrain)(int fildes); 287 int (tcflow)(int fildes, int action); 288 int (tcflush)(int fildes, int queue_selector); 289 int (tcgetattr)(int fildes, struct termios *tp); 290 pid_t (tcgetpgrp)(int fildes); 291 int (tcsendbreak)(int fildes, int duration); 292 int (tcsetattr)(int fildes, int options, const struct termios *tp); 293 int (tcsetpgrp)(int fildes, pid_t pgrpid); 294 time_t (time)(time_t *timer); 295 clock_t (times)(struct tms *buffer); 296 FILE *(tmpfile)(void); 297 char *(tmpnam)(char *s); 298 int (tolower)(int c); 299 int (toupper)(int c); 300 char *(ttyname)(int filedes); 301 void (tzset)(void); 302 mode_t (umask)(mode_t cmask); 303 int (uname)(struct utsname *name); 304 int (ungetc)(int c, FILE *stream); 305 int (unlink)(const char *path); 306 int (utime)(const char *path, const struct utimbuf *times); 307 int (vfprintf)(FILE *stream, const char *format, va_list arg); 308 int (vprintf)(const char *format, va_list arg); 309 int (vsprintf)(char *s, const char *format, va_list arg); 310 pid_t (wait)(int *statloc); 311 pid_t (waitpid)(pid_t pid, int *stat_loc, int options); 312 size_t (wcstombs)(char *s, const wchar_t *pwcs, size_t n); 313 int (wctomb)(char *s, wchar_t wchar); 314 ssize_t (write)(int fildes, const void *buf, size_t nbyte); 315