Source code pulled from OpenBSD for OpenNTPD. The place to contribute to this code is via the OpenBSD CVS tree.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

279 lines
7.6 KiB

  1. /* $OpenBSD: stdlib.h,v 1.44 2008/06/24 06:01:33 otto Exp $ */
  2. /* $NetBSD: stdlib.h,v 1.25 1995/12/27 21:19:08 jtc Exp $ */
  3. /*-
  4. * Copyright (c) 1990 The Regents of the University of California.
  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. Neither the name of the University nor the names of its contributors
  16. * may be used to endorse or promote products derived from this software
  17. * without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  20. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  21. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  22. * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  23. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  24. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  25. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  26. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  27. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  28. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  29. * SUCH DAMAGE.
  30. *
  31. * @(#)stdlib.h 5.13 (Berkeley) 6/4/91
  32. */
  33. #ifndef _STDLIB_H_
  34. #define _STDLIB_H_
  35. #include <sys/cdefs.h>
  36. #include <machine/_types.h>
  37. #if __BSD_VISIBLE /* for quad_t, etc. (XXX - use protected types) */
  38. #include <sys/types.h>
  39. #endif
  40. #ifndef _SIZE_T_DEFINED_
  41. #define _SIZE_T_DEFINED_
  42. typedef __size_t size_t;
  43. #endif
  44. /* in C++, wchar_t is a built-in type */
  45. #if !defined(_WCHAR_T_DEFINED_) && !defined(__cplusplus)
  46. #define _WCHAR_T_DEFINED_
  47. typedef __wchar_t wchar_t;
  48. #endif
  49. typedef struct {
  50. int quot; /* quotient */
  51. int rem; /* remainder */
  52. } div_t;
  53. typedef struct {
  54. long quot; /* quotient */
  55. long rem; /* remainder */
  56. } ldiv_t;
  57. #if __ISO_C_VISIBLE >= 1999
  58. typedef struct {
  59. long long quot; /* quotient */
  60. long long rem; /* remainder */
  61. } lldiv_t;
  62. #endif
  63. #if __BSD_VISIBLE
  64. typedef struct {
  65. quad_t quot; /* quotient */
  66. quad_t rem; /* remainder */
  67. } qdiv_t;
  68. #endif
  69. #ifndef NULL
  70. #ifdef __GNUG__
  71. #define NULL __null
  72. #else
  73. #define NULL 0L
  74. #endif
  75. #endif
  76. #define EXIT_FAILURE 1
  77. #define EXIT_SUCCESS 0
  78. #define RAND_MAX 0x7fffffff
  79. extern size_t __mb_cur_max;
  80. #define MB_CUR_MAX __mb_cur_max
  81. #include <sys/cdefs.h>
  82. /*
  83. * Some header files may define an abs macro.
  84. * If defined, undef it to prevent a syntax error and issue a warning.
  85. */
  86. #ifdef abs
  87. #undef abs
  88. #warning abs macro collides with abs() prototype, undefining
  89. #endif
  90. __BEGIN_DECLS
  91. __dead void abort(void);
  92. int abs(int);
  93. int atexit(void (*)(void));
  94. double atof(const char *);
  95. int atoi(const char *);
  96. long atol(const char *);
  97. void *bsearch(const void *, const void *, size_t, size_t,
  98. int (*)(const void *, const void *));
  99. void *calloc(size_t, size_t);
  100. div_t div(int, int);
  101. char *ecvt(double, int, int *, int *);
  102. __dead void exit(int);
  103. __dead void _Exit(int);
  104. char *fcvt(double, int, int *, int *);
  105. void free(void *);
  106. char *gcvt(double, int, char *);
  107. char *getenv(const char *);
  108. long labs(long);
  109. ldiv_t ldiv(long, long);
  110. void *malloc(size_t);
  111. void qsort(void *, size_t, size_t, int (*)(const void *, const void *));
  112. int rand(void);
  113. void *realloc(void *, size_t);
  114. void srand(unsigned);
  115. double strtod(const char *, char **);
  116. float strtof(const char *, char **);
  117. long strtol(const char *, char **, int);
  118. unsigned long
  119. strtoul(const char *, char **, int);
  120. int system(const char *);
  121. /* these are currently just stubs */
  122. int mblen(const char *, size_t);
  123. size_t mbstowcs(wchar_t *, const char *, size_t);
  124. int wctomb(char *, wchar_t);
  125. int mbtowc(wchar_t *, const char *, size_t);
  126. size_t wcstombs(char *, const wchar_t *, size_t);
  127. /*
  128. * IEEE Std 1003.1c-95, also adopted by X/Open CAE Spec Issue 5 Version 2
  129. */
  130. #if __BSD_VISIBLE || __POSIX_VISIBLE >= 199506 || __XPG_VISIBLE >= 500 || \
  131. defined(_REENTRANT)
  132. int rand_r(unsigned int *);
  133. #endif
  134. #if __BSD_VISIBLE || __XPG_VISIBLE >= 400
  135. double drand48(void);
  136. double erand48(unsigned short[3]);
  137. long jrand48(unsigned short[3]);
  138. void lcong48(unsigned short[7]);
  139. long lrand48(void);
  140. long mrand48(void);
  141. long nrand48(unsigned short[3]);
  142. unsigned short *seed48(unsigned short[3]);
  143. void srand48(long);
  144. int putenv(const char *);
  145. #endif
  146. #if __BSD_VISIBLE || __XPG_VISIBLE >= 420
  147. long a64l(const char *);
  148. char *l64a(long);
  149. char *initstate(unsigned int, char *, size_t)
  150. __attribute__((__bounded__ (__string__,2,3)));
  151. long random(void);
  152. char *setstate(const char *);
  153. void srandom(unsigned int);
  154. int mkstemp(char *);
  155. char *mktemp(char *);
  156. char *realpath(const char *, char *);
  157. int setkey(const char *);
  158. int ttyslot(void);
  159. void *valloc(size_t); /* obsoleted by malloc() */
  160. #endif /* __BSD_VISIBLE || __XPG_VISIBLE >= 420 */
  161. /*
  162. * ISO C99
  163. */
  164. #if __ISO_C_VISIBLE >= 1999
  165. long long
  166. atoll(const char *);
  167. long long
  168. llabs(long long);
  169. lldiv_t
  170. lldiv(long long, long long);
  171. long long
  172. strtoll(const char *, char **, int);
  173. unsigned long long
  174. strtoull(const char *, char **, int);
  175. #endif
  176. /*
  177. * The Open Group Base Specifications, Issue 6; IEEE Std 1003.1-2001 (POSIX)
  178. */
  179. #if __BSD_VISIBLE || __POSIX_VISIBLE >= 200112 || __XPG_VISIBLE >= 600
  180. int setenv(const char *, const char *, int);
  181. void unsetenv(const char *);
  182. #endif
  183. #if __BSD_VISIBLE
  184. void *alloca(size_t);
  185. char *getbsize(int *, long *);
  186. char *cgetcap(char *, const char *, int);
  187. int cgetclose(void);
  188. int cgetent(char **, char **, const char *);
  189. int cgetfirst(char **, char **);
  190. int cgetmatch(char *, const char *);
  191. int cgetnext(char **, char **);
  192. int cgetnum(char *, const char *, long *);
  193. int cgetset(const char *);
  194. int cgetusedb(int);
  195. int cgetstr(char *, const char *, char **);
  196. int cgetustr(char *, const char *, char **);
  197. int daemon(int, int);
  198. char *devname(int, mode_t);
  199. int getloadavg(double [], int);
  200. void cfree(void *);
  201. #ifndef _GETOPT_DEFINED_
  202. #define _GETOPT_DEFINED_
  203. int getopt(int, char * const *, const char *);
  204. extern char *optarg; /* getopt(3) external variables */
  205. extern int opterr, optind, optopt, optreset;
  206. int getsubopt(char **, char * const *, char **);
  207. extern char *suboptarg; /* getsubopt(3) external variable */
  208. #endif /* _GETOPT_DEFINED_ */
  209. char *mkdtemp(char *);
  210. int mkstemps(char *, int);
  211. int heapsort(void *, size_t, size_t, int (*)(const void *, const void *));
  212. int mergesort(void *, size_t, size_t, int (*)(const void *, const void *));
  213. int radixsort(const unsigned char **, int, const unsigned char *,
  214. unsigned);
  215. int sradixsort(const unsigned char **, int, const unsigned char *,
  216. unsigned);
  217. void srandomdev(void);
  218. long long
  219. strtonum(const char *, long long, long long, const char **);
  220. void setproctitle(const char *, ...)
  221. __attribute__((__format__ (__printf__, 1, 2)));
  222. quad_t qabs(quad_t);
  223. qdiv_t qdiv(quad_t, quad_t);
  224. quad_t strtoq(const char *, char **, int);
  225. u_quad_t strtouq(const char *, char **, int);
  226. u_int32_t arc4random(void);
  227. void arc4random_stir(void);
  228. void arc4random_addrandom(unsigned char *, int)
  229. __attribute__((__bounded__ (__string__,1,2)));
  230. u_int32_t arc4random_uniform(u_int32_t);
  231. void arc4random_buf(void *, size_t)
  232. __attribute__((__bounded__ (__string__,1,2)));
  233. #endif /* __BSD_VISIBLE */
  234. __END_DECLS
  235. #endif /* _STDLIB_H_ */