Linux开发 – 02 – 文件和目录

Linux大全评论526 views阅读模式

本文列出一些与文件相关的设备和函数,以备查用。至于具体意义和用法自己查man

0. 查man page方法

系统调用

$man 2 read

  
   
    1 NAME
2 read - read from a file descriptor
3
4
5
6 SYNOPSIS
7 #include <unistd.h>
8
9 ssize_t read(int fd, void *buf, size_t count);
10
11 DESCRIPTION
12 read() attempts to read up to count bytes from file descriptor fd into
13 the buffer starting at buf.
14
15 If count is zero, read() returns zero and has no other results. If
16 count is greater than SSIZE_MAX, the result is unspecified. 

标准C函数

$man 3 printf

... 

1. 设备

/dev/console

/dev/tty

/dev/null 

2. 文件系统调用函数

open, read, write, close, ioctl,

ioctl 的功能与具体硬件相关, 所以针对不同的硬件功能可能完全不同。 

lseek

fstat, stat, lstat

dup, dup2 

检测程序运行时间

$TIMEFORMAT=”” time my_system

1.07user 3.50system 0:04.77elapsed 95%CPU 

3. 标准IO函数

fopen, fclose
fread, fwrite
fflush
fseek
fgetc, getc, getchar
fputc, putc, putchar
fgets, gets
printf, fprintf, and sprintf
scanf, fscanf, and sscanf 

fgetpos
fsetpos
ftell
rewind
freopen
setvbuf
remove 

4. 出错处理

#include <errno.h>
extern int errno; 

#include <stdio.h>
ferror(FILE *stream);
feof(FILE *stream);
clearerr(FILE *stream);

strerror(int errno);

perror("prefix string"); 

5. 文件描述符和FILE流互转函数

int fileno(FILE *stream);
FILE *fdopen(int fildes, const char *mode); 

6. 文件和目录维护

chmod

chown

unlink, link, symlink 

mkdir, rmdir

chdir, getcwd

opendir, closedir
readdir
telldir
seekdir 

7. /proc 文件系统

procfs 文件系统, provide a higher-level access to driver and kernel information. 

8. 更高级的函数

fcntl

mmap 

9. 结束语

应该很全了,  如有遗漏, 欢迎补充

企鹅博客
  • 本文由 发表于 2020年7月5日 09:02:54
  • 转载请务必保留本文链接:https://www.qieseo.com/147981.html

发表评论