This section mainly studies system call stat、lstat、fstat.

The format is as follows :

int fstat(int filedes, struct stat *buf);
int stat(const char *path, struct stat *buf);
int lstat(const char *path, struct stat *buf);

Smart people can see it at a glance fstat The first parameter of is different from the other two ,
Yes !fstat The difference between the other two system calls is ,fstat The system call accepts One “ File descriptor ”,
And the other two accept it directly “ File full path ”. File descriptors need to be used open It can only be obtained after system call ,
And the whole document can be written directly .
stat and lstat The difference between : When the file is a symbolic link ,lstat What is returned is the information of the symbolic link itself ;
and stat What is returned is the information of the file that the link points to .( It seems a little dizzy , Remember like this ,lstat Than stat One more. l,
So it has the ability to handle symbolic link files , So when you come across a symbolic link file ,lstat Of course not .
and stat System calls don't have this ability , It can only turn a blind eye to symbolic link files , Directly deal with the file that the link refers to )

Let's not worry about the usage of these , In my work, I often use lstat Judge whether the directory exists or not , Write down the usage here :

int CreateDir(const char *pPathName)
{
char szPath[256] = {0}, *pPath, *p;
int nLen;
assert(NULL != pPathName);
strncpy(szPath, pPathName, sizeof(szPath) - 2);
nLen = strlen(szPath);
// Make sure that the catalog is '/' ending
if('/' != szPath[nLen - 1])
{
szPath[nLen] = '/';
}
pPath = szPath + 1;
while((p = strchr(pPath, '/')) != NULL)
{
*p = '\0';
if(access(szPath, W_OK) != 0)
{
if(mkdir(szPath, 0755) == -1)
{
return -1;
}
}
*p = '/';
pPath = p + 1;
}
return 0;
}
 // Check whether the directory exists or not 
struct stat sfile;
if(lstat("/apps/hotel/paibo", &sfile) == -1 && m_oComm->CreateDir("/apps/hotel/paibo") != 0)
{
POST_INFO(" Error creating Directory [%s]", "/apps/hotel/paibo");
exit(-1);
}

06 File with the IO More articles about

  1. 【Go】 Use compressed file optimization io ( Two )

    Link to the original text : https://blog.thinkeridea.com/201907/go/compress_file_io_optimization2.html Last article < Use compressed file optimization io ...

  2. node Source details ( 7、 ... and ) —— Asynchronous files io、 Thread pool 【 The mutex 、 Condition variables, 、 The Conduit 、 Event object 】

    This work adopts the signature of knowledge sharing 4.0 International license agreement to license . The head of the reprint reservation statement is linked to the original text https://luzeshu.com/blog/nodesource7 This blog is synchronized in https://cnodejs.o ...

  3. Document and IO flow

    Abstract : This paper mainly introduces Java File processing and common IO Flow operation . File operations Concept File Data source ( Where to store data ) A kind of , Can represent a file , It can also represent a file directory . File Class can only create files and folders ...

  4. Atitit. Cross language &#160;&#160; Folder and file io Operation set &#160;&#160; The draft

    Atitit. Cross language    Folder and file io Operation set    The draft 1. Jdk The native is too hard to use ..1 2. PS: apache commons-io package ,FileUtils There are related methods ,IOUtils It's usually torture ...

  5. PythonCookBook note —— File with the IO

    File with the IO All programs deal with input and output , When it comes to text . Binary . File encoding and file name . Directory operation . Read and write text data You need to read and write all kinds of coded text data , Use rt Mode open() function . The read-write operation uses the system default ...

  6. raise productivity : Document and IO operation (ApacheCommonsIO- Share in Chinese )

    Copy . Move . Delete . Compare . monitor . File read and write And so on IO Operation is a common function in programming .        Fortunately, ,Apache Commons IO And other open source components have helped us achieve .        We don't have to repeat it ...

  7. linux System programming files and io( Four )

    Continue to learn about documents and io, It's mainly about file sharing and file sharing . Copy file descriptors , A bit abstract , It's mainly about conceptual understanding , But it's important , Let's break it down : File sharing : Take a look back. , stay linux In system call , Access to a file is through a file descriptor ...

  8. linux System programming files and io( Two )

    Continue to learn about documents and io, Don't talk much , Start to get to the point : Of documents read and write system call : explain : Function appears in size_t and ssize_t It's a data type customized for the system :     Here is an example of how to realize a simple copy of a file ...

  9. linux System programming files and io( One )

    After a long study ,C The basic knowledge of language is over , This is also an attempt to learn by blogging c Language , Looking back , Although the content may be relatively simple , But I feel that it's the most down-to-earth study in history , Because every experiment in it is from ...

Random recommendation

  1. hdu4405 Aeroplane chess

    Aeroplane chess Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)T ...

  2. C++ Create a multi-level directory at once

    #ifdef WIN32 #include <io.h> #include <direct.h> #else #include <unistd.h> #includ ...

  3. resin Basic operation

    1. What is? resin?     resin yes CAUCHO Products of the company , It's a very popular support servlets and jsp The engine of , Very fast .Resin It contains a support HTTP/1.1 Of WEB The server . Although it can ...

  4. 60 Drive from scratch in minutes Hive Practical learning notes

    The main content of this blog is : 1. Hive Essence analysis 2. Hive Installation practice 3.  Use Hive Operation of search engine data combat SparkSQL Formerly known as Shark,Shark Strongly dependent on Hive.Spark I didn't do it SQL ...

  5. Hdu 4010-Query on The Trees LCT, Dynamic trees

    Query on The Trees Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Othe ...

  6. Swift note 2

    1. A tuple type let cat =(age:4,weight:2,cocle:"black",beauty :true) if(cat.beauty){ printf(" I ...

  7. 【web】 And jquery Upload the plug-in Plupload Use

    First download plupload->http://www.plupload.com because Plupload There are many configurable parameters , So here's the most common , combination jquery-ui The display interface ! as follows : Plupload ...

  8. Android CTS Test

    What is? CTS test ? Before we understand this question , Let's search for it first “Google GMS authentication ”.GMS Its full name is GoogleMobile Service, Google Mobile Services . To put it bluntly GMS It's actually a collection of Google Apps . valley ...

  9. [ turn ]MyBatis Dynamic incoming table name 、 The solution to the field name parameter

    Always in use Mybatis This ORM frame , Is to use mybatis Some common functions in . In today's project development, it is necessary to restrict users to query fields in some tables and whether some fields are displayed , For example, some fields in a table cannot be queried by users . this ...

  10. Be similar to placehoder Icon display of effect

    Doing it app When developing, there is always a login , What kind of page , It's going to contain something like placeholder The icon of the effect , I was also with ios Mixed with Android to develop a app I wrote all the pages inside , At the beginning, it was landing , register ...