日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

apue 第4章 文件和目录

發布時間:2025/3/20 编程问答 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 apue 第4章 文件和目录 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

獲取文件屬性

#include <sys/types.h> #include <sys/stat.h> #include <unistd.h>int stat(const char *pathname, struct stat *buf); int fstat(int fd, struct stat *buf); int lstat(const char *pathname, struct stat *buf);#include <fcntl.h> #include <sys/stat.h>int fstatat(int dirfd, const char *pathname, struct stat *buf, int flags);
返回值:成功0,出錯-1

stat結構:

struct stat {dev_t st_dev; /* ID of device containing file */ino_t st_ino; /* inode number */mode_t st_mode; /* protection */nlink_t st_nlink; /* number of hard links */uid_t st_uid; /* user ID of owner */gid_t st_gid; /* group ID of owner */dev_t st_rdev; /* device ID (if special file) */off_t st_size; /* total size, in bytes */blksize_t st_blksize; /* blocksize for filesystem I/O */blkcnt_t st_blocks; /* number of 512B blocks allocated */  /* Since Linux 2.6, the kernel supports nanosecondprecision for the following timestamp fields.For the details before Linux 2.6, see NOTES. */
  struct timespec st_atim; /* time of last access */   struct timespec st_mtim; /* time of last modification */   struct timespec st_ctim; /* time of last status change */  #define st_atime st_atim.tv_sec /* Backward compatibility */   #define st_mtime st_mtim.tv_sec   #define st_ctime st_ctim.tv_sec };

?

按實際用戶ID和實際組ID進行訪問權限測試

#include <unistd.h>int access(const char *pathname, int mode);#include <fcntl.h> #include <unistd.h>int faccessat(int dirfd, const char *pathname, int mode, int flags);
返回值:成功0,出錯-1

?

為進程設置文件模式創建屏蔽字

#include <sys/types.h> #include <sys/stat.h>mode_t umask(mode_t mask); 返回值:之前文件模式創建屏蔽字

?

更改現有文件的訪問權限

#include <sys/stat.h>int chmod(const char *pathname, mode_t mode); int fchmod(int fd, mode_t mode);#include <fcntl.h> #inlcude <sys/stat.h>int fchmodat(int dirfd, const char *pathname, mode_t mode, int flags);
返回值:成功0,出錯-1

?

用于改變文件的用戶ID和組ID。如果兩個參數owner或group中的任意一個是-1,則對應ID不變

#include <unistd.h>int chown(const char *pathname, uid_t owner, gid_t group); int fchown(int fd, uid_t owner, gid_t group); int lchown(const char *pathname, uid_t owner, gid_t group);#include <fcntl.h> /* Definition of AT_* constants */ #include <unistd.h>int fchownat(int dirfd, const char *pathname, uid_t owner, gid_t group, int flags);
返回值:成功0,出錯-1

?

截斷文件

#include <unistd.h> #include <sys/types.h>int truncate(const char *path, off_t length); int ftruncate(int fd, off_t length); 返回值:成功0,出錯-1

?

?

創建一個指向現有文件的鏈接

#include <unistd.h>int link(const char *oldpath, const char *newpath);#include <fcntl.h> /* Definition of AT_* constants */ #include <unistd.h>int linkat(int olddirfd, const char *oldpath, int newdirfd, const char *newpath, int flags); 返回值:成功0,出錯-1

?

刪除一個現有目錄項

#include <unistd.h>int unlink(const char *pathname);#include <fcntl.h> #include <unistd.h>int unlinkat(int dirfd, const char *pathname, int flags);
返回值:成功0,出錯-1

?

解除對一個文件或目錄的鏈接

#include <stdio.h>int remove(const char *pathname); 返回值:成功0,出錯-1

?

對文件或目錄進行重命名

#include <stdio.h>int rename(const char *oldpath, const char *newpath);#include <fcntl.h> #include <stdio.h>int renameat(int olddirfd, const char *oldpath, int newdirfd, const char *newpath); int renameat2(int olddirfd, const char *oldpath, int newdirfd, const char *newpath, unsigned int flags); 返回值:成功0,出錯-1

?

創建一個符號鏈接

#include <unistd.h>int symlink(const char *target, const char *linkpath);#include <fcntl.h> #include <unistd.h>int symlinkat(const char *target, int newdirfd, const char *linkpath); 返回值:成功0,出錯-1

?

因為open函數跟隨符號鏈接,所以需要一種方法打開鏈接本身,并讀該鏈接中的名字。

#include <unistd.h>ssize_t readlink(const char *pathname, char *buf, size_t bufsiz);#include <fcntl.h> /* Definition of AT_* constants */ #include <unistd.h>ssize_t readlinkat(int dirfd, const char *pathname, char *buf, size_t bufsiz); 返回值:成功讀取字節數,出錯-1

?

一個文件的訪問和修改時間可以用以下幾個函數更改。futimens和utimensat函數可以指定納秒級精度的時間戳。

用到數據結構是與stat函數族相同的timespec結構。

#include <fcntl.h> /* Definition of AT_* constants */ #include <sys/stat.h>int utimensat(int dirfd, const char *pathname, const struct timespec times[2], int flags);int futimens(int fd, const struct timespec times[2]); 返回值:成功0,出錯-1

?

創建目錄,刪除目錄

#include <sys/stat.h> #include <sys/types.h>int mkdir(const char *pathname, mode_t mode);#include <fcntl.h> /* Definition of AT_* constants */ #include <sys/stat.h>int mkdirat(int dirfd, const char *pathname, mode_t mode);
返回值:成功0,出錯-1

?

刪除一個空目錄,空目錄只包含.和..

#include <unistd.h>int rmdir(const char *pathname); 返回值:成功0,出錯-1

?

讀目錄

#include <sys/types.h> #include <dirent.h>DIR *opendir(const char *name); DIR *fdopendir(int fd);
返回值:成功指針,出錯NULL
struct dirent *readdir(DIR *dirp);
返回值:成功指針,若在目錄或出錯,返回NULL
void rewinddir(DIR *dirp); int closedir(DIR *dirp);
返回值:成功0,出錯-1
long telldir(DIR *dirp);
返回值:dp關聯的目錄中的當前位置
void seekdir(DIR *dirp, long loc);

dirent結構

struct dirent {ino_t d_ino; /* inode number */off_t d_off; /* not an offset; see NOTES */unsigned short d_reclen; /* length of this record */unsigned char d_type; /* type of file; not supportedby all filesystem types */char d_name[256]; /* filename */ };

?

?

?

更改當前目錄

#include <unistd.h>int chdir(const char *path); int fchdri(int fd);
返回值:成功0,出錯-1

?

得到當前工作目錄完整絕對路徑名

#include <unistd.h>char *getcwd(char *buf, size_t size); 返回值:成功返回buf,出錯NULL

?

轉載于:https://www.cnblogs.com/ch122633/p/8157707.html

總結

以上是生活随笔為你收集整理的apue 第4章 文件和目录的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 久久国产精品电影 | 免费国产a级片 | 在线观看一区二区三区四区 | 国产成年人视频 | 国产网站免费观看 | 免费午夜av | 大地资源在线观看免费高清版粤语 | 久久视奸 | 成人久久久精品国产乱码一区二区 | 日本 片 成人 在线 九色麻豆 | 麻豆一级片| 成人无高清96免费 | 国产成人免费在线 | 国产做爰免费观看视频 | 中文字幕有码在线观看 | 欧美日韩免费观看一区=区三区 | 成人免费毛片色戒 | 一区二区三区在线观 | 丁香婷婷综合激情 | 国产一级片免费观看 | 国模人体私拍xvideos | 黄色字幕网 | 日本a级黄 | 亚洲福利一区二区三区 | 一区二区三区蜜桃 | 国产精品白嫩白嫩大学美女 | 久久精品久久久 | 国产精品成人电影在线观看 | 国产精品99久久免费黑人人妻 | 手机av网| 久久久久久久福利 | 少妇闺蜜换浪荡h肉辣文 | 特黄特色特刺激免费播放 | jizz亚洲女人高潮大叫 | 久久综合九色综合欧美狠狠 | 少妇特黄一区二区三区 | 欧美老肥妇做.爰bbww视频 | 国产a免费观看 | 第四色影音先锋 | 91在线免费看片 | 亚洲日本中文字幕 | 麻豆久久久午夜一区二区 | 自拍偷拍亚洲图片 | 麻豆精品久久久 | 日本中文字幕久久 | 国产黑丝一区二区 | 河北彩花av在线播放 | 欧美黄色免费网站 | 国产69精品久久久久久 | 插插插综合 | 成人黄色在线网站 | 欧美亚洲综合在线 | 亚洲精品在线观看免费 | 国产嫩草在线观看 | 亚洲综合图| 国产又黄又粗又爽 | 在线视频成人 | 涩涩免费网站 | 色香色香欲天天天影视综合网 | 天天躁日日躁狠狠躁喷水 | 色一五月| 性av在线| 九热在线视频 | 性中文字幕 | 女18毛片| 国产99精品 | 一级黄色影院 | 欧美中文一区 | 国产女主播在线播放 | 亚洲AV无码精品久久一区二区 | 黑人与亚洲人色ⅹvideos | 日本啪啪动态图 | 视频一区二区三区精品 | 黄色免费在线看 | 国产夜夜操 | 日韩sese| 成人在线观看www | 肮脏的交易在线观看 | 野花视频在线免费观看 | 给我免费观看片在线电影的 | 中文字幕在线视频观看 | 91热久久| 欧美性猛交久久久久 | 免费无码av片在线观看 | 桃色在线视频 | 国产sss| 国产精品传媒 | 深夜视频在线免费观看 | 欧美一级二级三级 | 亚洲最大av网站 | 91精品美女 | 免费成人黄色片 | 精品一区国产 | 狼人综合伊人 | 无码粉嫩虎白一线天在线观看 | 午夜视频在线免费 | 美女网站视频在线观看 | 久久久久这里只有精品 | 国产网站黄 |