source: branches/libc-0.6/src/emx/include/stdlib.h

Last change on this file was 3903, checked in by bird, 11 years ago

0.6: Safer and more generic _path and _searchenv functions, making the spawn code use for locating executables in a more flexible manner. Unix style search PATH separators are now honored. Fixes #180 and #308.

  • Property cvs2svn:cvs-rev set to 1.34
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 16.0 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__uint32_t
244 arc4random(void);
245void arc4random_addrandom(unsigned char *dat, int datlen);
246void 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);
294char *_realrealpath(const char *, char *, size_t);
295int _getenv_longlong(const char *, long long *);
296int _getenv_long(const char *, long *);
297int _getenv_int(const char *, int *);
298#endif
299#ifdef __USE_GNU
300char *canonicalize_file_name(const char *);
301void *valloc(size_t);
302#endif
303int on_exit(void (*)(int, void *), void *);
304/* bird: LIBC stuff - end */
305
306
307/* bird: EMX/PC stuff - start */
308
309#include <malloc.h>
310
311#if !defined (_MAX_PATH)
312#define _MAX_PATH 260
313#define _MAX_DRIVE 3
314#define _MAX_DIR 256
315#define _MAX_FNAME 256
316#define _MAX_EXT 256
317#endif
318
319#if !defined (__STRICT_ANSI__) && !defined (_POSIX_SOURCE) || defined(__USE_EMX)
320
321#if !defined (OS2_MODE)
322#define DOS_MODE 0
323#define OS2_MODE 1
324#endif
325
326#ifndef _INTPTR_T_DECLARED
327typedef __intptr_t intptr_t;
328typedef __uintptr_t uintptr_t;
329#define _INTPTR_T_DECLARED
330#endif
331
332#if !defined(_MODE_T_DECLARED) && !defined(_MODE_T) /* bird: emx */
333typedef __mode_t mode_t;
334#define _MODE_T_DECLARED
335#define _MODE_T /* bird: emx */
336#endif
337
338/* declare _errno to be compatible with MS/VAC/WATCOM */
339#if !defined (_ERRNO)
340#define _ERRNO
341extern int * _errno(void);
342#define errno (* _errno())
343#endif /* bird: emx */
344
345#if !defined (_ULDIV_T)
346#define _ULDIV_T
347typedef struct
348{
349 unsigned long quot;
350 unsigned long rem;
351} _uldiv_t;
352
353#if __ISO_C_VISIBLE >= 1999 && defined(__LONG_LONG_SUPPORTED)
354typedef struct _lldiv_t _lldiv_t;
355#else
356typedef struct
357{
358 long long quot;
359 long long rem;
360} _lldiv_t;
361#endif
362typedef struct
363{
364 unsigned long long quot;
365 unsigned long long rem;
366} _ulldiv_t;
367#endif
368
369extern char **environ;
370
371extern const unsigned char _osminor;
372extern const unsigned char _osmajor;
373
374/* No DOS support ... */
375#define _osmode OS2_MODE
376
377unsigned alarm (unsigned);
378int brk(const void *);
379int chdir (const char *);
380char *gcvt (double, int, char *); /* this is rubbish standardwise */
381char *getcwd (char *, size_t);
382int getpagesize (void);
383char *getwd (char *);
384int mkdir(const char *, mode_t);
385void perror (const char *);
386int rmdir (const char *);
387void *sbrk(intptr_t);
388unsigned sleep (unsigned);
389long ulimit (int, ...);
390
391char *itoa (int, char *, int);
392char *ltoa (long, char *, int);
393char *ultoa (unsigned long, char *, int);
394char *lltoa (long long, char *, int);
395char *ulltoa (unsigned long long, char *, int);
396
397#endif
398
399
400#if (!defined (__STRICT_ANSI__) && !defined (_POSIX_SOURCE)) || defined (_WITH_UNDERSCORE) || defined(__USE_EMX)
401
402extern char **_environ;
403extern const char * const _sys_errlist[];
404extern const int _sys_nerr;
405
406unsigned _alarm (unsigned);
407int _brk(const void *);
408int _chdir (const char *);
409char *_gcvt (double, int, char *);
410char *_getcwd (char *, size_t);
411int _getpagesize (void);
412char *_getwd (char *);
413int _mkdir (const char *, long);
414int _putenv (const char *);
415int _rmdir (const char *);
416void *_sbrk(intptr_t);
417unsigned _sleep (unsigned);
418void _swab (const void *, void *, size_t);
419long _ulimit (int, ...);
420
421int _abspath (char *, const char *, int);
422long long _atoll (const char *);
423long double _atofl (const char *);
424int _chdir2 (const char *);
425int _chdir_os2 (const char *);
426int _chdrive (int);
427int _core (int);
428void _defext (char *, const char *);
429void _envargs (int *, char ***, const char *);
430int _execname (char *, size_t);
431void _exit (int) __attribute__ ((__noreturn__));
432int _filesys (const char *, char *, size_t);
433char **_fnexplode (const char *);
434void _fnexplodefree (char **);
435char _fngetdrive (const char *);
436int _fnisabs (const char *);
437int _fnisrel (const char *);
438void _fnlwr (char *);
439void _fnlwr2 (char *, const char *);
440char *_fnslashify (char *);
441int _fullpath (char *, const char *, int);
442int _getcwd1 (char *, char);
443char *_getcwd2 (char *, int);
444int _getdrive (void);
445char *_getext (const char *);
446char *_getext2 (const char *);
447char *_getname (const char *);
448int _getsockhandle (int);
449int _gettid (void);
450char *_getvol (char);
451char *_itoa (int, char *, int);
452_lldiv_t _lldiv (long long, long long);
453char *_lltoa (long long, char *, int);
454_uldiv_t _uldiv (unsigned long, unsigned long);
455_ulldiv_t _ulldiv (unsigned long long, unsigned long long);
456char *_itoa (int, char *, int);
457char *_ltoa (long, char *, int);
458char *_ultoa (unsigned long, char *, int);
459char *_lltoa (long long, char *, int);
460char *_ulltoa (unsigned long long, char *, int);
461void _makepath (char *, const char *, const char *,
462 const char *, const char *);
463int _path (char *, const char *);
464int _path2(const char *pszName, const char *pszSuffixes, char *pszDst, size_t cbDst);
465int _read_kbd (int, int, int);
466void _remext (char *);
467void _rfnlwr (void);
468void _response (int *, char ***);
469void _scrsize (int *);
470void _searchenv (const char *, const char *, char *);
471int _searchenv2(const char *pszEnvVar, const char *pszName, unsigned fFlags, const char *pszSuffixes,
472 char *pszDst, size_t cbDst);
473int _searchenv2_value(const char *pszSearchPath, const char *pszName, unsigned fFlags, const char *pszSuffixes,
474 char *pszDst, size_t cbDst);
475int _searchenv2_has_suffix(const char *pszName, size_t cchName, const char *pszSuffixes);
476int _searchenv2_one_file(char *pszDst, size_t cbDst, size_t cchName, unsigned fFlags, const char *pszSuffixes);
477/** @name _SEARCHENV2_F_XXX - Flags for _searchenv2(), _searchenv2_value()
478 * and _searchenv2_one_file().
479 * @{ */
480/** Indicates that we're searching for an executable file. */
481#define _SEARCHENV2_F_EXEC_FILE 1
482/** Indicates that we shouldn't explicitly check the current directory before
483 * searching the search path. */
484#define _SEARCHENV2_F_SKIP_CURDIR 2
485/** @} */
486
487void _sfnlwr (const char *);
488unsigned _sleep2 (unsigned);
489char ** _splitargs (char *, int *);
490void _splitpath (const char *, char *, char *, char *, char *);
491float _strtof (const char *, char **);
492long double _strtold (const char *, char **);
493long long _strtoll (const char *, char **, int);
494unsigned long long _strtoull (const char *, char **, int);
495char _swchar (void);
496void _wildcard (int *, char ***);
497
498int _beginthread (void (*)(void *), void *, unsigned, void *);
499void _endthread (void);
500void **_threadstore (void);
501
502int _setenv(const char *envname, const char *envval, int overwrite);
503int _unsetenv(const char *name);
504
505#endif
506
507__END_DECLS
508
509/* bird: EMX/PC stuff - end */
510
511#endif /* !_STDLIB_H_ */
512
Note: See TracBrowser for help on using the repository browser.