1 /* $NetBSD: llib-lstdc,v 1.4 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 _ANSI_SOURCE 37 38 #include <assert.h> 39 #include <ctype.h> 40 #include <errno.h> 41 #include <locale.h> 42 #include <math.h> 43 #include <setjmp.h> 44 #include <signal.h> 45 #include <stdarg.h> 46 #include <stddef.h> 47 #include <stdio.h> 48 #include <stdlib.h> 49 #include <string.h> 50 #include <time.h> 51 52 /* PROTOLIB1 */ 53 54 /* 55 * assert.h 56 */ 57 #ifdef __NetBSD__ 58 void (__assert)(const char *expression, int line, const char *file); 59 #else 60 void (assert)(int expression); 61 #endif 62 63 /* 64 * ctype.h 65 */ 66 int (isalnum)(int c); 67 int (isalpha)(int c); 68 int (iscntrl)(int c); 69 int (isdigit)(int c); 70 int (isgraph)(int c); 71 int (islower)(int c); 72 int (isprint)(int c); 73 int (ispunct)(int c); 74 int (isspace)(int c); 75 int (isupper)(int c); 76 int (isxdigit)(int c); 77 int (tolower)(int c); 78 int (toupper)(int c); 79 80 /* 81 * errno.h 82 */ 83 #ifndef errno 84 int (errno); 85 #endif 86 87 /* 88 * locale.h 89 */ 90 char *(setlocale)(int category, const char *locale); 91 struct lconv *(localeconv)(void); 92 93 /* 94 * math.h 95 */ 96 double (acos)(double x); 97 double (asin)(double x); 98 double (atan)(double x); 99 double (atan2)(double y, double x); 100 double (cos)(double x); 101 double (sin)(double x); 102 double (tan)(double x); 103 double (cosh)(double x); 104 double (sinh)(double x); 105 double (tanh)(double x); 106 double (exp)(double x); 107 double (frexp)(double value, int *exp); 108 double (ldexp)(double x, int exp); 109 double (log)(double x); 110 double (log10)(double x); 111 double (modf)(double value, double *iptr); 112 double (pow)(double x, double y); 113 double (sqrt)(double x); 114 double (ceil)(double x); 115 double (fabs)(double x); 116 double (floor)(double x); 117 double (fmod)(double x, double y); 118 119 /* 120 * setjmp.h 121 */ 122 int (setjmp)(jmp_buf env); 123 void (longjmp)(jmp_buf env, int val); 124 125 /* 126 * signal.h 127 */ 128 void (*(signal)(int sig, void (*func)(int)))(int); 129 int (raise)(int sig); 130 131 /* 132 * stdio.h 133 */ 134 int (remove)(const char *filename); 135 int (rename)(const char *old, const char *new); 136 FILE *(tmpfile)(void); 137 char *(tmpnam)(char *s); 138 int (fclose)(FILE *stream); 139 int (fflush)(FILE *stream); 140 FILE *(fopen)(const char *filename, const char *mode); 141 FILE *(freopen)(const char *filename, const char *mode, FILE *stream); 142 void (setbuf)(FILE *stream, char *buf); 143 int (setvbuf)(FILE *stream, char *buf, int mode, size_t size); 144 /* PRINTFLIKE2 */ 145 int (fprintf)(FILE *stream, const char *format, ...); 146 /* SCANFLIKE2 */ 147 int (fscanf)(FILE *stream, const char *format, ...); 148 /* PRINTFLIKE1 */ 149 int (printf)(const char *format, ...); 150 /* SCANFLIKE1 */ 151 int (scanf)(const char *format, ...); 152 /* PRINTFLIKE2 */ 153 int (sprintf)(char *s, const char *format, ...); 154 /* SCANFLIKE2 */ 155 int (sscanf)(const char *s, const char *format, ...); 156 int (vfprintf)(FILE *stream, const char *format, va_list arg); 157 int (vprintf)(const char *format, va_list arg); 158 int (vsprintf)(char *s, const char *format, va_list arg); 159 int (fgetc)(FILE *stream); 160 char *(fgets)(char *s, int n, FILE *stream); 161 int (fputc)(int c, FILE *stream); 162 int (fputs)(const char *s, FILE *stream); 163 int (getc)(FILE *stream); 164 int (getchar)(void); 165 char *(gets)(char *s); 166 int (putc)(int c, FILE *stream); 167 int (putchar)(int c); 168 int (puts)(const char *s); 169 int (ungetc)(int c, FILE *stream); 170 size_t (fread)(void *ptr, size_t size, size_t nmemb, FILE *stream); 171 size_t (fwrite)(const void *ptr, size_t size, size_t nmemb, FILE *stream); 172 int (fgetpos)(FILE *stream, fpos_t *pos); 173 int (fseek)(FILE *stream, long offset, int whence); 174 int (fsetpos)(FILE *stream, const fpos_t *pos); 175 long (ftell)(FILE *stream); 176 void (rewind)(FILE *stream); 177 void (clearerr)(FILE *stream); 178 int (feof)(FILE *stream); 179 int (ferror)(FILE *stream); 180 void (perror)(const char *s); 181 182 /* 183 * stdlib.h 184 */ 185 double (atof)(const char *nptr); 186 int (atoi)(const char *nptr); 187 long (atol)(const char *nptr); 188 double (strtod)(const char *nptr, char **endptr); 189 long (strtol)(const char *nptr, char **endptr, int base); 190 unsigned long (strtoul)(const char *nptr, char **endptr, int base); 191 int (rand)(void); 192 void (srand)(unsigned seed); 193 void *(calloc)(size_t nmemb, size_t size); 194 void (free)(void *ptr); 195 void *(malloc)(size_t size); 196 void *(realloc)(void *ptr, size_t size); 197 void (abort)(void); 198 int (atexit)(void (*func)(void)); 199 void (exit)(int status); 200 char *(getenv)(const char *name); 201 int (system)(const char *string); 202 void *(bsearch)(const void *key, const void *base, size_t nmemb, 203 size_t size, int (*compar)(const void *, const void *)); 204 void (qsort)(void *base, size_t nmemb, size_t size, 205 int (*compar)(const void *, const void *)); 206 int (abs)(int j); 207 div_t (div)(int numer, int denom); 208 long (labs)(long j); 209 ldiv_t (ldiv)(long numer, long denom); 210 int (mblen)(const char *s, size_t n); 211 int (mbtowc)(wchar_t *PWC, const char *s, size_t n); 212 int (wctomb)(char *s, wchar_t wchar); 213 size_t (mbstowcs)(wchar_t *pwcs, const char *s, size_t n); 214 size_t (wcstombs)(char *s, const wchar_t *pwcs, size_t n); 215 216 /* 217 * string.h 218 */ 219 void *(memcpy)(void *s1, const void *s2, size_t n); 220 void *(memmove)(void *s1, const void *s2, size_t n); 221 char *(strcpy)(char *s1, const char *s2); 222 char *(strncpy)(char *s1, const char *s2, size_t n); 223 char *(strcat)(char *s1, const char *s2); 224 char *(strncat)(char *s1, const char *s2, size_t n); 225 int (memcmp)(const void *s1, const void *s2, size_t n); 226 int (strcmp)(const char *s1, const char *s2); 227 int (strcoll)(const char *s1, const char *s2); 228 int (strncmp)(const char *s1, const char *s2, size_t n); 229 size_t (strxfrm)(char *s1, const char *s2, size_t n); 230 void *(memchr)(const void *s, int c, size_t n); 231 char *(strchr)(const char *s, int c); 232 size_t (strcspn)(const char *s1, const char *s2); 233 char *(strpbrk)(const char *s1, const char *s2); 234 char *(strrchr)(const char *s1, int c); 235 size_t (strspn)(const char *s1, const char *s2); 236 char *(strstr)(const char *s1, const char *s2); 237 char *(strtok)(char *s1, const char *s2); 238 void *(memset)(void *s, int c, size_t n); 239 char *(strerror)(int errnom); 240 size_t (strlen)(const char *s); 241 242 /* 243 * time.h 244 */ 245 clock_t (clock)(void); 246 double (difftime)(time_t time1, time_t time2); 247 time_t (mktime)(struct tm *timeptr); 248 time_t (time)(time_t *timer); 249 char *(asctime)(const struct tm *timeptr); 250 char *(ctime)(const time_t *timer); 251 struct tm *(gmtime)(const time_t *timer); 252 struct tm *(localtime)(const time_t *timer); 253 size_t (strftime)(char *s, size_t maxsize, const char *format, 254 const struct tm *timeptr); 255