Linux 文件系统函数
 作者:贾献华
- 2022 年 7 月 21 日
- 本文字数:616 字 - 阅读完需:约 2 分钟 
Linux 内核模块简介
Linux 提供了这样的机制,这种机制被称为模块(Module)。模块具有这样的特点。
- 模块本身不被编译入内核映像,从而控制了内核的大小。 
- 模块一旦被加载,它就和内核中的其他部分完全一样。 
Linux 文件系统与设备文件
文件打开标志
 
 文件访问权限
 
  1  #include <sys/types.h> 2  #include <sys/stat.h> 3  #include <fcntl.h> 4  #include <stdio.h> 5  #define LENGTH 100 6  int main(void) 7  { 8    int fd, len; 9    char str[LENGTH];1011    fd = open("hello.txt", O_CREAT | O_RDWR, S_IRUSR | S_IWUSR); /*12  创建并打开文件 */13    if (fd) {14         write(fd, "Hello World", strlen("Hello World")); /*15       写入字符串 */16         close(fd);17    }1819    fd = open("hello.txt", O_RDWR);20    len = read(fd, str, LENGTH); /* 读取文件内容 */21    str[len] = '\0';22    printf("%s\n", str);23    close(fd);24 }复制代码
 C 库文件操作
 
  1 #include <stdio.h> 2 #define LENGTH 100 3 int main(void) 4 { 5   fiLE *fd; 6   char str[LENGTH]; 7 8   fd = fopen("hello.txt", "w+");/* 创建并打开文件 */ 9   if (fd) {10       fputs("Hello World", fd); /* 写入字符串 */11       fclose(fd);12   }1314   fd = fopen("hello.txt", "r");15   fgets(str, LENGTH, fd);       /* 读取文件内容 */16   printf("%s\n", str);17   fclose(fd);18 }复制代码
 划线
评论
复制
发布于: 刚刚阅读数: 3


贾献华
关注
及时当勉励 岁月不待人 2018.06.04 加入
https://2022.iosdevlog.com










 
    
评论