LinuxC编程实战之文件操作
来源:互联网 发布:golang ide 编辑:程序博客网 时间:2024/05/16 05:13
1.open函数
#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>int open(const char *pathname, int flags);int open(const char *pathname, int flags, mode_t mode);调用成功返回一个文件描述符,失败返回-1.
2.creat函数
#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>int open(const char *pathname, mode_t mode);调用成功返回一个文件描述符,失败返回-1.Note:creat只能以只写的方式打开创建的文件,creat无法创建设备文件,设备文件的创建要使用mknod函数.
3.close函数
#include <unistd.h>int close(int fd);调用成功返回0,失败返回-1.Note:close函数调用成功时并不保证数据能全部写回硬盘.
4.lseek函数
#include <sys/types.h>#include <unistd.h>off_t lseek(int fildes, off_t offset, int whence);调用成功返回新的偏移量,失败返回-1.Note:打开文件时通常读写位置是指向文件开头,若是追加方式打开文件,读写位置会指向文件尾.
5.stat函数
#include <sys/types.h>#include <sys/stat.h>#include <unistd.h>int stat(const char *file_name, struct stat *buf);int fstat(int filedes, struct stat *buf);int lstat(const char *file_name,struct stat *buf);调用成功返回0,失败返回-1.
6.utime函数
#include <sys/types.h>#include <utime.h>int utime(const char *filename, struct utimebuf *buf);#include <sys/time.h>int utimes(char *filename,struct timeval *tvp);调用成功返回0,失败返回-1.Note:utime系统调用会把由第一个参数filename指定的文件的存取时间改为第二个参数buf的actime域,把修改时间改为第二个参数buf的modtime域,如果buf是一个空指针,则存取时间和修改时间都改为当前时间.
7.getcwd函数
#include <unistd.h>char *getcwd(char *buf, size_t size);char *get_current_dir_name(void);char *getwd(char *buf);成功则将结果复制到参数buf所指的内存空间,或是返回自动配置的字符串指针,失败返回NULL.Note:getcwd会将当前的工作目录绝对路径复制到参数buf所指的内存空间,buf所指的内存空间要足够大.
8.opendir函数
#include <sys/types.h>#include <dirent.h>DIR *opendir(const char *name);成功返回DIR*型态的目录流,失败则返回NULL.
9.readdir函数
#include <sys/types.h>#include <dirent.h>struct dirent *readdir(DIR *dir);struct dirent{ long d_ino; //目录i节点编号 off_t d_off; //目录开头至此目录进入点的位移 unsigned short d_reclen; //文件名的长度 char d_name [NAME_MAX+1]; //以NULL结尾的文件名};函数执行成功返回该目录下一个文件信息,第一次调用返回第一个文件信息,第二次调用返回第二个,以此类推;函数调用如有错误发生或读取到目录文件尾,则返回NULL.
10.closedir函数
#include <sys/types.h>#include <dirent.h>int closedir(DIR *dir);closedir用来关闭参数dir指向的目录,执行成功返回0,当有错误发生时返回-1.
1 0
- LinuxC编程实战之文件操作
- LinuxC编程实战学习——第六章文件操作
- linuxC编程之文件操作与进程初步
- LinuxC编程实战
- linuxC编程实战-第六章
- LinuxC编程实战Myshell总结
- Linuxc编程之信号
- LinuxC/C++编程(1)—文件操作
- linuxC系统编程——文件的I/O操作
- Linuxc 文件操作讲座知识
- 学习linuxC编程实战-----linux进程控制
- 《linuxC编程实战》面试题摘选
- LinuxC编程实战第七章学习总结
- linuxc不带缓存的文件操作
- LinuxC学习之字符和字符串操作
- linuxC编程
- LinuxC编程
- LinuxC编程之IO-通过lseek对文件进行读写
- Matlab画图技巧之消除空白
- java对字符串进行去重并排序
- 杭电-2089 不要62 (打表)
- cocos2dx v3.x之HttpRequest改动
- 关于Calling View methods on another thread than the UI thread的错误
- LinuxC编程实战之文件操作
- 自己实现 SharedPtr(4)—— 一个代码洁癖的救赎
- C语言getpriority()函数:取得程序进程执行优先权
- 拼图游戏学习
- jsp中Post和Get请求获取表单里的中文
- PHP 检测是否全为数字或者字母方法ctype_alnum(String text)
- linux管理和进程(4)
- 2016 Multi-University Training Contest 1-1001---HDU 5723 Abandoned country(DFS+最小生成树)
- link