Dirnet. h

Source: Internet
Author: User

 

I have never understood how to operate directories in Linux. I recently studied dirent. h. The following are the results of the study:

There are two dirent. h:

 

/Usr/include/dirent. h

Defines the directory stream structure Dir and some operation directory node interfaces, including opening, reading, closing, and the operation of the pointer position in the stream; very similar to file operations, where DIR is not actually defined, the estimation is complicated, but in the process of use, he just transmits and does not need to modify him. It is a bit similar to the file handle. Common interfaces include:

Extern dir * opendir (_ const char * _ name) _ nonnull (1 ));

 

Extern int scandir (_ const char * _ restrict _ DIR ,...)

Extern int closedir (dir * _ dirp) _ nonnull (1 ));

Extern struct dirent * readdir (dir * _ dirp) _ nonnull (1 ));

 

/Usr/include/bits/dirent. h

Defines the data structure of the next file node in Dir, including attributes such as name and file type. After obtaining this structure through readdir, you can use the stat function to further parse these attributes, the following are various file types:

 

Enum

{

Dt_unknown = 0,

# Define dt_unknown

Dt_fifo = 1,

# Define dt_fifo

Dt_chr = 2,

# Define dt_chr

Dt_dir = 4,

# Define dt_dir

Dt_blk = 6,

# Define dt_blk

Dt_reg = 8,

# Define dt_reg

Dt_lnk = 10,

# Define dt_lnk

Dt_sock = 12,

# Define dt_sock

Dt_wht = 14

# Define dt_wht

};

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.