Linux 文件操作函数

//@@获取当前路径的完整路径
#include <unistd.h>
char *getcwd(char *buf, size_t size);
char *getwd(char *buf);
char *get_current_dir_name(void);


//打开文件
 int open(const char *pathname, int flags);
 int open(const char *pathname, int flags, mode_t mode)
 int creat(const char *pathname, mode_t mode);
引用:
#includ e <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
返回值:
打开成功返回文件描述符,错误返回-1

//关闭文件
#include <unistd.h>
int close(int fd);
close() 关闭成功返回0,否则返回-1

//创建文件
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
int creat(const char *pathname, mode_t mode);


//写文件
#include <unistd.h>
ssize_t write(int fd, const void *buf, size_t count);
write向文件描述符 fd 所引用的文件中写入从 buf 开始的缓冲区中 count 字节的数据
 
成功时返回所写入的字节数(若为零则表示没有写入数据).  错误时返回-1,并置errno为相应值.
若count为零,对于普通文件无任何影响,但对特殊文件将产生不可预料的后果

//文件偏移位置定位函数
 #include <sys/types.h>
 #include <unistd.h>
off_t lseek(int fd, off_t offset, int whence);


//文件状态操作函数
stat

//对文件的时间信息操作
utime

//测试文件 访问权限 是否存在'
access
成功时返回0  否则返回-1

//
chmod
fchmod 使用文件描述符对一个已经打开的文件操作

//改名
rename

每打开一个文件的对应的操作符不是唯一的,同一个文件可能有多个描述符
dup  dup2 用来复制文件描述符

通常使用这两个系统调用,来重定向一个已打开的文件描述符
fcnl 函数提供进一步管理低级文件描述符的各种手段,可以对已打开的文件操作符执行各种控制操作


Linux中 每个进程都有一个对应的工作目录,工作路径 

chdir
fchdir
//来修改当前的工作目录,成功返回0,否则返回-1

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值