点击(此处)折叠或打开
- #include <unistd.h>
- //write系统调用
- size_t write(int fd, const void *buf, size_t nbytes);
- //read系统调用
- size_t read(int fd, void *buf, size_t nbytes);
点击(此处)折叠或打开
- #include
- #include
- #include
- 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);
- //flags值
- O_RDONLY 只读打开
- O_WRONLY 只写打开
- O_RDWR 读写方式打开
- O_APPEND 追加方式-可选
- O_TRUNC 文件长度清零,清除文件已有内容
- O_CREAT 文件不存在则创建
- O_EXCL 与O_CREAT组合,防止不同进程同时创建同一个文件
- //mode值 创建文件权限,需设置O_CREAT
- S_IRUSR
- S_IWUSR
- S_IXUSR
- S_IRGRP
- S_IWGRP
- S_IXGRP
- S_IROTH
- S_IWOTH
- S_IXOTH
#include
int close(int fd);//关闭文件
点击(此处)折叠或打开
- #include <unistd.h>
- int ioctl(int fields, int cmd, ...);
- //e.g 打开键盘LED灯
- ioctl(tty_fd,KDSETLED, LED_NUM|LED_CAP|LED_SCR);