欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費電子書(shū)等14項超值服

開(kāi)通VIP
linux文件操作
一.文件類(lèi)型
1)普通文件(regular file).這是最常見(jiàn)的文件類(lèi)型,這種文件包含了某種形式的數據.
2)目錄 (directory)
3)字符特殊文件(character special file).系統中某些類(lèi)型的設備,例如聲卡,網(wǎng)卡,鍵盤(pán),鼠標。
4)塊特殊文件(block special file).用于磁盤(pán)設備,系統中的所有設備或者是字符特殊文件,或者是塊特殊文件。
5)FIFO:這種文件用于進(jìn)程間的通信,有時(shí)也將其稱(chēng)為命名管道。
6)套接口(socket).用于進(jìn)程間的網(wǎng)絡(luò )通信。套接口也可用于在一臺宿主機上的進(jìn)程之間的非網(wǎng)絡(luò )通信。
7)符號連接(symbolic link),這種文件指向另一個(gè)文件。
 
可以用下面的宏確定文件類(lèi)型:S_ISREG( ) 普通文件    S_ISDIR( ) 目錄文件  S_ISCHR( ) 字符特殊文件
S_ISBLK( ) 塊特殊文件  S_ISFIFO( ) 管道或FIFO  S_ISLNK( ) 符號連接    S_ISSOCK( ) 套接字
 
二.文件的屬性和操作
stat、fstat和lstat函數取得文件的屬性,三個(gè)函數的返回:若成功則為0,若出錯則為-1
#include <sys/types.h>
#include <sys/stat.h>
int stat(const char * pathname, struct stat *buf);
int fstat(int filedes,struct stat *buf);
int lstat(const char *pathname, struct stat *buf);
struct stat {
    dev_t      st_dev;      /* device */
    ino_t      st_ino;      /* inode */
    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 type (if inode device) */
    off_t      st_size;     /* total size, in bytes */
    blksize_t  st_blksize; /* blocksize for filesystem I/O */
    blkcnt_t   st_blocks;   /* number of blocks allocated */
    time_t     st_atime;    /* time of last access */
    time_t     st_mtime;    /* time of last modification */
    time_t     st_ctime;    /* time of last change */
};
access函數按進(jìn)程的實(shí)際用戶(hù)ID和實(shí)際組ID進(jìn)行存取許可權測試。
#include <unistd.h>
int access(const char *pathname, int mode);
返回:若成功則為0,若出錯則為-1

umask函數為進(jìn)程設置文件方式創(chuàng )建屏蔽字,并返回以前的值。
#include <sys/types.h>
#include <sys/stat.h>
mode_t umask(mode_t cmask);
返回:以前的文件方式創(chuàng )建屏蔽字
chmod和fchmod函數:改變存取許可權
#include <sys/types.h>
#include <sys/stat.h>
int chmod(const char *pathname, mode_t mode);
int fchmod(int filedes, mode_t mode);
兩個(gè)函數返回:若成功則為0,若出錯則為-1
chown、fchown和lchown函數:改變所有者和組所有者
#include <sys/types.h>
#include <unistd.h>
int chown(const char *pathname, uid_t owner, gid_t group);
int fchown(int filedes, uid_t owner, gid_t group);
int lchown(const char *pathname, uid_t owner, gid_t group);
三個(gè)函數返回:若成功則為0,若出錯則為-1
截短文件可以調用函數truncate和ftruncate
#include <sys/types.h>
#include <unistd.h>
int truncate(const char *pathname, off_t length);
int ftruncate(int filedes, off_t length);
兩個(gè)函數返回;若成功則為0,若出錯則為-1
rename:文件重命名
#include <stdio.h>
int rename(const char *oldname, const char *newname);
返回:若成功則為0,若出錯則為-1
utime:修改文件時(shí)間
#include <sys/types.h>
#include <utime.h>
int utime(const char *pathname, const struct utimbuf *times);
返回:若成功則為0,若出錯則為-1
struct utimbuf {
time_t actime; /*access time*/
time_t modtime; /*modification time*/
}
 
三、目錄操作
mkdir和rmdir:創(chuàng )建和刪除目錄
#include <sys/types.h>
#include <sys/stat.h>
int mkdir(const char *pathname, mode_t mode);
返回:若成功則為0,若出錯則為-1
函數rmdir刪除一個(gè)空目錄。
#include <unistd.h>
int rmdir(const char *pathname);
#include <sys/types.h>
#include <dirent.h>
DIR *opendir(const char *pathname);
返回:若成功則為指針,若出錯則為NULL
struct dirent *readdir(DIR *dir);
返回:若成功則為指針,若在目錄尾或出錯則為NULL
void rewinddir(DIR *dir);
int closedir(DIR *dir);
返回:若成功則為0,若出錯則為-1
定義在頭文件<dirent.h>中的dirent結構如下所示:
struct dirent
{
    __ino_t d_ino;
    __off_t d_off;
    unsigned short int d_reclen;
    unsigned char d_type;
    char d_name[256];
};
chdir、fchdir和getcwd函數:改變目錄和取得當前目錄
#include <unistd.h>
int chdir(const char *pathname);
int fchdir(int filedes);
char *getcwd(char *buf, size_t size);
兩個(gè)函數的返回:若成功則為0,若出錯則為-1
四、文件I/O接口概述
文件有5個(gè)操作:打開(kāi)、關(guān)閉、讀、寫(xiě)、定位。有兩套接口都可以用來(lái)完成這些操作,一類(lèi)是系統調用接口,對應的函數是open
、close、read、write、lseek,另一類(lèi)是標準I/O庫接口,對應的函數是fopen、fclose、fread、fwrite、fseek。
調用open函數可以打開(kāi)或創(chuàng )建一個(gè)文件。
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
int open(const char *pathname, int oflag,.../*, mode_t mode */);
返回:若成功為文件描述符,若出錯為-1
用creat函數創(chuàng )建一個(gè)新文件。
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
int creat(const char * pathname, mode_t mode) ;
返回:若成功為只寫(xiě)打開(kāi)的文件描述符,若出錯為-1
此函數等效于:
open(pathname, O_WRONLY|O_CREAT|O_TRUNC, mode);
close函數關(guān)閉一個(gè)打開(kāi)文件:
#include <unistd.h>
int close(int filedes);
返回:若成功為0,若出錯為-1
read函數從打開(kāi)文件中讀數據。
#include <unistd.h>
ssize_t read(int filedes, void *buff, size_t nbyt s);
返回:讀到的字節數,若已到文件尾為0,若出錯為-1
write函數向打開(kāi)文件寫(xiě)數據。
#include <unistd.h>
ssize_t write(int filedes, const void * buff, size_t nbytes);
返回:若成功為已寫(xiě)的字節數,若出錯為-1
用lseek顯式地定位一個(gè)打開(kāi)文件。
#include <sys/types.h>
#include <unistd.h>
off_t lseek(int filedes, off_t offset, int whence);
返回:若成功為新的文件位移,若出錯為-1? 
若whence是SEEK_SET,則將該文件的位移量設置為距文件開(kāi)始處offset個(gè)字節。
若whence是SEEK_CUR,則將該文件的位移量設置為其當前值加offset,offset可為正或負。
若whence是SEEK_END,則將該文件的位移量設置為文件長(cháng)度加offset,offset可為正或負。
本站僅提供存儲服務(wù),所有內容均由用戶(hù)發(fā)布,如發(fā)現有害或侵權內容,請點(diǎn)擊舉報。
打開(kāi)APP,閱讀全文并永久保存 查看更多類(lèi)似文章
猜你喜歡
類(lèi)似文章
linux I/O函數集 - 水無(wú)恨 - 博客園
linux解釋器原理
open文件操作
linux c創(chuàng )建文件夾,并在文件夾中創(chuàng )建以系統時(shí)間命名的文件
open
fcntl.h與unistd.h
更多類(lèi)似文章 >>
生活服務(wù)
分享 收藏 導長(cháng)圖 關(guān)注 下載文章
綁定賬號成功
后續可登錄賬號暢享VIP特權!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服

欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久