source: trunk/src/emx/include/stdlib.h@ 1905

Last change on this file since 1905 was 1905, checked in by bird, 20 years ago

Rewrote atexit() fixing recursive exit() calling. Added on_exit().

  • Property cvs2svn:cvs-rev set to 1.31
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 15.1 KB
Line 
1/* stdlib.h,v 1.24 2004/09/14 22:27:36 bird Exp */
2/** @file
3 * FreeBSD 5.3
4 * @changed bird: EMXifications and OS2ifications.
5 */
6
7/*-
8 * Copyright (c) 1990, 1993
9 * The Regents of the University of California. All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. All advertising materials mentioning features or use of this software
20 * must display the following acknowledgement:
21 * This product includes software developed by the University of
22 * California, Berkeley and its contributors.
23 * 4. Neither the name of the University nor the names of its contributors
24 * may be used to endorse or promote products derived from this software
25 * without specific prior written permission.
26 *
27 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
28 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
31 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 * SUCH DAMAGE.
38 *
39 * @(#)stdlib.h 8.5 (Berkeley) 5/19/95
40 * $FreeBSD: src/include/stdlib.h,v 1.56 2004/02/23 03:16:58 ache Exp $
41 */
42
43#ifndef _STDLIB_H_
44#define _STDLIB_H_
45
46#include <sys/cdefs.h>
47#include <sys/_null.h>
48#include <sys/_types.h>
49
50#if __BSD_VISIBLE
51#ifndef _RUNE_T_DECLARED
52typedef __rune_t rune_t;
53#define _RUNE_T_DECLARED
54#endif
55#endif
56
57#if !defined(_SIZE_T_DECLARED) && !defined(_SIZE_T) /* bird: emx */
58typedef __size_t size_t;
59#define _SIZE_T_DECLARED
60#define _SIZE_T /* bird: emx */
61#endif
62
63#ifndef __cplusplus
64#if !defined(_WCHAR_T_DECLARED) && !defined(_WCHAR_T) /* bird: emx */
65typedef __wchar_t wchar_t;
66#define _WCHAR_T_DECLARED
67#define _WCHAR_T /* bird: emx */
68#endif
69#endif
70
71typedef struct _div_t { /* bird: emx (tag) */
72 int quot; /* quotient */
73 int rem; /* remainder */
74} div_t;
75
76typedef struct _ldiv_t { /* bird: emx (tag) */
77 long quot;
78 long rem;
79} ldiv_t;
80
81#define EXIT_FAILURE 1
82#define EXIT_SUCCESS 0
83
84#define RAND_MAX 0x7fffffff
85
86extern int __mb_cur_max;
87#define MB_CUR_MAX __mb_cur_max
88
89__BEGIN_DECLS
90void abort(void) __dead2;
91int abs(int) __pure2;
92int atexit(void (*)(void));
93double atof(const char *);
94int atoi(const char *);
95long atol(const char *);
96void *bsearch(const void *, const void *, size_t,
97 size_t, int (*)(const void *, const void *));
98void *calloc(size_t, size_t);
99div_t div(int, int) __pure2;
100void exit(int) __dead2;
101void free(void *);
102char *getenv(const char *);
103long labs(long) __pure2;
104ldiv_t ldiv(long, long) __pure2;
105void *malloc(size_t);
106int mblen(const char *, size_t);
107size_t mbstowcs(wchar_t * __restrict , const char * __restrict, size_t);
108int mbtowc(wchar_t * __restrict, const char * __restrict, size_t);
109void qsort(void *, size_t, size_t,
110 int (*)(const void *, const void *));
111int rand(void);
112void *realloc(void *, size_t);
113void srand(unsigned);
114double strtod(const char * __restrict, char ** __restrict);
115float strtof(const char * __restrict, char ** __restrict);
116long strtol(const char * __restrict, char ** __restrict, int);
117long double
118 strtold(const char * __restrict, char ** __restrict);
119unsigned long
120 strtoul(const char * __restrict, char ** __restrict, int);
121int system(const char *);
122int wctomb(char *, wchar_t);
123size_t wcstombs(char * __restrict, const wchar_t * __restrict, size_t);
124
125/*
126 * Functions added in C99 which we make conditionally available in the
127 * BSD^C89 namespace if the compiler supports `long long'.
128 * The #if test is more complicated than it ought to be because
129 * __BSD_VISIBLE implies __ISO_C_VISIBLE == 1999 *even if* `long long'
130 * is not supported in the compilation environment (which therefore means
131 * that it can't really be ISO C99).
132 *
133 * (The only other extension made by C99 in thie header is _Exit().)
134 */
135#if __ISO_C_VISIBLE >= 1999
136#ifdef __LONG_LONG_SUPPORTED
137/* LONGLONG */
138typedef struct _lldiv_t { /* bird: emx (tag) */
139 long long quot;
140 long long rem;
141} lldiv_t;
142
143/* LONGLONG */
144long long
145 atoll(const char *);
146/* LONGLONG */
147long long
148 llabs(long long) __pure2;
149/* LONGLONG */
150lldiv_t lldiv(long long, long long) __pure2;
151/* LONGLONG */
152long long
153 strtoll(const char * __restrict, char ** __restrict, int);
154/* LONGLONG */
155unsigned long long
156 strtoull(const char * __restrict, char ** __restrict, int);
157#endif /* __LONG_LONG_SUPPORTED */
158
159void _Exit(int) __dead2;
160#endif /* __ISO_C_VISIBLE >= 1999 */
161
162/*
163 * Extensions made by POSIX relative to C. We don't know yet which edition
164 * of POSIX made these extensions, so assume they've always been there until
165 * research can be done.
166 */
167#if __POSIX_VISIBLE /* >= ??? */
168int posix_memalign(void **, size_t, size_t); /* bird: we implement this. */
169int rand_r(unsigned *); /* (TSF) */
170int setenv(const char *, const char *, int);
171int unsetenv(const char *); /* bird: standard saith shall return int. */
172#endif
173
174/*
175 * The only changes to the XSI namespace in revision 6 were the deletion
176 * of the ttyslot() and valloc() functions, which FreeBSD never declared
177 * in this header. For revision 7, ecvt(), fcvt(), and gcvt(), which
178 * FreeBSD also does not have, and mktemp(), are to be deleted.
179 */
180#if __XSI_VISIBLE
181/* XXX XSI requires pollution from <sys/wait.h> here. We'd rather not. */
182/* long a64l(const char *); */
183double drand48(void);
184/* char *ecvt(double, int, int * __restrict, int * __restrict); */
185double erand48(unsigned short[3]);
186/* char *fcvt(double, int, int * __restrict, int * __restrict); */
187/* char *gcvt(double, int, int * __restrict, int * __restrict); */
188int getsubopt(char **, char *const *, char **);
189/** @todo int grantpt(int); */
190char *initstate(unsigned long /* XSI requires u_int */, char *, long);
191long jrand48(unsigned short[3]);
192/* char *l64a(long); */
193void lcong48(unsigned short[7]);
194long lrand48(void);
195#ifndef _MKSTEMP_DECLARED
196int mkstemp(char *);
197#define _MKSTEMP_DECLARED
198#endif
199#ifndef _MKTEMP_DECLARED
200char *mktemp(char *);
201#define _MKTEMP_DECLARED
202#endif
203long mrand48(void);
204long nrand48(unsigned short[3]);
205/** @todo int posix_openpt(int); */
206/** @todo char *ptsname(int); */
207int putenv(const char *);
208long random(void);
209char *realpath(const char *, char resolved_path[]);
210unsigned short
211 *seed48(unsigned short[3]);
212#ifndef _SETKEY_DECLARED
213/** @todo int setkey(const char *); */
214#define _SETKEY_DECLARED
215#endif
216char *setstate(/* const */ char *);
217void srand48(long);
218void srandom(unsigned long);
219/** @todo int unlockpt(int); */
220#endif /* __XSI_VISIBLE */
221
222#if __BSD_VISIBLE
223extern const char *_malloc_options;
224extern void (*_malloc_message)(const char *, const char *, const char *,
225 const char *);
226
227/*
228 * The alloca() function can't be implemented in C, and on some
229 * platforms it can't be implemented at all as a callable function.
230 * The GNU C compiler provides a built-in alloca() which we can use;
231 * in all other cases, provide a prototype, mainly to pacify various
232 * incarnations of lint. On platforms where alloca() is not in libc,
233 * programs which use it will fail to link when compiled with non-GNU
234 * compilers.
235 */
236#if __GNUC__ >= 2 || defined(__INTEL_COMPILER)
237#undef alloca /* some GNU bits try to get cute and define this on their own */
238#define alloca(sz) __builtin_alloca(sz)
239#elif defined(lint)
240void *alloca(size_t);
241#endif
242
243/** @todo __uint32_t
244 arc4random(void); */
245/** @todo void arc4random_addrandom(unsigned char *dat, int datlen); */
246/** @todo void arc4random_stir(void); */
247char *getbsize(int *, long *);
248 /* getcap(3) functions */
249/** @todo char *cgetcap(char *, const char *, int); */
250/** @todo int cgetclose(void); */
251/** @todo int cgetent(char **, char **, const char *); */
252/** @todo int cgetfirst(char **, char **); */
253/** @todo int cgetmatch(const char *, const char *); */
254/** @todo int cgetnext(char **, char **); */
255/** @todo int cgetnum(char *, const char *, long *); */
256/** @todo int cgetset(const char *); */
257/** @todo int cgetstr(char *, const char *, char **); */
258/** @todo int cgetustr(char *, const char *, char **); */
259
260/** @todo int daemon(int, int); */
261/** @todo char *devname(int, int); */
262/** @todo char *devname_r(int, int, char *, int); */
263int getloadavg(double [], int);
264__const char *
265 getprogname(void);
266
267int heapsort(void *, size_t, size_t, int (*)(const void *, const void *));
268int mergesort(void *, size_t, size_t, int (*)(const void *, const void *));
269void qsort_r(void *, size_t, size_t, void *,
270 int (*)(void *, const void *, const void *));
271int radixsort(const unsigned char **, int, const unsigned char *,
272 unsigned);
273void *reallocf(void *, size_t);
274void setprogname(const char *);
275int sradixsort(const unsigned char **, int, const unsigned char *,
276 unsigned);
277void sranddev(void);
278void srandomdev(void);
279
280/* Deprecated interfaces, to be removed in FreeBSD 6.0. */
281/** @todo __int64_t
282 strtoq(const char *, char **, int); */
283/** @todo __uint64_t
284 strtouq(const char *, char **, int); */
285
286extern char *suboptarg; /* getsubopt(3) external variable */
287#endif /* __BSD_VISIBLE */
288
289
290
291/* bird: LIBC stuff - start */
292#ifdef __BSD_VISIBLE
293char *_getcwdux(char *, size_t);
294/** @todo: int _chdirux(char *); */
295char *_realrealpath(const char *, char *, size_t);
296#endif
297#ifdef __USE_GNU
298char *canonicalize_file_name(const char *);
299void *valloc(size_t);
300#endif
301int on_exit(void (*)(int, void *), void *);
302/* bird: LIBC stuff - end */
303
304
305/* bird: EMX/PC stuff - start */
306
307#include <malloc.h>
308
309#if !defined (_MAX_PATH)
310#define _MAX_PATH 260
311#define _MAX_DRIVE 3
312#define _MAX_DIR 256
313#define _MAX_FNAME 256
314#define _MAX_EXT 256
315#endif
316
317#if !defined (__STRICT_ANSI__) && !defined (_POSIX_SOURCE) || defined(__USE_EMX)
318
319#if !defined (OS2_MODE)
320#define DOS_MODE 0
321#define OS2_MODE 1
322#endif
323
324#ifndef _INTPTR_T_DECLARED
325typedef __intptr_t intptr_t;
326typedef __uintptr_t uintptr_t;
327#define _INTPTR_T_DECLARED
328#endif
329
330#if !defined(_MODE_T_DECLARED) && !defined(_MODE_T) /* bird: emx */
331typedef __mode_t mode_t;
332#define _MODE_T_DECLARED
333#define _MODE_T /* bird: emx */
334#endif
335
336/* declare _errno to be compatible with MS/VAC/WATCOM */
337#if !defined (_ERRNO)
338#define _ERRNO
339extern int * _errno(void);
340#define errno (* _errno())
341#endif /* bird: emx */
342
343#if !defined (_ULDIV_T)
344#define _ULDIV_T
345typedef struct
346{
347 unsigned long quot;
348 unsigned long rem;
349} _uldiv_t;
350
351#if __ISO_C_VISIBLE >= 1999 && defined(__LONG_LONG_SUPPORTED)
352typedef struct _lldiv_t _lldiv_t;
353#else
354typedef struct
355{
356 long long quot;
357 long long rem;
358} _lldiv_t;
359#endif
360typedef struct
361{
362 unsigned long long quot;
363 unsigned long long rem;
364} _ulldiv_t;
365#endif
366
367extern char **environ;
368
369extern __const__ unsigned char _osminor;
370extern __const__ unsigned char _osmajor;
371
372/* No DOS support ... */
373#define _osmode OS2_MODE
374
375unsigned alarm (unsigned);
376int brk(const void *);
377int chdir (const char *);
378char *gcvt (double, int, char *); /* this is rubbish standardwise */
379char *getcwd (char *, size_t);
380int getpagesize (void);
381char *getwd (char *);
382int mkdir(const char *, mode_t);
383void perror (const char *);
384int rmdir (const char *);
385void *sbrk(intptr_t);
386unsigned sleep (unsigned);
387long ulimit (int, ...);
388
389char *itoa (int, char *, int);
390char *ltoa (long, char *, int);
391char *ultoa (unsigned long, char *, int);
392char *lltoa (long long, char *, int);
393char *ulltoa (unsigned long long, char *, int);
394
395#endif
396
397
398#if (!defined (__STRICT_ANSI__) && !defined (_POSIX_SOURCE)) || defined (_WITH_UNDERSCORE) || defined(__USE_EMX)
399
400extern char **_environ;
401extern __const__ char * __const__ _sys_errlist[];
402extern __const__ int _sys_nerr;
403
404unsigned _alarm (unsigned);
405int _brk(const void *);
406int _chdir (__const__ char *);
407char *_gcvt (double, int, char *);
408char *_getcwd (char *, size_t);
409int _getpagesize (void);
410char *_getwd (char *);
411int _mkdir (__const__ char *, long);
412int _putenv (__const__ char *);
413int _rmdir (__const__ char *);
414void *_sbrk(intptr_t);
415unsigned _sleep (unsigned);
416void _swab (__const__ void *, void *, size_t);
417long _ulimit (int, ...);
418
419int _abspath (char *, __const__ char *, int);
420long long _atoll (__const__ char *);
421long double _atofl (__const__ char *);
422int _chdir2 (__const__ char *);
423int _chdrive (int);
424int _core (int);
425void _defext (char *, __const__ char *);
426void _envargs (int *, char ***, __const__ char *);
427int _execname (char *, size_t);
428void _exit (int) __attribute__ ((__noreturn__));
429int _filesys (__const__ char *, char *, size_t);
430char **_fnexplode (__const__ char *);
431void _fnexplodefree (char **);
432char _fngetdrive (__const__ char *);
433int _fnisabs (__const__ char *);
434int _fnisrel (__const__ char *);
435void _fnlwr (char *);
436void _fnlwr2 (char *, __const__ char *);
437char *_fnslashify (char *);
438int _fullpath (char *, __const__ char *, int);
439int _getcwd1 (char *, char);
440char *_getcwd2 (char *, int);
441int _getdrive (void);
442char *_getext (__const__ char *);
443char *_getext2 (__const__ char *);
444char *_getname (__const__ char *);
445int _getsockhandle (int);
446int _gettid (void);
447char *_getvol (char);
448char *_itoa (int, char *, int);
449_lldiv_t _lldiv (long long, long long);
450char *_lltoa (long long, char *, int);
451_uldiv_t _uldiv (unsigned long, unsigned long);
452_ulldiv_t _ulldiv (unsigned long long, unsigned long long);
453char *_itoa (int, char *, int);
454char *_ltoa (long, char *, int);
455char *_ultoa (unsigned long, char *, int);
456char *_lltoa (long long, char *, int);
457char *_ulltoa (unsigned long long, char *, int);
458void _makepath (char *, __const__ char *, __const__ char *,
459 __const__ char *, __const__ char *);
460int _path (char *, __const__ char *);
461int _read_kbd (int, int, int);
462void _remext (char *);
463void _rfnlwr (void);
464void _response (int *, char ***);
465void _scrsize (int *);
466void _searchenv (__const__ char *, __const__ char *, char *);
467void _sfnlwr (__const__ char *);
468unsigned _sleep2 (unsigned);
469char ** _splitargs (char *, int *);
470void _splitpath (__const__ char *, char *, char *, char *, char *);
471float _strtof (__const__ char *, char **);
472long double _strtold (__const__ char *, char **);
473long long _strtoll (__const__ char *, char **, int);
474unsigned long long _strtoull (__const__ char *, char **, int);
475char _swchar (void);
476void _wildcard (int *, char ***);
477
478int _beginthread (void (*)(void *), void *, unsigned, void *);
479void _endthread (void);
480void **_threadstore (void);
481
482int _setenv(const char *envname, const char *envval, int overwrite);
483int _unsetenv(const char *name);
484
485#endif
486
487__END_DECLS
488
489/* bird: EMX/PC stuff - end */
490
491#endif /* !_STDLIB_H_ */
492
Note: See TracBrowser for help on using the repository browser.