//@@获取当前路径的完整路径
#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