11.3Srillig/* $NetBSD: llib-lposix,v 1.3 2025/03/14 06:40:51 rillig Exp $ */ 21.2Scgd 31.1Scgd/* 41.1Scgd * Copyright (c) 1994, 1995 Jochen Pohl 51.1Scgd * All Rights Reserved. 61.1Scgd * 71.1Scgd * Redistribution and use in source and binary forms, with or without 81.1Scgd * modification, are permitted provided that the following conditions 91.1Scgd * are met: 101.1Scgd * 1. Redistributions of source code must retain the above copyright 111.1Scgd * notice, this list of conditions and the following disclaimer. 121.1Scgd * 2. Redistributions in binary form must reproduce the above copyright 131.1Scgd * notice, this list of conditions and the following disclaimer in the 141.1Scgd * documentation and/or other materials provided with the distribution. 151.1Scgd * 3. All advertising materials mentioning features or use of this software 161.1Scgd * must display the following acknowledgement: 171.1Scgd * This product includes software developed by Jochen Pohl for 181.1Scgd * The NetBSD Project. 191.1Scgd * 4. The name of the author may not be used to endorse or promote products 201.1Scgd * derived from this software without specific prior written permission. 211.1Scgd * 221.1Scgd * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 231.1Scgd * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 241.1Scgd * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 251.1Scgd * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 261.1Scgd * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 271.1Scgd * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 281.1Scgd * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 291.1Scgd * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 301.1Scgd * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 311.1Scgd * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 321.1Scgd */ 331.1Scgd 341.1Scgd/* LINTLIBRARY */ 351.1Scgd 361.1Scgd#define _POSIX_SOURCE 371.1Scgd 381.1Scgd#include <sys/types.h> 391.1Scgd#include <sys/stat.h> 401.1Scgd#include <sys/utsname.h> 411.1Scgd#include <sys/times.h> 421.1Scgd#include <assert.h> 431.3Srillig#include <ctype.h> 441.1Scgd#include <dirent.h> 451.3Srillig#include <errno.h> 461.1Scgd#include <fcntl.h> 471.1Scgd#include <grp.h> 481.3Srillig#include <locale.h> 491.3Srillig#include <math.h> 501.1Scgd#include <pwd.h> 511.3Srillig#include <setjmp.h> 521.1Scgd#include <signal.h> 531.3Srillig#include <stdarg.h> 541.3Srillig#include <stdio.h> 551.3Srillig#include <stdlib.h> 561.1Scgd#include <string.h> 571.3Srillig#include <termios.h> 581.3Srillig#include <time.h> 591.3Srillig#include <unistd.h> 601.1Scgd#include <utime.h> 611.1Scgd 621.1Scgd 631.1Scgd/* PROTOLIB1 */ 641.1Scgd 651.1Scgd 661.1Scgdvoid (abort)(void); 671.1Scgdint (abs)(int j); 681.1Scgdint (access)(const char *path, int amode); 691.1Scgddouble (acos)(double x); 701.1Scgdunsigned (alarm)(unsigned seconds); 711.1Scgdchar *(asctime)(const struct tm *timeptr); 721.1Scgddouble (asin)(double x); 731.1Scgdvoid (__assert)(const char *expression, int line, const char *file); 741.1Scgddouble (atan)(double x); 751.1Scgddouble (atan2)(double y, double x); 761.1Scgdint (atexit)(void (*func)(void)); 771.1Scgddouble (atof)(const char *nptr); 781.1Scgdint (atoi)(const char *nptr); 791.1Scgdlong (atol)(const char *nptr); 801.1Scgdvoid *(bsearch)(const void *key, const void *base, size_t nmemb, 811.1Scgd size_t size, int (*compar)(const void *, const void *)); 821.1Scgdvoid *(calloc)(size_t nmemb, size_t size); 831.1Scgddouble (ceil)(double x); 841.1Scgdspeed_t (cfgetispeed)(const struct termios *p); 851.1Scgdspeed_t (cfgetospeed)(const struct termios *p); 861.1Scgdint (cfsetispeed)(struct termios *p, speed_t speed); 871.1Scgdint (cfsetospeed)(struct termios *p, speed_t speed); 881.1Scgdint (chdir)(const char *path); 891.1Scgdint (chmod)(const char *path, mode_t mode); 901.1Scgdint (chown)(const char *path, uid_t owner, gid_t group); 911.1Scgdvoid (clearerr)(FILE *stream); 921.1Scgdclock_t (clock)(void); 931.1Scgdint (close)(int fildes); 941.1Scgdint (closedir)(DIR *dirp); 951.1Scgddouble (cos)(double x); 961.1Scgddouble (cosh)(double x); 971.1Scgdint (creat)(const char *path, mode_t mode); 981.1Scgdchar *(ctermid)(char *s); 991.1Scgdchar *(ctime)(const time_t *timer); 1001.1Scgdchar *(cuserid)(char *s); 1011.1Scgddouble (difftime)(time_t time1, time_t time0); 1021.1Scgddiv_t (div)(int numer, int denom); 1031.1Scgdint (dup)(int fildes); 1041.1Scgdint (dup2)(int fildes, int fildes2); 1051.3Srillig#ifndef errno 1061.1Scgdint (errno); 1071.3Srillig#endif 1081.1Scgdint (execl)(const char *path, const char *arg, ...); 1091.1Scgdint (execle)(const char *path, const char *arg, ...); 1101.1Scgdint (execlp)(const char *file, const char *arg, ...); 1111.1Scgdint (execv)(const char *path, char *const argv[]); 1121.1Scgdint (execve)(const char *path, char *const argv[], char *const *envp); 1131.1Scgdint (execvp)(const char *file, char *const argv[]); 1141.1Scgdvoid (exit)(int status); 1151.1Scgdvoid (_exit)(int status); 1161.1Scgddouble (exp)(double x); 1171.1Scgddouble (fabs)(double x); 1181.1Scgdint (fclose)(FILE *stream); 1191.1Scgdint (fcntl)(int fildes, int cmd, ...); 1201.1ScgdFILE *(fdopen)(int fildes, const char *type); 1211.1Scgdint (feof)(FILE *stream); 1221.1Scgdint (ferror)(FILE *stream); 1231.1Scgdint (fflush)(FILE *stream); 1241.1Scgdint (fgetc)(FILE *stream); 1251.1Scgdint (fgetpos)(FILE *stream, fpos_t *pos); 1261.1Scgdchar *(fgets)(char *s, int n, FILE *stream); 1271.1Scgdint (fileno)(FILE *stream); 1281.1Scgddouble (floor)(double x); 1291.1Scgddouble (fmod)(double x, double y); 1301.1ScgdFILE *(fopen)(const char *filename, const char *mode); 1311.1Scgdpid_t (fork)(void); 1321.1Scgdlong (fpathconf)(int fildes, int name); 1331.1Scgd/* PRINTFLIKE2 */ 1341.1Scgdint (fprintf)(FILE *stream, const char *format, ...); 1351.1Scgdint (fputc)(int c, FILE *stream); 1361.1Scgdint (fputs)(const char *s, FILE *stream); 1371.1Scgdsize_t (fread)(void *ptr, size_t size, size_t nmemb, FILE *stream); 1381.1Scgdvoid (free)(void *ptr); 1391.1ScgdFILE *(freopen)(const char *filename, const char *mode, FILE *stream); 1401.1Scgddouble (frepx)(double value, int *exp); 1411.1Scgd/* SCANFLIKE2 */ 1421.1Scgdint (fscanf)(FILE *stream, const char *format, ...); 1431.1Scgdint (fseek)(FILE *stream, long int offset, int whence); 1441.1Scgdint (fsetpos)(FILE *stream, const fpos_t *pos); 1451.1Scgdint (fstat)(int fildes, struct stat *buf); 1461.1Scgdlong (ftell)(FILE *stream); 1471.1Scgdsize_t (fwrite)(const void *ptr, size_t size, size_t nmemb, FILE *stream); 1481.1Scgdint (getc)(FILE *stream); 1491.1Scgdint (getchar)(void); 1501.1Scgdchar *(getcwd)(char *buf, size_t size); 1511.1Scgdgid_t (getegid)(void); 1521.1Scgdchar *(getenv)(const char *name); 1531.1Scgduid_t (geteuid)(void); 1541.1Scgdgid_t (getgid)(void); 1551.1Scgdstruct group *(getgrgid)(gid_t gid); 1561.1Scgdstruct group *(getgrnam)(const char *name); 1571.1Scgdint (getgroups)(int gidsetsize, gid_t grouplist[]); 1581.1Scgdchar *(getlogin)(void); 1591.1Scgdpid_t (getpgrp)(void); 1601.1Scgdpid_t (getpid)(void); 1611.1Scgdpid_t (getppid)(void); 1621.1Scgdstruct passwd *(getpwnam)(const char *name); 1631.1Scgdstruct passwd *(getpwuid)(uid_t uid); 1641.1Scgdchar *(gets)(char *s); 1651.1Scgduid_t (getuid)(void); 1661.1Scgdstruct tm *(gmtime)(const time_t *timer); 1671.1Scgdint (isalnum)(int c); 1681.1Scgdint (isalpha)(int c); 1691.1Scgdint (isatty)(int fildes); 1701.1Scgdint (iscntrl)(int c); 1711.1Scgdint (isdigit)(int c); 1721.1Scgdint (isgraph)(int c); 1731.1Scgdint (islower)(int c); 1741.1Scgdint (isprint)(int c); 1751.1Scgdint (ispunct)(int c); 1761.1Scgdint (isspace)(int c); 1771.1Scgdint (isupper)(int c); 1781.1Scgdint (isxdigit)(int c); 1791.1Scgdint (kill)(pid_t pid, int sig); 1801.1Scgdlong (labs)(long j); 1811.1Scgddouble (ldexp)(double x, int exp); 1821.1Scgdldiv_t (ldiv)(long numer, long denom); 1831.1Scgdint (link)(const char *existing, const char *new); 1841.1Scgdstruct lconv *(localeconv)(void); 1851.1Scgdstruct tm *(localtime)(const time_t *timer); 1861.1Scgddouble (log)(double x); 1871.1Scgddouble (log10)(double x); 1881.1Scgdvoid (longjmp)(jmp_buf env, int val); 1891.1Scgdoff_t (lseek)(int fildes, off_t offset, int whence); 1901.1Scgdvoid *(malloc)(size_t size); 1911.1Scgdint (mblen)(const char *s, size_t n); 1921.1Scgdsize_t (mbstowcs)(wchar_t *pwcs, const char *s, size_t n); 1931.1Scgdint (mbtowc)(wchar_t *pwc, const char *s, size_t n); 1941.1Scgdvoid *(memchr)(const void *s, int c, size_t n); 1951.1Scgdint (memcmp)(const void *s1, const void *s2, size_t n); 1961.1Scgdvoid *(memcpy)(void *s1, const void *s2, size_t n); 1971.1Scgdvoid *(memmove)(void *s1, const void *s2, size_t n); 1981.1Scgdvoid *(memset)(void *s, int c, size_t n); 1991.1Scgdint (mkdir)(const char *path, mode_t mode); 2001.1Scgdint (mkfifo)(const char *path, mode_t mode); 2011.1Scgdtime_t (mktime)(struct tm *timeptr); 2021.1Scgddouble (modf)(double value, double *iptr); 2031.1Scgdint (open)(const char *path, int oflag, ...); 2041.1ScgdDIR *(opendir)(const char *dirname); 2051.1Scgdlong (pathconf)(const char *path, int name); 2061.1Scgdint (pause)(void); 2071.1Scgdvoid (perror)(const char *s); 2081.1Scgdint (pipe)(int fildes[2]); 2091.1Scgddouble (pow)(double x, double y); 2101.1Scgd/* PRINTFLIKE1 */ 2111.1Scgdint (printf)(const char *format, ...); 2121.1Scgdint (putc)(int c, FILE *stream); 2131.1Scgdint (putchar)(int c); 2141.1Scgdint (puts)(const char *s); 2151.1Scgdvoid (qsort)(void *base, size_t nmemb, size_t size, 2161.1Scgd int (*compar)(const void *, const void *)); 2171.1Scgdint (raise)(int sig); 2181.1Scgdint (rand)(void); 2191.1Scgdssize_t (read)(int fildes, void *buf, size_t nbyte); 2201.1Scgdstruct dirent *(readdir)(DIR *dirp); 2211.1Scgdvoid *(realloc)(void *ptr, size_t size); 2221.1Scgdint (remove)(const char *filename); 2231.1Scgdint (rename)(const char *old, const char *new); 2241.1Scgdvoid (rewind)(FILE *stream); 2251.1Scgdvoid (rewinddir)(DIR *dirp); 2261.1Scgdint (rmdir)(const char *path); 2271.1Scgd/* SCANFLIKE1 */ 2281.1Scgdint (scanf)(const char *format, ...); 2291.1Scgdvoid (setbuf)(FILE *stream, char *buf); 2301.1Scgdint (setgid)(gid_t gid); 2311.1Scgdint (setjmp)(jmp_buf env); 2321.1Scgdchar *(setlocale)(int category, const char *locale); 2331.1Scgdint (setpgid)(pid_t pid, pid_t pgid); 2341.1Scgdpid_t (setsid)(void); 2351.1Scgdint (setuid)(uid_t uid); 2361.1Scgdint (setvbuf)(FILE *stream, char *buf, int mode, size_t size); 2371.1Scgdint (sigaction)(int sig, const struct sigaction *act, 2381.1Scgd struct sigaction *oact); 2391.1Scgdint (sigaddset)(sigset_t *set, int signo); 2401.1Scgdint (sigdelset)(sigset_t *set, int signo); 2411.1Scgdint (sigemptyset)(sigset_t *set); 2421.1Scgdint (sigfillset)(sigset_t *set); 2431.1Scgdint (sigismember)(const sigset_t *set, int signo); 2441.1Scgdvoid (siglongjmp)(sigjmp_buf env, int val); 2451.1Scgdvoid (*(signal)(int sig, void (*func)(int)))(int); 2461.1Scgdint (sigpending)(sigset_t *set); 2471.1Scgdint (sigprocmask)(int how, const sigset_t *set, sigset_t *oset); 2481.1Scgdint (sigsetjmp)(sigjmp_buf env, int savemask); 2491.1Scgdint (sigsuspend)(const sigset_t *sigmask); 2501.1Scgddouble (sin)(double x); 2511.1Scgddouble (sinh)(double x); 2521.1Scgdunsigned (sleep)(unsigned seconds); 2531.1Scgd/* PRINTFLIKE2 */ 2541.1Scgdint (sprintf)(char *s, const char *format, ...); 2551.1Scgddouble (sqrt)(double x); 2561.1Scgdvoid (srand)(unsigned seed); 2571.1Scgd/* SCANFLIKE2 */ 2581.1Scgdint (sscanf)(const char *s, const char *format, ...); 2591.1Scgdint (stat)(const char *path, struct stat *buf); 2601.1Scgdchar *(strcat)(char *s1, const char *s2); 2611.1Scgdchar *(strchr)(const char *s, int c); 2621.1Scgdint (strcmp)(const char *s1, const char *s2); 2631.1Scgdint (strcoll)(const char *s1, const char *s2); 2641.1Scgdchar *(strcpy)(char *s1, const char *s2); 2651.1Scgdsize_t (strcspn)(const char *s1, const char *s2); 2661.1Scgdchar *(strerror)(int errnum); 2671.1Scgdsize_t (strftime)(char *s, size_t maxsize, const char *format, 2681.1Scgd const struct tm *timeptr); 2691.1Scgdsize_t (strlen)(const char *s); 2701.1Scgdchar *(strncat)(char *s1, const char *s2, size_t n); 2711.1Scgdint (strncmp)(const char *s1, const char *s2, size_t n); 2721.1Scgdchar *(strncpy)(char *s1, const char *s2, size_t n); 2731.1Scgdchar *(strpbrk)(const char *s1, const char *s2); 2741.1Scgdchar *(strrchr)(const char *s, int c); 2751.1Scgdsize_t (strspn)(const char *s1, const char *s2); 2761.1Scgdchar *(strstr)(const char *s1, const char *s2); 2771.1Scgddouble (strtod)(const char *nptr, char **endptr); 2781.1Scgdchar *(strtok)(char *s1, const char *s2); 2791.1Scgdlong (strtol)(const char *nptr, char **endptr, int base); 2801.1Scgdunsigned long (strtoul)(const char *nptr, char **endptr, int base); 2811.1Scgdsize_t (strxfrm)(char *s1, const char *s2, size_t n); 2821.1Scgdlong (sysconf)(int name); 2831.1Scgdint (system)(const char *string); 2841.1Scgddouble (tan)(double x); 2851.1Scgddouble (tanh)(double x); 2861.1Scgdint (tcdrain)(int fildes); 2871.1Scgdint (tcflow)(int fildes, int action); 2881.1Scgdint (tcflush)(int fildes, int queue_selector); 2891.1Scgdint (tcgetattr)(int fildes, struct termios *tp); 2901.1Scgdpid_t (tcgetpgrp)(int fildes); 2911.1Scgdint (tcsendbreak)(int fildes, int duration); 2921.1Scgdint (tcsetattr)(int fildes, int options, const struct termios *tp); 2931.1Scgdint (tcsetpgrp)(int fildes, pid_t pgrpid); 2941.1Scgdtime_t (time)(time_t *timer); 2951.1Scgdclock_t (times)(struct tms *buffer); 2961.1ScgdFILE *(tmpfile)(void); 2971.1Scgdchar *(tmpnam)(char *s); 2981.1Scgdint (tolower)(int c); 2991.1Scgdint (toupper)(int c); 3001.1Scgdchar *(ttyname)(int filedes); 3011.1Scgdvoid (tzset)(void); 3021.1Scgdmode_t (umask)(mode_t cmask); 3031.1Scgdint (uname)(struct utsname *name); 3041.1Scgdint (ungetc)(int c, FILE *stream); 3051.1Scgdint (unlink)(const char *path); 3061.1Scgdint (utime)(const char *path, const struct utimbuf *times); 3071.1Scgdint (vfprintf)(FILE *stream, const char *format, va_list arg); 3081.1Scgdint (vprintf)(const char *format, va_list arg); 3091.1Scgdint (vsprintf)(char *s, const char *format, va_list arg); 3101.1Scgdpid_t (wait)(int *statloc); 3111.1Scgdpid_t (waitpid)(pid_t pid, int *stat_loc, int options); 3121.1Scgdsize_t (wcstombs)(char *s, const wchar_t *pwcs, size_t n); 3131.1Scgdint (wctomb)(char *s, wchar_t wchar); 3141.1Scgdssize_t (write)(int fildes, const void *buf, size_t nbyte); 315