还在苦苦敲代码开发APP?你out啦! 试试积木搭建APP吧~

Linux编程中各种头文件

来源:     2016-08-29 15:58:03    人气:     我有话说( 0 人参与)

2.stdlib.h stdlib 头文件里包含了C、C++语言的最常用的系统函数stdlib.h里面定义了五种类型、一些宏和通用工具函数。类型例如size_t、wc...

1.stdlib.h

 stdlib 头文件里包含了C、C++语言的最常用的系统函数

stdlib.h里面定义了五种类型、一些宏和通用工具函数。类型例如size_t、wchar_t、div_t、ldiv_t和lldiv_t;宏例如EXIT_FAILURE、EXIT_SUCCESS、RAND_MAX和MB_CUR_MAX等等;常用的函数如malloc()、calloc()、realloc()、free()、system()、atoi()、atol()、rand()、srand()、exit()等等

2.unistd.h
 是POSIX标准定义的unix类系统定义符号常量的头文件,包含了许多UNIX系统服务的函数原型,例如read函数、write函数和getpid函数
 

3. string.h

提供比如 bzero,bcopy,bcmp,memset,memcpy memcmp 等函数。

4.netdb.h定义了与网络有关的结构,变量类型,宏,函数。例如:

struct hostent *gethostbyaddr(const void *addr, size_t len, int type); struct hostent *gethostbyname(const char *name);
 
sys/types.h:数据类型定义
sys/socket.h:提供socket函数及数据结构
netinet/in.h:定义数据结构sockaddr_in
arpa/inet.h:提供IP地址转换函数如inet_pton,inet_ntop
netdb.h:提供设置及获取域名的函数
sys/ioctl.h:提供对I/O控制的函数
sys/poll.h:提供socket等待测试机制的函数
fcntl.h:提供对文件控制的函数
 
time.h:提供有关时间的函数
crypt.h:提供使用DES加密算法的加密函数
pwd.h:提供对/etc/passwd文件访问的函数
shadow.h:提供对/etc/shadow文件访问的函数
pthread.h:提供多线程操作的函数
signal.h:提供对信号操作的函数
sys/wait.h、sys/ipc.h、sys/shm.h:提供进程等待、进程间通讯(IPC)及共享内存的函数


建议在编写网络程序时,可以直接使用下面这段头文件代码
 #include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <errno.h>
#include <malloc.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/ioctl.h>
#include <stdarg.h>
#include <fcntl.h>
#include <fcntl.h>
 
 
 涉及到用户权限及密码验证问题时加入如下语句:
#include <shadow.h>
#include <crypt.h>
#include <pwd.h>
 需要注意的是,应该在编译时链接加密算法库,即增加编译选项:
-lcrypt

 
 涉及到文件及时间操作加入如下语句:
 #include <sys/time.h>
#include <utime.h>
#include <time.h>
#include <sys/stat.h>
#include <sys/file.h>

 
 涉及到多进程操作时加入如下语句:
 #include <sys/wait.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <signal.h>
 

 涉及到多线程操作时加入如下语句:
 #include <pthread.h>
#include <sys/poll.h>
需要注意的是,应该在编译时链接线程库,即增加编译选项:
-lthread

Linux编程 头文件

本文源自互联网,采用知识共享署名-非商业性使用 4.0 国际许可协议进行许可,
版权归原作者,如有问题请联系service@tsingfun.com (编辑:admin)
分享到: