APUE(UNIX環境高級編程第二版)函數歸納(3-7章)

第3章 文件I/O

序號 函數名 原型 頭文件
1 open int open(const char *pathname, int flag, …/* mode_t mode */ ); #include <fcntl.h>
2 create int create(const char *pathname, mode_t mode); #include <fcntl.h>
3 close int close(int filedes); #include <unistd.h>
4 lseek off_t lseek(int flags, off_t offset, int whence); #include <unistd.h>
5 read ssize_t read(int filedes, void *buf, size_t nbytes); #include <unistd.h>
6 write ssize_t write(int filedes, const void *buf, size_t nbytes); #include <unistd.h>
7 pread ssize_t pread(int filedes, void *buf, size_t nbytes, off_t offset); #include <unistd.h>
8 pwrite ssize_t pwrite(int filedes, const void *buf, size_t nbytes, off_t offset); #include <unistd.h>
9 dup int dup(int filedes); #include <unistd.h>
10 dup2 int dup2(int filedes, int filedes2) #include <unistd.h>
11 fsync int fsync(int filedes); #include <unistd.h>
12 fdatasync int fdatasync(int filedes); #include <unistd.h>
13 sync int sync(void); #include <unistd.h>
14 fcntl int fcntl(int filedes, int cmd, … /* int arg */ ); #include <fcntl.h>
15 ioctl int ioctl(int filedes, int request, …); #include <sys/ioctl.h>

第4章 文件和目錄

序號 函數名 原型 頭文件
1 stat int stat(const char *restrict pathname, struct stat *restrict buf); #include <sys/stat.h>
2 fstat int fstat(int filedes, struct stat *buf); #include <sys/stat.h>
3 lstat int lstat(const char* restrict pathname, struct stat *restrict buf); #include <sys/stat.h>
4 S_ISREG S_ISREG() #include <sys/stat.h>
5 S_ISDIR S_ISDIR() #include <sys/stat.h>
6 S_ISCHR S_ISCHR() #include <sys/stat.h>
7 S_ISBLK S_ISBLK() #include <sys/stat.h>
8 S_ISFIFO S_ISFIFO() #include <sys/stat.h>
9 S_ISLNK S_ISLNK() #include <sys/stat.h>
10 S_ISSOCK S_ISSOCK() #include <sys/stat.h>
11 S_TYPEISMQ S_TYPEISMQ() #include <sys/stat.h>
12 S_TYPEISSEM S_TYPEISEM() #include <sys/stat.h>
13 S_TYPEISSHM S_TYPEISSHM() #include <sys/stat.h>
14 access int access(const char *pathname, int mode); #include <unistd.h>
15 umask mode_t umask(mode_t cmask); #include <sys/stat.h>
16 chmod int chmod(const char *pathname, mode_t mode); #include <sys/stat.h>
17 fchmod int fchmod(int filedes, mode_t mode); #include <sys/stat.h>
18 chown int chown(const char *pathname, uid_t owner, gid_t group); #include <unistd.h>
19 fchown int fchown(int filedes, uid_t owner, gid_t group); #include <unistd.h>
20 lchown int lchown(const char *pathname, uid_t owner, gid_t group); #include <unistd.h>
21 truncate int truncate(const char *pathname, off_t length); #include <unistd.h>
22 ftruncate int ftruncate(int filedes, off_t length); #include <unistd.h>
23 remove int remove(const char *pathname); #include <stdio.h>
24 rename int rename(const char *oldname, const char *newname); #include <stdio.h>
25 symlink int symlink(const char *actualpath, const char *sympath); #include <unistd.h>
26 readlink ssize_t readlink(const char* restrict pathname, char *restrict buf, size_t bufsize); #include <unistd.h>
27 utime int utime(const char *pathname, const struct utimbuf *times); #include <utime.h>
28 mkdir int mkdir(const *pathname, mode_t mode); #include <sys/stat.h>
29 rmdir int rmdir(const char *pathname); #include <unistd.h>
30 opendir DIR *opendir(const char *pathname); #include <dirent.h>
31 readdir struct dirent *readdir(DIR *dp); #include <dirent.h>
32 rewinddir void rewinddir(DIR * dp); #include <dirent.h>
33 closedir int closedir(DIR *dp); #include <dirent.h>
34 telldir long telldir(DIR *dp); #include <dirent.h>
35 seekdir void seekdir(DIR *dp, long loc); #include <dirent.h>
36 chdir int chdir(const char *pathname); #include <unistd.h>
37 fchdir int fchdir(int filedes); #include <unistd.h>
38 getcwd char *getcwd(char *buf, size_t size); #include <unistd.h>

第5章 標準I/O庫

序號 函數名 原型 頭文件
1 fwide int fwide(FILE *fp, int mode); #include <stdio.h>
#include <wcharh>
2 setbuf void setbuf(FILE *restrict fp, char *restrict buf); #include <stdio.h>
3 setvbuf int setvbuf(FILE *restrict fp, char *restrict buf, int mode, size_t size); #include <stdio.h>
4 fflush int fflush(FILE *fp); #include <stdio.h>
5 fopen FILE *fopen(const char *restrict pathname, const char *restrict type); #include <stdio.h>
6 freopen FILE *freopen(const char *restrict pathnam, const char *restrict type, FILE *restrict fp); #include <stdio.h>
7 fdopen FILE *fdopen(int filedes, const char *type); #include <stdio.h>
8 fclose int fclose(FILE *fp); #include <stdio.h>
9 getc int getc(FILE *fp); #include <stdio.h>
10 fgetc int fgetc(FILE *fp); #include <stdio.h>
11 getchar int getchar(void); #include <stdio.h>
12 ferror int ferror(FILE *fp); #include <stdio.h>
13 feof int feof(FILE *fp); #include <stdio.h>
14 clearerr void clearerr(FILE *fp); #include <stdio.h>
15 ungetc int ungetc(int c, FILE *fp); #include <stdio.h>
16 putc int putc(int c, FILE *fp); #include <stdio.h>
17 fputc int fputc(int c, FILE *fp); #include <stdio.h>
18 putchar int putchar(int c); #inlcude <stdio.h>
19 fgets char *fgets(char *restrict buf, int n, FILE *restrict fp); #include <stdio.h>
20 gets char *gets(char *buf); #include <stdio.h>
21 fputs int fputs(const char *restrict str, FILE *restrict fp); #include <stdio.h>
22 puts int puts(const char *str); #include <stdio.h>
23 fread size_t fread(void *restrict ptr, size_t size, size_t nobj,  FILE *restrict fp); #include <stdio.h>
24 fwrite size_t fwrite(const void *restrict ptr, size_t size, size_t nobj, FILE *restrict fp); #include <stdio.h>
25 ftell long ftell(FILE *fp); #include <stdio.h>
26 fseek int fseek(FILE *fp, long offset, int whence); #include <stdio.h>
27 rewind void rewind(FILE *fp); #include <stdio.h>
28 ftello off_t ftello(FILE *fp); #include <stdio.h>
29 fseeko int fseeko(FILE *fp, off_t offset, int whence); #include <stdio.h>
30 fgetpos int fgetpos(FILE *restrict fp, fpos_t *restrict pos); #include <stdio.h>
31 fsetpos int fsetpos(FILE *fp, const fpos_t *pos); #include <stdio.h>
32 printf int printf(const char* restrict format,...); #include <stdio.h>
33 fprintf int fprintf(FILE *restrict fp, const char *restrict format, ...); #include <stdio.h>
34 sprintf int sprintf(char *restrict buf, const char *restrict format, ...); #include <stdio.h>
35 snprintf int snprintf(char *restrict buf, size_t n, const char *restrict format, ...); #include <stdio.h>
36 vprintf int vprintf(const char* restrict format, va_list arg); #include <stdarg.h>
#include <stdio.h>
37 vfprintf int vfprintf(FILE *restrict fp, const char *restrict format, va_list arg); #include <stdarg.h>
#include <stdio.h>
38 vsprintf int vsprintf(char *restrict buf, const char *restrict format, va_list arg); #include <stdarg.h>
#include <stdio.h>
39 vsnprintf int vsnprintf(char *restrict buf, size_t n, const char *restrict format, va_list arg); #include <stdarg.h>
#include <stdio.h>
40 scanf int scanf(const char * restrict format, ...); #include <stdio.h>
41 fscanf int fscanf(FILE *restrict fp, const char *restrict format, ...); #include <stdio.h>
42 sscanf int sscanf(const char *restrict buf, const char *restrict format, ...); #include <stdio.h>
43 vscanf int vscanf(const char *restrict format, va_list arg); #include <stdarg.h>
#include <stdio.h>
44 vfscanf int vfscanf(FILE *restrict fp, const char *restrict format, va_list arg); #include <stdarg.h>
#include <stdio.h>
45 vsscanf int vsscanf(const char *restrict buf, const char *restrict format, va_list arg); #include <stdarg.h>
#include <stdio.h>
46 fileno int fileno(FILE *fp); #include <stdio.h>
47 tmpnam char *tmpnam(char *ptr); #include <stdio.h>
48 tmpfile FILE *tmpfile(void); #include <stdio.h>
49 tempnam char *tempnam(const char *directory, const char *prefix); #include <stdio.h>
50 mkstemp int mkstemp(char *template); #include <stdlib>

第6章 系統數據信息和信息

序號 函數名 原型 頭文件
1 getpwuid struct passwd *getpwuid(uid_t uid); #include <pwd.h>
2 getpwnam struct passwd *getpwnam(const char *name); #include <pwd.h>
3 getpwent struct passwd *getpwent(void); #include <pwd.h>
4 setpwent void setpwent(void); #include <pwd.h>
5 endpwent void endpwent(void); #include <pwd.h>
6 getspnam struct spwd *getspnam(const char *name); #include <shadow.h>
7 getspent struct spwd *getspent(void); #include <shadow.h>
8 setspent void setspent(void); #include <shadow.h>
9 endspent void endspent(void); #include <shadow.h>
10 getgrgid struct grounp *getgrgid(gid_t gid); #include <grp.h>
11 getgrnam struct grounp *getgrnam(const char *name); #include <grp.h>
12 getgrent struct group *getgrent(void); #include <grp.h>
13 setgrent void setgrent(void); #include <grp.h>
14 endgrent void endgrent(void); #include <grp.h>
15 getgroups int getgroups(int gidsetsize, gid_t grouplist[]); #include <unistd.h>
16 setgroups int setgroups(int ngroups, const gid_t grouplist[]); #include <grp.h>
17 initgroups int initgroups(const char *username, gid_t basegid); #include <grp.h>
18 uname int uname(struct utsname *name); #include <sys/utsname.h>
19 gethostname int gethostname(char *name, int namelen); #include <unistd.h>
20 time time_t time(time_t *calptr); #include <time.h>
21 gettimeofday int gettimeofday(struct timeval *restrict tp, void *restrict tzp); #include <sys/time.h>
22 gmtime struct tm *gmtime(const time_t *calptr); #include <time.h>
23 localtime struct tm *localtime(const time_t *calptr); #include <time.h>
24 mktime time_t mktime(struct tm *tmptr); #include <time.h>
25 asctime char *asctime(const struct tm *tmptr); #include <time.h>
26 ctime char *ctime(const time_t *calptr); #include <time.h>
27 strftime size_t strftime(char *restrict buf, size_t maxsize, const char *restrict format, const struct tm *restrict tmptr); #include <time.h>

第7章 進程環境

序號 函數名 原型 頭文件
1 exit void exit(int status); #include <stdlib.h>
2 _Exit void _Exit(int status); #include <stdlib.h>
3 _exit void _Exit(int status); #include <unistd.h>
4 atexit int atexit(void (*func)(void)); #include <stdlib.h>
5 malloc void *malloc(size_t size); #include <stdlib.h>
6 calloc void *calloc(size_t nobj, size_t size); #include <stdlib.h>
7 realloc void realloc(void *ptr, size_t newsize); #include <stdlib.h>
8 free void free(void *ptr); #include <stdlib.h>
9 getenv char *getenv(const char *name); #include <stdlib.h>
10 putenv int putenv(char *str); #include <stdlib.h>
11 setenv int setenv(const char *name, const char *value, int rewrite); #include <stdlib.h>
12 unsetenv int unsetenv(const char *name); #include <stdlib.h>
13 setjmp int setjmp(jmp_buf env); #include <setjmp.h>
14 longjmp void longjmp(jmp_buf env, int val); #include <setjmp.h>
15 getrlimit int getrlimit(int resource, struct rlimit *rlptr); #include <sys/resource.h>
16 setrlimit int setrlimit(int resource, const struct rlimit *rlptr); #include <sys/resource.h>

發佈了11 篇原創文章 · 獲贊 13 · 訪問量 17萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章