file_access.c
来自「Solaris下的文件系统编程,sun公司培训用例.」· C语言 代码 · 共 27 行
C
27 行
#include <stdio.h>#include <stdlib.h>#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>#include <unistd.h>int main(void){ int file = 0, exit_wait; char buffer[10] = {0}; file = open("test.txt", O_RDONLY); printf("The file descriptor returned is %d\n", file); if (file == -1) { printf("The file opening failed.\n"); exit(0); } read(file, (void*)buffer, 9); buffer[9] = '\0'; printf("The data read from the file is %s\n", buffer); scanf("%d", &exit_wait);/*Make the process blocked here so that the kernel data structure can be inspected.*/ close (file); return 0;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?