嵌入式学习day22 Linux

文件IO:

  1. lseek

off_t lseek(int fd, off_t offset, int whence);

功能:

重新设定文件描述符的偏移量

参数:

fd:文件描述符

offset:偏移量

whence:

SEEK_SET 文件开头

SEEK_CUR 文件当前位置

SEEK_END 文件末尾

返回值:

成功返回当前偏移量

失败返回-1

目录IO:

1.mkdir

int mkdir(const char *pathname, mode_t mode);

功能:

创建目录文件

参数:

pathname:文件路径

mode:文件的权限

返回值:

成功返回0

失败返回-1

rwx rwx rwx

111 111 111

0777

r: 目录中是否能够查看文件

w: 目录中是否能够新建文件

x: 目录是否能够进入

2.rmdir

int rmdir(const char *pathname);

功能:

删除空目录文件

返回值:

成功返回0

失败返回-1

3.opendir

DIR *opendir(const char *name);

功能:

打开目录获得目录流指针

参数:

name:目录文件路径

返回值:

成功返回目录流指针

失败返回NULL

4.closedir

int closedir(DIR *dirp);

功能:

关闭目录流指针

5.readdir

struct dirent *readdir(DIR *dirp);

功能:

从目录流中读取下一个目录项的结构体信息

参数:

dirp:目录流指针

返回值:

成功返回包含目录项信息的空间首地址

失败返回NULL

读到文件末尾返回NULL

struct dirent {

ino_t d_ino; /* Inode number */

off_t d_off; /* Not an offset; see below */

unsigned short d_reclen; /* Length of this record */

unsigned char d_type; /* Type of file; not supported

by all filesystem types */

char d_name[256]; /* Null-terminated filename */

};

6.chdir

int chdir(const char *path);

功能:

切换当前代码的工作路径

7.getcwd

char *getcwd(char *buf, size_t size);

功能:

获得当前目录的绝对路径

8.access

int access(const char *pathname, int mode);

功能:

检测调用函数的程序对文件是否拥有指定权限

参数:

pathname:文件路径

mode:

R_OK 检测是否拥有读权限

W_OK 检测是否拥有写权限

X_OK 检测是否拥有执行权限

F_OK 检测文件是否存在

返回值:

有该权限返回0

出错返回-1

相关推荐
悠哉悠哉愿意21 小时前
【单片机学习笔记】串口、超声波、NE555的同时使用
笔记·单片机·学习
别催小唐敲代码1 天前
嵌入式学习路线
学习
毛小茛1 天前
计算机系统概论——校验码
学习
babe小鑫1 天前
大专经济信息管理专业学习数据分析的必要性
学习·数据挖掘·数据分析
winfreedoms1 天前
ROS2知识大白话
笔记·学习·ros2
在这habit之下1 天前
Linux Virtual Server(LVS)学习总结
linux·学习·lvs
我想我不够好。1 天前
2026.2.25监控学习
学习
im_AMBER1 天前
Leetcode 127 删除有序数组中的重复项 | 删除有序数组中的重复项 II
数据结构·学习·算法·leetcode
CodeJourney_J1 天前
从“Hello World“ 开始 C++
c语言·c++·学习
匠心网络科技1 天前
JavaScript进阶-ES6 带来的高效编程新体验
开发语言·前端·javascript·学习·面试