UNIX advanced environment programming (3) Files And Directories, unixdirectories

Source: Internet
Author: User
Tags lstat

UNIX advanced environment programming (3) Files And Directories, unixdirectories

In the previous two articles, we learned some basic operation functions of IO operations, including open, read, and write.

In this article, we will learn about other features of the file system and the attributes of a file. The functions involved include:

  • View all attributes of a file;
  • Change the file owner;
  • Change file permissions;
  • Operation folder.

We will also learn about the data structures and symbolic links related to file systems ).

 

1. stat, fstat, fstatat, and lsat Functions
# Include <sys/stat. h> int stat (const char * restrict pathname, struct stat * restrict buf); int fstat (int fd, struct stat * buf); int lstat (const char * restrict pathname, struct stat * restrict buf); int fstatat (int fd, const char * restrict pathname, struct stat * restrict buf, int flag); // All four return: 0 if OK, −1 on error

 

Function:

Stat returns the information of the specified file with pathname;

Fstat obtains information about the file opened on the file descriptor fd;

The functions of lstat are similar to those of the stat function, but there is only one difference. When the file specified by pathname is a symbolic link, the file information obtained by the lstat function is the information of the symbolic link, instead of the information of the file to which the symbolic link points, we will learn later

Related Article

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.