VC98\include\stdlib.h文件全部内容
我们先来看看古老的TC2中stdlib.h文件的内容,如下:
TC2下的stdlib.h
1/**//* stdlib.h
2
3 Definitions for common types, variables, and functions.
4
5 Copyright (c) Borland International 1987,1988
6 All Rights Reserved.
7*/
8#if __STDC__
9#define _Cdecl
10#else
11#define _Cdecl cdecl
12#endif
13
14#if !defined(__STDLIB)
15#define __STDLIB
16
17#ifndef _SIZE_T
18#define _SIZE_T
19typedef unsigned size_t;
20#endif
21
22#ifndef _DIV_T
23#define _DIV_T
24typedef struct {
25 int quot;
26 int rem;
27} div_t;
28#endif
29
30#ifndef _LDIV_T
31#define _LDIV_T
32typedef struct {
33 long quot;
34 long rem;
35} ldiv_t;
36#endif
37
38#define EXIT_SUCCESS 0
39#define EXIT_FAILURE 1
40
41/**//* Maximum value returned by "rand" function
42*/
43#define RAND_MAX 0x7FFF
44
45typedef void _Cdecl (* atexit_t)(void);
46
47void _Cdecl abort (void);
48int _Cdecl abs (int x);
49int _Cdecl atexit (atexit_t func);
50double _Cdecl atof (const char *s);
51int _Cdecl atoi (const char *s);
52long _Cdecl atol (const char *s);
53void *_Cdecl bsearch(const void *key, const void *base,
54 size_t nelem, size_t width,
55 int _Cdecl (*fcmp)(/**//* const void *, const void * */));
56void *_Cdecl calloc (size_t nitems, size_t size);
57div_t _Cdecl div (int numer, int denom);
58void _Cdecl exit (int status);
59void _Cdecl free (void *block);
60char *_Cdecl getenv (const char *name);
61long _Cdecl labs (long x);
62ldiv_t _Cdecl ldiv (long numer, long denom);
63void *_Cdecl malloc (size_t size);
64void _Cdecl qsort (void *base, size_t nelem, size_t width,
65 int _Cdecl (*fcmp)(/**//* const void *, const void * */));
66int _Cdecl rand (void);
67void *_Cdecl realloc(void *block, size_t size);
68void _Cdecl srand (unsigned seed);
69double _Cdecl strtod (const char *s, char **endptr);
70long _Cdecl strtol (const char *s, char **endptr, int radix);
71unsigned long _Cdecl strtoul (const char *s, char **endptr, int radix);
72int _Cdecl system (const char *command);
73
74#if !__STDC__
75
76#ifndef NULL
77#if defined(__TINY__) || defined(__SMALL__) || defined(__MEDIUM__)
78#define NULL 0
79#else
80#define NULL 0L
81#endif
82#endif
83
84/**//* Variables */
85extern int _Cdecl _doserrno;
86extern char **_Cdecl environ;
87extern int _Cdecl errno;
88extern int _Cdecl _fmode;
89extern unsigned char _Cdecl _osmajor;
90extern unsigned char _Cdecl _osminor;
91extern unsigned _Cdecl _psp;
92extern char *_Cdecl sys_errlist[];
93extern int _Cdecl sys_nerr;
94extern unsigned int _Cdecl _version;
95
96int _Cdecl __abs__(int x); /**//* This is an in-line function */
97#define abs(x) __abs__(x)
98#define atoi(s) ((int) atol (s))
99
100#define max(a,b) (((a) > (b)) ? (a) : (b))
101#define min(a,b) (((a) < (b)) ? (a) : (b))
102
103#define random(num) (rand() % (num))
104#define randomize() srand((unsigned)time(NULL))
105
106char *_Cdecl ecvt (double value, int ndig, int *dec, int *sign);
107void _Cdecl _exit (int status);
108char *_Cdecl fcvt (double value, int ndig, int *dec, int *sign);
109char *_Cdecl gcvt (double value, int ndec, char *buf);
110char *_Cdecl itoa (int value, char *string, int radix);
111void *_Cdecl lfind (const void *key, const void *base,
112 size_t *num, size_t width,
113 int _Cdecl (*fcmp)(/**//* const void *, const void * */));
114
115unsigned long _Cdecl _lrotl(unsigned long val, int count);
116unsigned long _Cdecl _lrotr(unsigned long val, int count);
117
118void *_Cdecl lsearch (const void *key, void *base,
119 size_t *num, size_t width,
120 int _Cdecl (*fcmp)(/**//* const void *, const void * */));
121char *_Cdecl ltoa (long value, char *string, int radix);
122int _Cdecl putenv (const char *name);
123
124unsigned _Cdecl _rotl (unsigned value, int count);
125unsigned _Cdecl _rotr (unsigned value, int count);
126
127void _Cdecl swab (char *from, char *to, int nbytes);
128char *_Cdecl ultoa (unsigned long value, char *string, int radix);
129#endif
130
131#endif
132
1/**//* stdlib.h
2
3 Definitions for common types, variables, and functions.
4
5 Copyright (c) Borland International 1987,1988
6 All Rights Reserved.
7*/
8#if __STDC__
9#define _Cdecl
10#else
11#define _Cdecl cdecl
12#endif
13
14#if !defined(__STDLIB)
15#define __STDLIB
16
17#ifndef _SIZE_T
18#define _SIZE_T
19typedef unsigned size_t;
20#endif
21
22#ifndef _DIV_T
23#define _DIV_T
24typedef struct {
25 int quot;
26 int rem;
27} div_t;
28#endif
29
30#ifndef _LDIV_T
31#define _LDIV_T
32typedef struct {
33 long quot;
34 long rem;
35} ldiv_t;
36#endif
37
38#define EXIT_SUCCESS 0
39#define EXIT_FAILURE 1
40
41/**//* Maximum value returned by "rand" function
42*/
43#define RAND_MAX 0x7FFF
44
45typedef void _Cdecl (* atexit_t)(void);
46
47void _Cdecl abort (void);
48int _Cdecl abs (int x);
49int _Cdecl atexit (atexit_t func);
50double _Cdecl atof (const char *s);
51int _Cdecl atoi (const char *s);
52long _Cdecl atol (const char *s);
53void *_Cdecl bsearch(const void *key, const void *base,
54 size_t nelem, size_t width,
55 int _Cdecl (*fcmp)(/**//* const void *, const void * */));
56void *_Cdecl calloc (size_t nitems, size_t size);
57div_t _Cdecl div (int numer, int denom);
58void _Cdecl exit (int status);
59void _Cdecl free (void *block);
60char *_Cdecl getenv (const char *name);
61long _Cdecl labs (long x);
62ldiv_t _Cdecl ldiv (long numer, long denom);
63void *_Cdecl malloc (size_t size);
64void _Cdecl qsort (void *base, size_t nelem, size_t width,
65 int _Cdecl (*fcmp)(/**//* const void *, const void * */));
66int _Cdecl rand (void);
67void *_Cdecl realloc(void *block, size_t size);
68void _Cdecl srand (unsigned seed);
69double _Cdecl strtod (const char *s, char **endptr);
70long _Cdecl strtol (const char *s, char **endptr, int radix);
71unsigned long _Cdecl strtoul (const char *s, char **endptr, int radix);
72int _Cdecl system (const char *command);
73
74#if !__STDC__
75
76#ifndef NULL
77#if defined(__TINY__) || defined(__SMALL__) || defined(__MEDIUM__)
78#define NULL 0
79#else
80#define NULL 0L
81#endif
82#endif
83
84/**//* Variables */
85extern int _Cdecl _doserrno;
86extern char **_Cdecl environ;
87extern int _Cdecl errno;
88extern int _Cdecl _fmode;
89extern unsigned char _Cdecl _osmajor;
90extern unsigned char _Cdecl _osminor;
91extern unsigned _Cdecl _psp;
92extern char *_Cdecl sys_errlist[];
93extern int _Cdecl sys_nerr;
94extern unsigned int _Cdecl _version;
95
96int _Cdecl __abs__(int x); /**//* This is an in-line function */
97#define abs(x) __abs__(x)
98#define atoi(s) ((int) atol (s))
99
100#define max(a,b) (((a) > (b)) ? (a) : (b))
101#define min(a,b) (((a) < (b)) ? (a) : (b))
102
103#define random(num) (rand() % (num))
104#define randomize() srand((unsigned)time(NULL))
105
106char *_Cdecl ecvt (double value, int ndig, int *dec, int *sign);
107void _Cdecl _exit (int status);
108char *_Cdecl fcvt (double value, int ndig, int *dec, int *sign);
109char *_Cdecl gcvt (double value, int ndec, char *buf);
110char *_Cdecl itoa (int value, char *string, int radix);
111void *_Cdecl lfind (const void *key, const void *base,
112 size_t *num, size_t width,
113 int _Cdecl (*fcmp)(/**//* const void *, const void * */));
114
115unsigned long _Cdecl _lrotl(unsigned long val, int count);
116unsigned long _Cdecl _lrotr(unsigned long val, int count);
117
118void *_Cdecl lsearch (const void *key, void *base,
119 size_t *num, size_t width,
120 int _Cdecl (*fcmp)(/**//* const void *, const void * */));
121char *_Cdecl ltoa (long value, char *string, int radix);
122int _Cdecl putenv (const char *name);
123
124unsigned _Cdecl _rotl (unsigned value, int count);
125unsigned _Cdecl _rotr (unsigned value, int count);
126
127void _Cdecl swab (char *from, char *to, int nbytes);
128char *_Cdecl ultoa (unsigned long value, char *string, int radix);
129#endif
130
131#endif
132
我们再来看看MS的VC编译器中的stdlib.h文件的内容,如下:
MS的VC编译器中附带的stdlib.h
1/**//***
2*stdlib.h - declarations/definitions for commonly used library functions
3*
4* Copyright (c) 1985-1997, Microsoft Corporation. All rights reserved.
5*
6*Purpose:
7* This include file contains the function declarations for commonly
8* used library functions which either don't fit somewhere else, or,
9* cannot be declared in the normal place for other reasons.
10* [ANSI]
11*
12* [Public]
13*
14****/
15
16#if _MSC_VER > 1000
17#pragma once
18#endif
19
20#ifndef _INC_STDLIB
21#define _INC_STDLIB
22
23#if !defined(_WIN32) && !defined(_MAC)
24#error ERROR: Only Mac or Win32 targets supported!
25#endif
26
27
28#ifdef _MSC_VER
29/**//*
30 * Currently, all MS C compilers for Win32 platforms default to 8 byte
31 * alignment.
32 */
33#pragma pack(push,8)
34#endif /* _MSC_VER */
35
36#ifdef __cplusplus
37extern "C" {
38#endif
39
40
41
42/**//* Define _CRTIMP */
43
44#ifndef _CRTIMP
45#ifdef _DLL
46#define _CRTIMP __declspec(dllimport)
47#else /* ndef _DLL */
48#define _CRTIMP
49#endif /* _DLL */
50#endif /* _CRTIMP */
51
52
53/**//* Define __cdecl for non-Microsoft compilers */
54
55#if ( !defined(_MSC_VER) && !defined(__cdecl) )
56#define __cdecl
57#endif
58
59/**//* Define _CRTAPI1 (for compatibility with the NT SDK) */
60
61#ifndef _CRTAPI1
62#if _MSC_VER >= 800 && _M_IX86 >= 300
63#define _CRTAPI1 __cdecl
64#else
65#define _CRTAPI1
66#endif
67#endif
68
69
70#ifndef _SIZE_T_DEFINED
71typedef unsigned int size_t;
72#define _SIZE_T_DEFINED
73#endif
74
75
76#ifndef _WCHAR_T_DEFINED
77typedef unsigned short wchar_t;
78#define _WCHAR_T_DEFINED
79#endif
80
81
82/**//* Define NULL pointer value */
83
84#ifndef NULL
85#ifdef __cplusplus
86#define NULL 0
87#else
88#define NULL ((void *)0)
89#endif
90#endif
91
92
93/**//* Definition of the argument values for the exit() function */
94
95#define EXIT_SUCCESS 0
96#define EXIT_FAILURE 1
97
98
99#ifndef _ONEXIT_T_DEFINED
100typedef int (__cdecl * _onexit_t)(void);
101#if !__STDC__
102/**//* Non-ANSI name for compatibility */
103#define onexit_t _onexit_t
104#endif
105#define _ONEXIT_T_DEFINED
106#endif
107
108
109/**//* Data structure definitions for div and ldiv runtimes. */
110
111#ifndef _DIV_T_DEFINED
112
113typedef struct _div_t {
114 int quot;
115 int rem;
116} div_t;
117
118typedef struct _ldiv_t {
119 long quot;
120 long rem;
121} ldiv_t;
122
123#define _DIV_T_DEFINED
124#endif
125
126
127/**//* Maximum value that can be returned by the rand function. */
128
129#define RAND_MAX 0x7fff
130
131/**//*
132 * Maximum number of bytes in multi-byte character in the current locale
133 * (also defined in ctype.h).
134 */
135#ifndef MB_CUR_MAX
136#define MB_CUR_MAX __mb_cur_max
137_CRTIMP extern int __mb_cur_max;
138#endif /* MB_CUR_MAX */
139
140
141/**//* Minimum and maximum macros */
142
143#define __max(a,b) (((a) > (b)) ? (a) : (b))
144#define __min(a,b) (((a) < (b)) ? (a) : (b))
145
146/**//*
147 * Sizes for buffers used by the _makepath() and _splitpath() functions.
148 * note that the sizes include space for 0-terminator
149 */
150#ifndef _MAC
151#define _MAX_PATH 260 /* max. length of full pathname */
152#define _MAX_DRIVE 3 /* max. length of drive component */
153#define _MAX_DIR 256 /* max. length of path component */
154#define _MAX_FNAME 256 /* max. length of file name component */
155#define _MAX_EXT 256 /* max. length of extension component */
156#else /* def _MAC */
157#define _MAX_PATH 256 /* max. length of full pathname */
158#define _MAX_DIR 32 /* max. length of path component */
159#define _MAX_FNAME 64 /* max. length of file name component */
160#endif /* _MAC */
161
162/**//*
163 * Argument values for _set_error_mode().
164 */
165#define _OUT_TO_DEFAULT 0
166#define _OUT_TO_STDERR 1
167#define _OUT_TO_MSGBOX 2
168#define _REPORT_ERRMODE 3
169
170
171/**//* External variable declarations */
172
173#if (defined(_MT) || defined(_DLL)) && !defined(_MAC)
174_CRTIMP int * __cdecl _errno(void);
175_CRTIMP unsigned long * __cdecl __doserrno(void);
176#define errno (*_errno())
177#define _doserrno (*__doserrno())
178#else /* ndef _MT && ndef _DLL */
179_CRTIMP extern int errno; /**//* XENIX style error number */
180_CRTIMP extern unsigned long _doserrno; /**//* OS system error value */
181#endif /* _MT || _DLL */
182
183
184#ifdef _MAC
185_CRTIMP extern int _macerrno; /**//* OS system error value */
186#endif
187
188
189_CRTIMP extern char * _sys_errlist[]; /**//* perror error message table */
190_CRTIMP extern int _sys_nerr; /**//* # of entries in sys_errlist table */
191
192
193#if defined(_DLL) && defined(_M_IX86)
194
195#define __argc (*__p___argc()) /* count of cmd line args */
196#define __argv (*__p___argv()) /* pointer to table of cmd line args */
197#define __wargv (*__p___wargv()) /* pointer to table of wide cmd line args */
198#define _environ (*__p__environ()) /* pointer to environment table */
199#ifdef _POSIX_
200extern char ** environ; /**//* pointer to environment table */
201#else
202#ifndef _MAC
203#define _wenviron (*__p__wenviron()) /* pointer to wide environment table */
204#endif /* ndef _MAC */
205#endif /* _POSIX_ */
206#define _pgmptr (*__p__pgmptr()) /* points to the module (EXE) name */
207#ifndef _MAC
208#define _wpgmptr (*__p__wpgmptr()) /* points to the module (EXE) wide name */
209#endif /* ndef _MAC */
210
211_CRTIMP int * __cdecl __p___argc(void);
212_CRTIMP char *** __cdecl __p___argv(void);
213_CRTIMP wchar_t *** __cdecl __p___wargv(void);
214_CRTIMP char *** __cdecl __p__environ(void);
215_CRTIMP wchar_t *** __cdecl __p__wenviron(void);
216_CRTIMP char ** __cdecl __p__pgmptr(void);
217_CRTIMP wchar_t ** __cdecl __p__wpgmptr(void);
218
219
220#else
221
222_CRTIMP extern int __argc; /**//* count of cmd line args */
223_CRTIMP extern char ** __argv; /**//* pointer to table of cmd line args */
224#ifndef _MAC
225_CRTIMP extern wchar_t ** __wargv; /**//* pointer to table of wide cmd line args */
226#endif /* ndef _MAC */
227
228#ifdef _POSIX_
229extern char ** environ; /**//* pointer to environment table */
230#else
231_CRTIMP extern char ** _environ; /**//* pointer to environment table */
232#ifndef _MAC
233_CRTIMP extern wchar_t ** _wenviron; /**//* pointer to wide environment table */
234#endif /* ndef _MAC */
235#endif /* _POSIX_ */
236
237_CRTIMP extern char * _pgmptr; /**//* points to the module (EXE) name */
238#ifndef _MAC
239_CRTIMP extern wchar_t * _wpgmptr; /**//* points to the module (EXE) wide name */
240#endif /* ndef _MAC */
241
242#endif
243
244
245_CRTIMP extern int _fmode; /**//* default file translation mode */
246_CRTIMP extern int _fileinfo; /**//* open file info mode (for spawn) */
247
248
249/**//* Windows major/minor and O.S. version numbers */
250
251_CRTIMP extern unsigned int _osver;
252_CRTIMP extern unsigned int _winver;
253_CRTIMP extern unsigned int _winmajor;
254_CRTIMP extern unsigned int _winminor;
255
256
257/**//* function prototypes */
258
259#if _MSC_VER >= 1200
260_CRTIMP __declspec(noreturn) void __cdecl abort(void);
261_CRTIMP __declspec(noreturn) void __cdecl exit(int);
262#else
263_CRTIMP void __cdecl abort(void);
264_CRTIMP void __cdecl exit(int);
265#endif
266
267#if defined(_M_MRX000)
268_CRTIMP int __cdecl abs(int);
269#else
270 int __cdecl abs(int);
271#endif
272 int __cdecl atexit(void (__cdecl *)(void));
273_CRTIMP double __cdecl atof(const char *);
274_CRTIMP int __cdecl atoi(const char *);
275_CRTIMP long __cdecl atol(const char *);
276#ifdef _M_M68K
277_CRTIMP long double __cdecl _atold(const char *);
278#endif
279_CRTIMP void * __cdecl bsearch(const void *, const void *, size_t, size_t,
280 int (__cdecl *)(const void *, const void *));
281_CRTIMP void * __cdecl calloc(size_t, size_t);
282_CRTIMP div_t __cdecl div(int, int);
283_CRTIMP void __cdecl free(void *);
284_CRTIMP char * __cdecl getenv(const char *);
285_CRTIMP char * __cdecl _itoa(int, char *, int);
286#if _INTEGRAL_MAX_BITS >= 64
287_CRTIMP char * __cdecl _i64toa(__int64, char *, int);
288_CRTIMP char * __cdecl _ui64toa(unsigned __int64, char *, int);
289_CRTIMP __int64 __cdecl _atoi64(const char *);
290#endif
291#if defined(_M_MRX000)
292_CRTIMP long __cdecl labs(long);
293#else
294 long __cdecl labs(long);
295#endif
296_CRTIMP ldiv_t __cdecl ldiv(long, long);
297_CRTIMP char * __cdecl _ltoa(long, char *, int);
298_CRTIMP void * __cdecl malloc(size_t);
299_CRTIMP int __cdecl mblen(const char *, size_t);
300_CRTIMP size_t __cdecl _mbstrlen(const char *s);
301_CRTIMP int __cdecl mbtowc(wchar_t *, const char *, size_t);
302_CRTIMP size_t __cdecl mbstowcs(wchar_t *, const char *, size_t);
303_CRTIMP void __cdecl qsort(void *, size_t, size_t, int (__cdecl *)
304 (const void *, const void *));
305_CRTIMP int __cdecl rand(void);
306_CRTIMP void * __cdecl realloc(void *, size_t);
307_CRTIMP int __cdecl _set_error_mode(int);
308_CRTIMP void __cdecl srand(unsigned int);
309_CRTIMP double __cdecl strtod(const char *, char **);
310_CRTIMP long __cdecl strtol(const char *, char **, int);
311#ifdef _M_M68K
312_CRTIMP long double __cdecl _strtold(const char *, char **);
313#endif
314_CRTIMP unsigned long __cdecl strtoul(const char *, char **, int);
315#ifndef _MAC
316_CRTIMP int __cdecl system(const char *);
317#endif
318_CRTIMP char * __cdecl _ultoa(unsigned long, char *, int);
319_CRTIMP int __cdecl wctomb(char *, wchar_t);
320_CRTIMP size_t __cdecl wcstombs(char *, const wchar_t *, size_t);
321
322
323#ifndef _MAC
324#ifndef _WSTDLIB_DEFINED
325
326/**//* wide function prototypes, also declared in wchar.h */
327
328_CRTIMP wchar_t * __cdecl _itow (int, wchar_t *, int);
329_CRTIMP wchar_t * __cdecl _ltow (long, wchar_t *, int);
330_CRTIMP wchar_t * __cdecl _ultow (unsigned long, wchar_t *, int);
331_CRTIMP double __cdecl wcstod(const wchar_t *, wchar_t **);
332_CRTIMP long __cdecl wcstol(const wchar_t *, wchar_t **, int);
333_CRTIMP unsigned long __cdecl wcstoul(const wchar_t *, wchar_t **, int);
334_CRTIMP wchar_t * __cdecl _wgetenv(const wchar_t *);
335_CRTIMP int __cdecl _wsystem(const wchar_t *);
336_CRTIMP int __cdecl _wtoi(const wchar_t *);
337_CRTIMP long __cdecl _wtol(const wchar_t *);
338#if _INTEGRAL_MAX_BITS >= 64
339_CRTIMP wchar_t * __cdecl _i64tow(__int64, wchar_t *, int);
340_CRTIMP wchar_t * __cdecl _ui64tow(unsigned __int64, wchar_t *, int);
341_CRTIMP __int64 __cdecl _wtoi64(const wchar_t *);
342#endif
343
344#define _WSTDLIB_DEFINED
345#endif
346#endif /* ndef _MAC */
347
348
349#ifndef _POSIX_
350
351_CRTIMP char * __cdecl _ecvt(double, int, int *, int *);
352#if _MSC_VER >= 1200
353_CRTIMP __declspec(noreturn) void __cdecl _exit(int);
354#else
355_CRTIMP void __cdecl _exit(int);
356#endif
357_CRTIMP char * __cdecl _fcvt(double, int, int *, int *);
358_CRTIMP char * __cdecl _fullpath(char *, const char *, size_t);
359_CRTIMP char * __cdecl _gcvt(double, int, char *);
360 unsigned long __cdecl _lrotl(unsigned long, int);
361 unsigned long __cdecl _lrotr(unsigned long, int);
362#ifndef _MAC
363_CRTIMP void __cdecl _makepath(char *, const char *, const char *, const char *,
364 const char *);
365#endif
366 _onexit_t __cdecl _onexit(_onexit_t);
367_CRTIMP void __cdecl perror(const char *);
368_CRTIMP int __cdecl _putenv(const char *);
369 unsigned int __cdecl _rotl(unsigned int, int);
370 unsigned int __cdecl _rotr(unsigned int, int);
371_CRTIMP void __cdecl _searchenv(const char *, const char *, char *);
372#ifndef _MAC
373_CRTIMP void __cdecl _splitpath(const char *, char *, char *, char *, char *);
374#endif
375_CRTIMP void __cdecl _swab(char *, char *, int);
376
377#ifndef _MAC
378#ifndef _WSTDLIBP_DEFINED
379
380/**//* wide function prototypes, also declared in wchar.h */
381
382_CRTIMP wchar_t * __cdecl _wfullpath(wchar_t *, const wchar_t *, size_t);
383_CRTIMP void __cdecl _wmakepath(wchar_t *, const wchar_t *, const wchar_t *, const wchar_t *,
384 const wchar_t *);
385_CRTIMP void __cdecl _wperror(const wchar_t *);
386_CRTIMP int __cdecl _wputenv(const wchar_t *);
387_CRTIMP void __cdecl _wsearchenv(const wchar_t *, const wchar_t *, wchar_t *);
388_CRTIMP void __cdecl _wsplitpath(const wchar_t *, wchar_t *, wchar_t *, wchar_t *, wchar_t *);
389
390#define _WSTDLIBP_DEFINED
391#endif
392#endif /* ndef _MAC */
393
394/**//* --------- The following functions are OBSOLETE --------- */
395/**//* The Win32 API SetErrorMode, Beep and Sleep should be used instead. */
396#ifndef _MAC
397_CRTIMP void __cdecl _seterrormode(int);
398_CRTIMP void __cdecl _beep(unsigned, unsigned);
399_CRTIMP void __cdecl _sleep(unsigned long);
400#endif /* ndef _MAC */
401/**//* --------- The preceding functions are OBSOLETE --------- */
402
403#endif /* _POSIX_ */
404
405
406#if !__STDC__
407/**//* --------- The declarations below should not be in stdlib.h --------- */
408/**//* --------- and will be removed in a future release. Include --------- */
409/**//* --------- ctype.h to obtain these declarations. --------- */
410#ifndef tolower /**//* tolower has been undefined - use function */
411_CRTIMP int __cdecl tolower(int);
412#endif /* tolower */
413#ifndef toupper /**//* toupper has been undefined - use function */
414_CRTIMP int __cdecl toupper(int);
415#endif /* toupper */
416/**//* --------- The declarations above will be removed. --------- */
417#endif
418
419
420#if !__STDC__
421
422#ifndef _POSIX_
423
424/**//* Non-ANSI names for compatibility */
425
426#ifndef __cplusplus
427#define max(a,b) (((a) > (b)) ? (a) : (b))
428#define min(a,b) (((a) < (b)) ? (a) : (b))
429#endif
430
431#define sys_errlist _sys_errlist
432#define sys_nerr _sys_nerr
433#define environ _environ
434
435_CRTIMP char * __cdecl ecvt(double, int, int *, int *);
436_CRTIMP char * __cdecl fcvt(double, int, int *, int *);
437_CRTIMP char * __cdecl gcvt(double, int, char *);
438_CRTIMP char * __cdecl itoa(int, char *, int);
439_CRTIMP char * __cdecl ltoa(long, char *, int);
440 onexit_t __cdecl onexit(onexit_t);
441_CRTIMP int __cdecl putenv(const char *);
442_CRTIMP void __cdecl swab(char *, char *, int);
443_CRTIMP char * __cdecl ultoa(unsigned long, char *, int);
444
445#endif /* _POSIX_ */
446
447#endif /* __STDC__ */
448
449#ifdef __cplusplus
450}
451
452#endif
453
454#ifdef _MSC_VER
455#pragma pack(pop)
456#endif /* _MSC_VER */
457
458#endif /* _INC_STDLIB */
459
1/**//***
2*stdlib.h - declarations/definitions for commonly used library functions
3*
4* Copyright (c) 1985-1997, Microsoft Corporation. All rights reserved.
5*
6*Purpose:
7* This include file contains the function declarations for commonly
8* used library functions which either don't fit somewhere else, or,
9* cannot be declared in the normal place for other reasons.
10* [ANSI]
11*
12* [Public]
13*
14****/
15
16#if _MSC_VER > 1000
17#pragma once
18#endif
19
20#ifndef _INC_STDLIB
21#define _INC_STDLIB
22
23#if !defined(_WIN32) && !defined(_MAC)
24#error ERROR: Only Mac or Win32 targets supported!
25#endif
26
27
28#ifdef _MSC_VER
29/**//*
30 * Currently, all MS C compilers for Win32 platforms default to 8 byte
31 * alignment.
32 */
33#pragma pack(push,8)
34#endif /* _MSC_VER */
35
36#ifdef __cplusplus
37extern "C" {
38#endif
39
40
41
42/**//* Define _CRTIMP */
43
44#ifndef _CRTIMP
45#ifdef _DLL
46#define _CRTIMP __declspec(dllimport)
47#else /* ndef _DLL */
48#define _CRTIMP
49#endif /* _DLL */
50#endif /* _CRTIMP */
51
52
53/**//* Define __cdecl for non-Microsoft compilers */
54
55#if ( !defined(_MSC_VER) && !defined(__cdecl) )
56#define __cdecl
57#endif
58
59/**//* Define _CRTAPI1 (for compatibility with the NT SDK) */
60
61#ifndef _CRTAPI1
62#if _MSC_VER >= 800 && _M_IX86 >= 300
63#define _CRTAPI1 __cdecl
64#else
65#define _CRTAPI1
66#endif
67#endif
68
69
70#ifndef _SIZE_T_DEFINED
71typedef unsigned int size_t;
72#define _SIZE_T_DEFINED
73#endif
74
75
76#ifndef _WCHAR_T_DEFINED
77typedef unsigned short wchar_t;
78#define _WCHAR_T_DEFINED
79#endif
80
81
82/**//* Define NULL pointer value */
83
84#ifndef NULL
85#ifdef __cplusplus
86#define NULL 0
87#else
88#define NULL ((void *)0)
89#endif
90#endif
91
92
93/**//* Definition of the argument values for the exit() function */
94
95#define EXIT_SUCCESS 0
96#define EXIT_FAILURE 1
97
98
99#ifndef _ONEXIT_T_DEFINED
100typedef int (__cdecl * _onexit_t)(void);
101#if !__STDC__
102/**//* Non-ANSI name for compatibility */
103#define onexit_t _onexit_t
104#endif
105#define _ONEXIT_T_DEFINED
106#endif
107
108
109/**//* Data structure definitions for div and ldiv runtimes. */
110
111#ifndef _DIV_T_DEFINED
112
113typedef struct _div_t {
114 int quot;
115 int rem;
116} div_t;
117
118typedef struct _ldiv_t {
119 long quot;
120 long rem;
121} ldiv_t;
122
123#define _DIV_T_DEFINED
124#endif
125
126
127/**//* Maximum value that can be returned by the rand function. */
128
129#define RAND_MAX 0x7fff
130
131/**//*
132 * Maximum number of bytes in multi-byte character in the current locale
133 * (also defined in ctype.h).
134 */
135#ifndef MB_CUR_MAX
136#define MB_CUR_MAX __mb_cur_max
137_CRTIMP extern int __mb_cur_max;
138#endif /* MB_CUR_MAX */
139
140
141/**//* Minimum and maximum macros */
142
143#define __max(a,b) (((a) > (b)) ? (a) : (b))
144#define __min(a,b) (((a) < (b)) ? (a) : (b))
145
146/**//*
147 * Sizes for buffers used by the _makepath() and _splitpath() functions.
148 * note that the sizes include space for 0-terminator
149 */
150#ifndef _MAC
151#define _MAX_PATH 260 /* max. length of full pathname */
152#define _MAX_DRIVE 3 /* max. length of drive component */
153#define _MAX_DIR 256 /* max. length of path component */
154#define _MAX_FNAME 256 /* max. length of file name component */
155#define _MAX_EXT 256 /* max. length of extension component */
156#else /* def _MAC */
157#define _MAX_PATH 256 /* max. length of full pathname */
158#define _MAX_DIR 32 /* max. length of path component */
159#define _MAX_FNAME 64 /* max. length of file name component */
160#endif /* _MAC */
161
162/**//*
163 * Argument values for _set_error_mode().
164 */
165#define _OUT_TO_DEFAULT 0
166#define _OUT_TO_STDERR 1
167#define _OUT_TO_MSGBOX 2
168#define _REPORT_ERRMODE 3
169
170
171/**//* External variable declarations */
172
173#if (defined(_MT) || defined(_DLL)) && !defined(_MAC)
174_CRTIMP int * __cdecl _errno(void);
175_CRTIMP unsigned long * __cdecl __doserrno(void);
176#define errno (*_errno())
177#define _doserrno (*__doserrno())
178#else /* ndef _MT && ndef _DLL */
179_CRTIMP extern int errno; /**//* XENIX style error number */
180_CRTIMP extern unsigned long _doserrno; /**//* OS system error value */
181#endif /* _MT || _DLL */
182
183
184#ifdef _MAC
185_CRTIMP extern int _macerrno; /**//* OS system error value */
186#endif
187
188
189_CRTIMP extern char * _sys_errlist[]; /**//* perror error message table */
190_CRTIMP extern int _sys_nerr; /**//* # of entries in sys_errlist table */
191
192
193#if defined(_DLL) && defined(_M_IX86)
194
195#define __argc (*__p___argc()) /* count of cmd line args */
196#define __argv (*__p___argv()) /* pointer to table of cmd line args */
197#define __wargv (*__p___wargv()) /* pointer to table of wide cmd line args */
198#define _environ (*__p__environ()) /* pointer to environment table */
199#ifdef _POSIX_
200extern char ** environ; /**//* pointer to environment table */
201#else
202#ifndef _MAC
203#define _wenviron (*__p__wenviron()) /* pointer to wide environment table */
204#endif /* ndef _MAC */
205#endif /* _POSIX_ */
206#define _pgmptr (*__p__pgmptr()) /* points to the module (EXE) name */
207#ifndef _MAC
208#define _wpgmptr (*__p__wpgmptr()) /* points to the module (EXE) wide name */
209#endif /* ndef _MAC */
210
211_CRTIMP int * __cdecl __p___argc(void);
212_CRTIMP char *** __cdecl __p___argv(void);
213_CRTIMP wchar_t *** __cdecl __p___wargv(void);
214_CRTIMP char *** __cdecl __p__environ(void);
215_CRTIMP wchar_t *** __cdecl __p__wenviron(void);
216_CRTIMP char ** __cdecl __p__pgmptr(void);
217_CRTIMP wchar_t ** __cdecl __p__wpgmptr(void);
218
219
220#else
221
222_CRTIMP extern int __argc; /**//* count of cmd line args */
223_CRTIMP extern char ** __argv; /**//* pointer to table of cmd line args */
224#ifndef _MAC
225_CRTIMP extern wchar_t ** __wargv; /**//* pointer to table of wide cmd line args */
226#endif /* ndef _MAC */
227
228#ifdef _POSIX_
229extern char ** environ; /**//* pointer to environment table */
230#else
231_CRTIMP extern char ** _environ; /**//* pointer to environment table */
232#ifndef _MAC
233_CRTIMP extern wchar_t ** _wenviron; /**//* pointer to wide environment table */
234#endif /* ndef _MAC */
235#endif /* _POSIX_ */
236
237_CRTIMP extern char * _pgmptr; /**//* points to the module (EXE) name */
238#ifndef _MAC
239_CRTIMP extern wchar_t * _wpgmptr; /**//* points to the module (EXE) wide name */
240#endif /* ndef _MAC */
241
242#endif
243
244
245_CRTIMP extern int _fmode; /**//* default file translation mode */
246_CRTIMP extern int _fileinfo; /**//* open file info mode (for spawn) */
247
248
249/**//* Windows major/minor and O.S. version numbers */
250
251_CRTIMP extern unsigned int _osver;
252_CRTIMP extern unsigned int _winver;
253_CRTIMP extern unsigned int _winmajor;
254_CRTIMP extern unsigned int _winminor;
255
256
257/**//* function prototypes */
258
259#if _MSC_VER >= 1200
260_CRTIMP __declspec(noreturn) void __cdecl abort(void);
261_CRTIMP __declspec(noreturn) void __cdecl exit(int);
262#else
263_CRTIMP void __cdecl abort(void);
264_CRTIMP void __cdecl exit(int);
265#endif
266
267#if defined(_M_MRX000)
268_CRTIMP int __cdecl abs(int);
269#else
270 int __cdecl abs(int);
271#endif
272 int __cdecl atexit(void (__cdecl *)(void));
273_CRTIMP double __cdecl atof(const char *);
274_CRTIMP int __cdecl atoi(const char *);
275_CRTIMP long __cdecl atol(const char *);
276#ifdef _M_M68K
277_CRTIMP long double __cdecl _atold(const char *);
278#endif
279_CRTIMP void * __cdecl bsearch(const void *, const void *, size_t, size_t,
280 int (__cdecl *)(const void *, const void *));
281_CRTIMP void * __cdecl calloc(size_t, size_t);
282_CRTIMP div_t __cdecl div(int, int);
283_CRTIMP void __cdecl free(void *);
284_CRTIMP char * __cdecl getenv(const char *);
285_CRTIMP char * __cdecl _itoa(int, char *, int);
286#if _INTEGRAL_MAX_BITS >= 64
287_CRTIMP char * __cdecl _i64toa(__int64, char *, int);
288_CRTIMP char * __cdecl _ui64toa(unsigned __int64, char *, int);
289_CRTIMP __int64 __cdecl _atoi64(const char *);
290#endif
291#if defined(_M_MRX000)
292_CRTIMP long __cdecl labs(long);
293#else
294 long __cdecl labs(long);
295#endif
296_CRTIMP ldiv_t __cdecl ldiv(long, long);
297_CRTIMP char * __cdecl _ltoa(long, char *, int);
298_CRTIMP void * __cdecl malloc(size_t);
299_CRTIMP int __cdecl mblen(const char *, size_t);
300_CRTIMP size_t __cdecl _mbstrlen(const char *s);
301_CRTIMP int __cdecl mbtowc(wchar_t *, const char *, size_t);
302_CRTIMP size_t __cdecl mbstowcs(wchar_t *, const char *, size_t);
303_CRTIMP void __cdecl qsort(void *, size_t, size_t, int (__cdecl *)
304 (const void *, const void *));
305_CRTIMP int __cdecl rand(void);
306_CRTIMP void * __cdecl realloc(void *, size_t);
307_CRTIMP int __cdecl _set_error_mode(int);
308_CRTIMP void __cdecl srand(unsigned int);
309_CRTIMP double __cdecl strtod(const char *, char **);
310_CRTIMP long __cdecl strtol(const char *, char **, int);
311#ifdef _M_M68K
312_CRTIMP long double __cdecl _strtold(const char *, char **);
313#endif
314_CRTIMP unsigned long __cdecl strtoul(const char *, char **, int);
315#ifndef _MAC
316_CRTIMP int __cdecl system(const char *);
317#endif
318_CRTIMP char * __cdecl _ultoa(unsigned long, char *, int);
319_CRTIMP int __cdecl wctomb(char *, wchar_t);
320_CRTIMP size_t __cdecl wcstombs(char *, const wchar_t *, size_t);
321
322
323#ifndef _MAC
324#ifndef _WSTDLIB_DEFINED
325
326/**//* wide function prototypes, also declared in wchar.h */
327
328_CRTIMP wchar_t * __cdecl _itow (int, wchar_t *, int);
329_CRTIMP wchar_t * __cdecl _ltow (long, wchar_t *, int);
330_CRTIMP wchar_t * __cdecl _ultow (unsigned long, wchar_t *, int);
331_CRTIMP double __cdecl wcstod(const wchar_t *, wchar_t **);
332_CRTIMP long __cdecl wcstol(const wchar_t *, wchar_t **, int);
333_CRTIMP unsigned long __cdecl wcstoul(const wchar_t *, wchar_t **, int);
334_CRTIMP wchar_t * __cdecl _wgetenv(const wchar_t *);
335_CRTIMP int __cdecl _wsystem(const wchar_t *);
336_CRTIMP int __cdecl _wtoi(const wchar_t *);
337_CRTIMP long __cdecl _wtol(const wchar_t *);
338#if _INTEGRAL_MAX_BITS >= 64
339_CRTIMP wchar_t * __cdecl _i64tow(__int64, wchar_t *, int);
340_CRTIMP wchar_t * __cdecl _ui64tow(unsigned __int64, wchar_t *, int);
341_CRTIMP __int64 __cdecl _wtoi64(const wchar_t *);
342#endif
343
344#define _WSTDLIB_DEFINED
345#endif
346#endif /* ndef _MAC */
347
348
349#ifndef _POSIX_
350
351_CRTIMP char * __cdecl _ecvt(double, int, int *, int *);
352#if _MSC_VER >= 1200
353_CRTIMP __declspec(noreturn) void __cdecl _exit(int);
354#else
355_CRTIMP void __cdecl _exit(int);
356#endif
357_CRTIMP char * __cdecl _fcvt(double, int, int *, int *);
358_CRTIMP char * __cdecl _fullpath(char *, const char *, size_t);
359_CRTIMP char * __cdecl _gcvt(double, int, char *);
360 unsigned long __cdecl _lrotl(unsigned long, int);
361 unsigned long __cdecl _lrotr(unsigned long, int);
362#ifndef _MAC
363_CRTIMP void __cdecl _makepath(char *, const char *, const char *, const char *,
364 const char *);
365#endif
366 _onexit_t __cdecl _onexit(_onexit_t);
367_CRTIMP void __cdecl perror(const char *);
368_CRTIMP int __cdecl _putenv(const char *);
369 unsigned int __cdecl _rotl(unsigned int, int);
370 unsigned int __cdecl _rotr(unsigned int, int);
371_CRTIMP void __cdecl _searchenv(const char *, const char *, char *);
372#ifndef _MAC
373_CRTIMP void __cdecl _splitpath(const char *, char *, char *, char *, char *);
374#endif
375_CRTIMP void __cdecl _swab(char *, char *, int);
376
377#ifndef _MAC
378#ifndef _WSTDLIBP_DEFINED
379
380/**//* wide function prototypes, also declared in wchar.h */
381
382_CRTIMP wchar_t * __cdecl _wfullpath(wchar_t *, const wchar_t *, size_t);
383_CRTIMP void __cdecl _wmakepath(wchar_t *, const wchar_t *, const wchar_t *, const wchar_t *,
384 const wchar_t *);
385_CRTIMP void __cdecl _wperror(const wchar_t *);
386_CRTIMP int __cdecl _wputenv(const wchar_t *);
387_CRTIMP void __cdecl _wsearchenv(const wchar_t *, const wchar_t *, wchar_t *);
388_CRTIMP void __cdecl _wsplitpath(const wchar_t *, wchar_t *, wchar_t *, wchar_t *, wchar_t *);
389
390#define _WSTDLIBP_DEFINED
391#endif
392#endif /* ndef _MAC */
393
394/**//* --------- The following functions are OBSOLETE --------- */
395/**//* The Win32 API SetErrorMode, Beep and Sleep should be used instead. */
396#ifndef _MAC
397_CRTIMP void __cdecl _seterrormode(int);
398_CRTIMP void __cdecl _beep(unsigned, unsigned);
399_CRTIMP void __cdecl _sleep(unsigned long);
400#endif /* ndef _MAC */
401/**//* --------- The preceding functions are OBSOLETE --------- */
402
403#endif /* _POSIX_ */
404
405
406#if !__STDC__
407/**//* --------- The declarations below should not be in stdlib.h --------- */
408/**//* --------- and will be removed in a future release. Include --------- */
409/**//* --------- ctype.h to obtain these declarations. --------- */
410#ifndef tolower /**//* tolower has been undefined - use function */
411_CRTIMP int __cdecl tolower(int);
412#endif /* tolower */
413#ifndef toupper /**//* toupper has been undefined - use function */
414_CRTIMP int __cdecl toupper(int);
415#endif /* toupper */
416/**//* --------- The declarations above will be removed. --------- */
417#endif
418
419
420#if !__STDC__
421
422#ifndef _POSIX_
423
424/**//* Non-ANSI names for compatibility */
425
426#ifndef __cplusplus
427#define max(a,b) (((a) > (b)) ? (a) : (b))
428#define min(a,b) (((a) < (b)) ? (a) : (b))
429#endif
430
431#define sys_errlist _sys_errlist
432#define sys_nerr _sys_nerr
433#define environ _environ
434
435_CRTIMP char * __cdecl ecvt(double, int, int *, int *);
436_CRTIMP char * __cdecl fcvt(double, int, int *, int *);
437_CRTIMP char * __cdecl gcvt(double, int, char *);
438_CRTIMP char * __cdecl itoa(int, char *, int);
439_CRTIMP char * __cdecl ltoa(long, char *, int);
440 onexit_t __cdecl onexit(onexit_t);
441_CRTIMP int __cdecl putenv(const char *);
442_CRTIMP void __cdecl swab(char *, char *, int);
443_CRTIMP char * __cdecl ultoa(unsigned long, char *, int);
444
445#endif /* _POSIX_ */
446
447#endif /* __STDC__ */
448
449#ifdef __cplusplus
450}
451
452#endif
453
454#ifdef _MSC_VER
455#pragma pack(pop)
456#endif /* _MSC_VER */
457
458#endif /* _INC_STDLIB */
459
==================================================
我们首先关注的内容是下面的代码:(第42------50行)
1/**//* Define _CRTIMP */
2
3#ifndef _CRTIMP
4#ifdef _DLL
5#define _CRTIMP __declspec(dllimport)
6#else /* ndef _DLL */
7#define _CRTIMP
8#endif /* _DLL */
9#endif /* _CRTIMP */
2
3#ifndef _CRTIMP
4#ifdef _DLL
5#define _CRTIMP __declspec(dllimport)
6#else /* ndef _DLL */
7#define _CRTIMP
8#endif /* _DLL */
9#endif /* _CRTIMP */