int snprintf(char *str, size_t size, const char *format, ...);
功能:将可变参数(...)按照 format 格式化成字符串,并将字符串复制到 str 中,
size 为要写入的字符的最大数目,超过 size 会被截断。
参数:str:目标字符串
size:拷贝字节数(Bytes)
format:格式化成字符串
...:可变参数
返回:1.如果格式化后的字符串长度小于 size,
则会把字符串全部复制到 str 中,并给其后添加一个字符串结束符 \0;
2.如果格式化后的字符串长度大于等于 size,超过 size 的部分会被截断,
只将其中的 (size-1) 个字符复制到 str 中,并给其后添加一个字符串结束符 \0,返回值为欲写入的字符串长度。
long int atol(const char *str);
功能:把 str 所指向的字符串转换为一个长整数(long int)
返回:成功返回转换后的长整数
失败返回0
int stat(const char *path, struct stat *buf);
功能:获取文件信息
参1:文件路径(名)
参2:struct stat 类型的结构体
struct stat
{
dev_t st_dev; /* ID of device containing file */文件使用的设备号
ino_t st_ino; /* inode number */ 索引节点号
mode_t st_mode; /* protection */ 文件对应的模式,文件,目录等
nlink_t st_nlink; /* number of hard links */ 文件的硬连接数
uid_t st_uid; /* user ID of owner */ 所有者用户识别号
gid_t st_gid; /* group ID of owner */ 组识别号
dev_t st_rdev; /* device ID (if special file) */ 设备文件的设备号
off_t st_size; /* total size, in bytes */ 以字节为单位的文件容量
blksize_t st_blksize; /* blocksize for file system I/O */ 包含该文件的磁盘块的大小
blkcnt_t st_blocks; /* number of 512B blocks allocated */ 该文件所占的磁盘块
time_t st_atime; /* time of last access */ 最后一次访问该文件的时间
time_t st_mtime; /* time of last modification */ /最后一次修改该文件的时间
time_t st_ctime; /* time of last status change */ 最后一次改变该文件状态的时间
};
void * memalign (size_t boundary, size_t size);
功能:内存申请,区别与malloc的是,可以申请一个地址是boundary的倍数的内存块
malloc或realloc返回的内存块地址都是8的倍数(如果是64位系统,则为16的倍数)。如果你需要更大的粒度,请使用memalign或valloc。
参1:必须是2的幂,用来控制返回的地址是boundary倍数
参2:申请内存的大小
C库函数总结
于 2023-01-09 22:12:36 首次发布