(Owed by: 春夜喜雨 http://blog.csdn.net/chunyexiyu)
参考:https://www.tutorialspoint.com/c_standard_library/stdlib_h.htm
继续解析ANSI C标准库中的文件:按照下面个人理解的分类介绍
a. 测试及定义类:assert.h,errno.h,ctype.h,float.h,limits.h,locale.h,stddef.h,共计7个文件。
b. 语言特性:setjmp.h,stdarg.h,共计2个文件。
c. 信号处理:signal.h。
d. 输入输出:stdio.h。
e. 通用函数:math.h,string.h,time.h,stdlib,共计4个文件
通用函数
注:示例代码来源与turboc
stdlib.h
stdlib主要用来定义除数学库/字符串库/时间库之外的通用类型的库函数。函数库中定义了许多各种类型函数、变量、宏定义。
stdlib特征
a. 依赖:无头文件依赖;如果time_t,NULL类型未定义的话会就定义它。
b. 定义结构体div_t, ldiv_t,定义宏EXIT_SUCCESS/EXIT_FAILURE/RAND_MAX
c. 定义内存分配相关函数malloc/free/realloc/calloc
d. 定义了算法类的bsearch/qsort/lfind/lsearch
e. 定义了运行处理类的about/atexit/exit/system/_exit
f. 定义输出变量_doserrno/environ/errno/_fmode/_osminor/_psp/sys_errlist/sys_nerr/_version
g. 字符转换函数atof/atoi/atol/strtod/strtol/strtoul/itoa/ltoa/ultoa/ecvt/fcvt/gcvt/
h. 随机函数rand/srand,定义宏random/randomize
i. 取大小绝对值函数abs/labs/max/min
j. getenv/putenv–获取/设置环境变量名称关联值
k. div/ldiv–整数相除获取div_t/ldiv_t类型结果
l._rotl/_rotr/_lrotl/_lrotr: 左移/有移无符号数
m. swab: 交换奇偶字节复制到dst
stdlib源码
注:示例代码来源与turboc
#ifndef _SIZE_T
#define _SIZE_T
typedef unsigned size_t;
#endif
#ifndef _DIV_T
#define _DIV_T
typedef struct {
int quot;
int rem;
} div_t;
#endif
#ifndef _LDIV_T
#define _LDIV_T
typedef struct {
long quot;
long rem;
} ldiv_t;
#endif
#define EXIT_SUCCESS 0
#define EXIT_FAILURE 1
/* Maximum value returned by "rand" function
*/
#define RAND_MAX 0x7FFF
typedef void _Cdecl (* atexit_t)(void);
void _Cdecl abort (void);
int _Cdecl abs (int x);
int _Cdecl atexit (atexit_t func);
double _Cdecl atof (const char *s);
int _Cdecl atoi (const char *s);
long _Cdecl atol (const char *s);
void *_Cdecl bsearch(const void *key, const void *base,
size_t nelem, size_t width,
int _Cdecl (*fcmp)(/* const void *, const void * */));
void *_Cdecl calloc (size_t nitems, size_t size);
div_t _Cdecl div (int numer, int denom);
void _Cdecl exit (int status);
void _Cdecl free (void *block);
char *_Cdecl getenv (const char *name);
long _Cdecl labs (long x);
ldiv_t _Cdecl ldiv (long numer, long denom);
void *_Cdecl malloc (size_t size);
void _Cdecl qsort (void *base, size_t nelem, size_t width,
int _Cdecl (*fcmp)(/* const void *, const void * */));
int _Cdecl rand (void);
void *_Cdecl realloc(void *block, size_t size);
void _Cdecl srand (unsigned seed);
double _Cdecl strtod (const char *s, char **endptr);
long _Cdecl strtol (const char *s, char **endptr, int radix);
unsigned long _Cdecl strtoul (const char *s, char **endptr, int radix);
int _Cdecl system (const char *command);
#if !__STDC__
#ifndef NULL
#if defined(__TINY__) || defined(__SMALL__) || defined(__MEDIUM__)
#define NULL 0
#else
#define NULL 0L
#endif
#endif
/* Variables */
extern int _Cdecl _doserrno;
extern char **_Cdecl environ;
extern int _Cdecl errno;
extern int _Cdecl _fmode;
extern unsigned char _Cdecl _osmajor;
extern unsigned char _Cdecl _osminor;
extern unsigned _Cdecl _psp;
extern char *_Cdecl sys_errlist[];
extern int _Cdecl sys_nerr;
extern unsigned int _Cdecl _version;
int _Cdecl __abs__(int x); /* This is an in-line function */
#define abs(x) __abs__(x)
#define atoi(s) ((int) atol (s))
#define max(a,b) (((a) > (b)) ? (a) : (b))
#define min(a,b) (((a) < (b)) ? (a) : (b))
#define random(num) (rand() % (num))
#define randomize() srand((unsigned)time(NULL))
char *_Cdecl ecvt (double value, int ndig, int *dec, int *sign);
void _Cdecl _exit (int status);
char *_Cdecl fcvt (double value, int ndig, int *dec, int *sign);
char *_Cdecl gcvt (double value, int ndec, char *buf);
char *_Cdecl itoa (int value, char *string, int radix);
void *_Cdecl lfind (const void *key, const void *base,
size_t *num, size_t width,
int _Cdecl (*fcmp)(/* const void *, const void * */));
unsigned long _Cdecl _lrotl(unsigned long val, int count);
unsigned long _Cdecl _lrotr(unsigned long val, int count);
void *_Cdecl lsearch (const void *key, void *base,
size_t *num, size_t width,
int _Cdecl (*fcmp)(/* const void *, const void * */));
char *_Cdecl ltoa (long value, char *string, int radix);
int _Cdecl putenv (const char *name);
unsigned _Cdecl _rotl (unsigned value, int count);
unsigned _Cdecl _rotr (unsigned value, int count);
void _Cdecl swab (char *from, char *to, int nbytes);
char *_Cdecl ultoa (unsigned long value, char *string, int radix);
#endif
(Owed by: 春夜喜雨 http://blog.csdn.net/chunyexiyu)