1 /* @(#)libport.h 1.52 21/06/16 Copyright 1995-2021 J. Schilling */ 2 /* 3 * Prototypes for POSIX standard functions that may be missing on the 4 * local platform and thus are implemented inside libschily. 5 * 6 * Copyright (c) 1995-2021 J. Schilling 7 */ 8 /* 9 * The contents of this file are subject to the terms of the 10 * Common Development and Distribution License, Version 1.0 only 11 * (the "License"). You may not use this file except in compliance 12 * with the License. 13 * 14 * See the file CDDL.Schily.txt in this distribution for details. 15 * A copy of the CDDL is also available via the Internet at 16 * http://www.opensource.org/licenses/cddl1.txt 17 * 18 * When distributing Covered Code, include this CDDL HEADER in each 19 * file and include the License file CDDL.Schily.txt from this distribution. 20 */ 21 22 23 #ifndef _SCHILY_LIBPORT_H 24 #define _SCHILY_LIBPORT_H 25 26 #ifndef _SCHILY_MCONFIG_H 27 #include <schily/mconfig.h> 28 #endif 29 #ifndef _SCHILY_TYPES_H 30 #include <schily/types.h> 31 #endif 32 33 #ifndef _SCHILY_UNISTD_H 34 #include <schily/unistd.h> 35 #endif 36 37 #ifdef __cplusplus 38 extern "C" { 39 #endif 40 41 #if defined(_INCL_SYS_TYPES_H) || defined(_INCL_TYPES_H) || defined(size_t) 42 # ifndef FOUND_SIZE_T 43 # define FOUND_SIZE_T 44 # endif 45 #endif 46 #if defined(_MSC_VER) && !defined(_SIZE_T_DEFINED) 47 # undef FOUND_SIZE_T 48 #endif 49 50 #ifdef OPENSERVER 51 /* 52 * Don't use the usleep() from libc on SCO's OPENSERVER. 53 * It will kill our processes with SIGALRM. 54 */ 55 /* 56 * Don't #undef HAVE_USLEEP in this file, SCO has a 57 * usleep() prototype in unistd.h 58 */ 59 /* #undef HAVE_USLEEP */ 60 #endif 61 62 #ifdef FOUND_SIZE_T 63 /* 64 * We currently cannot define this here because there IRIX has a definition 65 * than violates the standard. 66 */ 67 #ifndef HAVE_SNPRINTF 68 /*PRINTFLIKE3*/ 69 extern int snprintf __PR((char *, size_t, const char *, ...)) 70 __printflike__(3, 4); 71 #endif 72 #ifndef HAVE_VSNPRINTF 73 #ifdef _SCHILY_VARARGS_H 74 extern int vsnprintf __PR((char *, size_t, const char *, va_list)); 75 #endif 76 #endif 77 #endif 78 79 #ifdef EOF /* stdio.h has been included */ 80 #ifdef FOUND_SIZE_T 81 #ifndef HAVE_GETDELIM 82 extern ssize_t getdelim __PR((char **, size_t *, int, FILE *)); 83 #endif 84 #endif 85 #endif 86 87 #ifndef HAVE_GETHOSTID 88 extern long gethostid __PR((void)); 89 #endif 90 #ifndef HAVE_GETPAGESIZE 91 extern int getpagesize __PR((void)); 92 #endif 93 #ifndef HAVE_USLEEP 94 extern int usleep __PR((int usec)); 95 #endif 96 97 #ifndef HAVE_STRCASECMP 98 extern int strcasecmp __PR((const char *, const char *)); 99 #endif 100 #ifdef FOUND_SIZE_T 101 #ifndef HAVE_STRNCASECMP 102 extern int strncasecmp __PR((const char *, const char *, 103 size_t)); 104 #endif 105 #endif 106 107 #ifndef HAVE_STRCAT 108 extern char *strcat __PR((char *s1, const char *s2)); 109 #endif 110 #ifndef HAVE_STRCHR 111 extern char *strchr __PR((const char *s1, int c)); 112 #endif 113 #ifndef HAVE_STRCMP 114 extern int strcmp __PR((const char *s1, const char *s2)); 115 #endif 116 #ifndef HAVE_STRCPY 117 extern char *strcpy __PR((char *s1, const char *s2)); 118 #endif 119 #if !defined(HAVE_STRDUP) || defined(__SVR4) 120 extern char *strdup __PR((const char *s)); 121 #endif 122 #ifdef FOUND_SIZE_T 123 #ifndef HAVE_STRNDUP 124 extern char *strndup __PR((const char *s, size_t len)); 125 #endif 126 #ifndef HAVE_STRLEN 127 extern size_t strlen __PR((const char *s)); 128 #endif 129 #ifndef HAVE_STRNLEN 130 extern size_t strnlen __PR((const char *s, size_t len)); 131 #endif 132 #ifndef HAVE_STRLCAT 133 extern size_t strlcat __PR((char *s1, const char *s2, 134 size_t len)); 135 #endif 136 #ifndef HAVE_STRLCPY 137 extern size_t strlcpy __PR((char *s1, const char *s2, 138 size_t len)); 139 #endif 140 #ifndef HAVE_STRNCAT 141 extern char *strncat __PR((char *s1, const char *s2, 142 size_t len)); 143 #endif 144 #ifndef HAVE_STRNCMP 145 extern int strncmp __PR((const char *s1, const char *s2, 146 size_t len)); 147 #endif 148 #ifndef HAVE_STRNCPY 149 extern char *strncpy __PR((char *s1, const char *s2, 150 size_t len)); 151 #endif 152 #endif /* FOUND_SIZE_T */ 153 #ifndef HAVE_STRRCHR 154 extern char *strrchr __PR((const char *s1, int c)); 155 #endif 156 157 #ifndef HAVE_STRSTR 158 extern char *strstr __PR((const char *s1, const char *s2)); 159 #endif 160 161 #ifdef _SCHILY_WCHAR_H 162 #ifndef HAVE_WCSCAT 163 extern wchar_t *wcscat __PR((wchar_t *s1, const wchar_t *s2)); 164 #endif 165 #ifndef HAVE_WCSCHR 166 extern wchar_t *wcschr __PR((const wchar_t *s1, wchar_t c)); 167 #endif 168 #ifndef HAVE_WCSCMP 169 extern int wcscmp __PR((const wchar_t *s1, 170 const wchar_t *s2)); 171 #endif 172 #ifndef HAVE_WCSCPY 173 extern wchar_t *wcscpy __PR((wchar_t *s1, const wchar_t *s2)); 174 #endif 175 #ifndef HAVE_WCSDUP 176 extern wchar_t *wcsdup __PR((const wchar_t *s)); 177 #endif 178 #ifdef FOUND_SIZE_T 179 #ifndef HAVE_WCSNDUP 180 extern wchar_t *wcsndup __PR((const wchar_t *s, size_t len)); 181 #endif 182 #ifndef HAVE_WCSLEN 183 extern size_t wcslen __PR((const wchar_t *s)); 184 #endif 185 #ifndef HAVE_WCSNLEN 186 extern size_t wcsnlen __PR((const wchar_t *s, size_t len)); 187 #endif 188 #ifndef HAVE_WCSLCAT 189 extern size_t wcslcat __PR((wchar_t *s1, const wchar_t *s2, 190 size_t len)); 191 #endif 192 #ifndef HAVE_WCSLCPY 193 extern size_t wcslcpy __PR((wchar_t *s1, const wchar_t *s2, 194 size_t len)); 195 #endif 196 #ifndef HAVE_WCSNCAT 197 extern wchar_t *wcsncat __PR((wchar_t *s1, const wchar_t *s2, 198 size_t len)); 199 #endif 200 #ifndef HAVE_WCSNCMP 201 extern int wcsncmp __PR((const wchar_t *s1, 202 const wchar_t *s2, 203 size_t len)); 204 #endif 205 #ifndef HAVE_WCSNCPY 206 extern wchar_t *wcsncpy __PR((wchar_t *s1, const wchar_t *s2, 207 size_t len)); 208 #endif 209 #endif /* FOUND_SIZE_T */ 210 #ifndef HAVE_WCSRCHR 211 extern wchar_t *wcsrchr __PR((const wchar_t *s1, wchar_t c)); 212 #endif 213 214 #ifndef HAVE_WCSSTR 215 extern wchar_t *wcsstr __PR((const wchar_t *s1, 216 const wchar_t *s2)); 217 #endif 218 #ifndef HAVE_WCSTOL 219 extern long wcstol __PR((const wchar_t *nptr, 220 wchar_t **endptr, 221 int base)); 222 #endif 223 #endif /* _SCHILY_WCHAR_H */ 224 225 #ifndef HAVE_RENAME 226 extern int rename __PR((const char *__old, 227 const char *__new)); 228 #endif 229 230 /* 231 * XXX Note: libgen.h / -lgen on Solaris contain eaccess() 232 */ 233 #ifndef HAVE_EACCESS 234 extern int eaccess __PR((const char *name, int mode)); 235 #endif 236 237 /* 238 * See also libgen.h 239 */ 240 #ifndef HAVE_BASENAME 241 extern char *basename __PR((char *name)); 242 #endif 243 #ifndef HAVE_DIRNAME 244 extern char *dirname __PR((char *name)); 245 #endif 246 247 #ifndef HAVE_TIMEGM 248 #if defined(_SCHILY_TIME_H) 249 extern time_t timegm __PR((struct tm *)); 250 #endif 251 #endif 252 253 #ifndef HAVE_GETUID 254 extern uid_t getuid __PR((void)); 255 #endif 256 #ifndef HAVE_GETEUID 257 extern uid_t geteuid __PR((void)); 258 #endif 259 #ifndef HAVE_SETUID 260 extern int setuid __PR((uid_t uid)); 261 #endif 262 #ifndef HAVE_SETEUID 263 extern int seteuid __PR((uid_t uid)); 264 #endif 265 266 #ifndef HAVE_GETGID 267 extern gid_t getgid __PR((void)); 268 #endif 269 #ifndef HAVE_GETEGID 270 extern gid_t getegid __PR((void)); 271 #endif 272 #ifndef HAVE_SETGID 273 extern int setgid __PR((gid_t gid)); 274 #endif 275 #ifndef HAVE_SETEGID 276 extern int setegid __PR((gid_t gid)); 277 #endif 278 279 #ifndef HAVE_GETPWNAM 280 extern struct passwd *getpwnam __PR((const char *name)); 281 #endif 282 #ifndef HAVE_GETPWENT 283 extern struct passwd *getpwent __PR((void)); 284 #endif 285 #ifndef HAVE_GETPWUID 286 extern struct passwd *getpwuid __PR((uid_t uid)); 287 #endif 288 #ifndef HAVE_SETPWENT 289 extern void setpwent __PR((void)); 290 #endif 291 #ifndef HAVE_ENDPWENT 292 extern void endpwent __PR((void)); 293 #endif 294 295 296 #ifndef HAVE_GETGRNAM 297 extern struct group *getgrnam __PR((const char *name)); 298 #endif 299 #ifndef HAVE_GETGRENT 300 extern struct group *getgrent __PR((void)); 301 #endif 302 #ifndef HAVE_GETGRGID 303 extern struct group *getgrgid __PR((gid_t gid)); 304 #endif 305 #ifndef HAVE_SETGRENT 306 extern void setgrent __PR((void)); 307 #endif 308 #ifndef HAVE_ENDGRENT 309 extern void endgrent __PR((void)); 310 #endif 311 312 #ifndef HAVE_FCHDIR 313 extern int fchdir __PR((int fd)); 314 #endif 315 #ifndef HAVE_OPENAT 316 #if defined(HAVE_LARGEFILES) 317 # define openat openat64 318 #endif 319 extern int openat __PR((int fd, const char *name, int oflag, ...)); 320 #endif 321 322 323 #ifndef HAVE_GETTIMEOFDAY 324 #ifdef _SCHILY_TIME_H 325 extern int gettimeofday __PR((struct timeval *__tp, void *__tzp)); 326 #endif 327 #endif 328 329 #ifndef HAVE_FACCESSAT 330 extern int faccessat __PR((int fd, const char *name, 331 int amode, int flag)); 332 #endif 333 #ifndef HAVE_FCHMODAT 334 extern int fchmodat __PR((int fd, const char *name, 335 mode_t mode, int flag)); 336 #endif 337 #ifndef HAVE_LCHMOD 338 extern int lchmod __PR((const char *name, mode_t mode)); 339 #endif 340 341 #ifndef HAVE_FCHOWNAT 342 extern int fchownat __PR((int fd, const char *name, 343 uid_t owner, gid_t group, int flag)); 344 #endif 345 346 #ifndef HAVE_FDOPENDIR 347 #ifdef _SCHILY_DIRENT_H 348 extern DIR *fdopendir __PR((int fd)); 349 #endif 350 #endif 351 352 #ifdef _SCHILY_STAT_H 353 #ifndef HAVE_FSTATAT 354 #if defined(HAVE_LARGEFILES) 355 # define fstatat fstatat64 356 #endif 357 extern int fstatat __PR((int fd, const char *name, 358 struct stat *sbuf, int flag)); 359 #endif 360 #endif /* _SCHILY_STAT_H */ 361 #ifdef _SCHILY_TIME_H 362 #ifndef HAVE_FUTIMENS 363 extern int futimens __PR((int fd, 364 const struct timespec __times__[2])); 365 #endif 366 #ifndef HAVE_FUTIMESAT 367 extern int futimesat __PR((int fd, const char *name, 368 const struct timeval __times__[2])); 369 #endif 370 #ifndef HAVE_LUTIMENS 371 extern int lutimens __PR((const char *name, 372 const struct timespec __times__[2])); 373 #endif 374 #endif /* _SCHILY_TIME_H */ 375 #ifndef HAVE_LINKAT 376 extern int linkat __PR((int fd1, const char *name1, 377 int fd2, const char *name2, int flag)); 378 #endif 379 #ifndef HAVE_MKDIRAT 380 extern int mkdirat __PR((int fd, const char *name, mode_t mode)); 381 #endif 382 #ifndef HAVE_MKFIFO 383 extern int mkfifo __PR((const char *name, mode_t mode)); 384 #endif 385 #ifndef HAVE_MKFIFOAT 386 extern int mkfifoat __PR((int fd, const char *name, mode_t mode)); 387 #endif 388 #ifndef HAVE_MKNODAT 389 extern int mknodat __PR((int fd, const char *name, 390 mode_t mode, dev_t dev)); 391 #endif 392 #ifndef HAVE_READLINKAT 393 extern ssize_t readlinkat __PR((int fd, const char *name, 394 char *lbuf, size_t lbufsize)); 395 #endif 396 #ifndef HAVE_RENAMEAT 397 extern int renameat __PR((int oldfd, const char *__old, 398 int newfd, const char *__new)); 399 #endif 400 #ifndef HAVE_SYMLINKAT 401 extern int symlinkat __PR((const char *content, 402 int fd, const char *name)); 403 #endif 404 #ifndef HAVE_UNLINKAT 405 extern int unlinkat __PR((int fd, const char *name, int flag)); 406 #endif 407 #ifdef _SCHILY_TIME_H 408 #ifndef HAVE_UTIMENS 409 extern int utimens __PR((const char *name, 410 const struct timespec __times__[2])); 411 #endif 412 #ifndef HAVE_UTIMENSAT 413 extern int utimensat __PR((int fd, const char *name, 414 const struct timespec __times__[2], 415 int flag)); 416 #endif 417 #endif /* _SCHILY_TIME_H */ 418 419 #ifndef HAVE_PUTENV 420 extern int putenv __PR((char *new)); 421 #endif 422 #ifndef HAVE_UNSETENV 423 extern int unsetenv __PR((const char *name)); 424 #endif 425 426 #ifndef HAVE_WAITID 427 #ifdef _SCHILY_WAIT_H 428 #define waitid js_waitid 429 extern int waitid __PR((idtype_t idtype, id_t id, 430 siginfo_t *infop, int opts)); 431 #endif 432 #endif 433 434 #ifdef __SUNOS4 435 /* 436 * Define prototypes for POSIX standard functions that are missing on SunOS-4.x 437 * to make compilation smooth. 438 */ 439 #include <schily/sunos4_proto.h> 440 441 #endif /* __SUNOS4 */ 442 443 #ifdef __cplusplus 444 } 445 #endif 446 447 #endif /* _SCHILY_LIBPORT_H */ 448