UNIX programming int Fstat (int fildes,struct stat *buf);

Source: Internet
Author: User
Tags define function error code file size

/*

* Fstat (Get file status from file descriptor)

* Correlation function Stat,lstat,chmod,chown,readlink,utime

* Table header File

* #include <sys/stat.h>

* #include <unistd.h>

* Define function

* int fstat (int fildes,struct stat *buf);

The * Function Description Fstat () is used to copy the file state of the parameter fildes to the structure referred to in the parameter buf (struct stat).

* Fstat () is exactly the same as stat (), except that the passed parameter is an open file descriptor.

* The return value performs successfully returns 0, the failure returns 1, and the error code is stored in errno.

*/

/* Example * *

#include <sys/stat.h>     
#include <unistd.h>     
#include <stdio.h>     
#include <sys/ types.h>      
#include <sys/stat.h>     
#include <fcntl.h>     
        
int main (int argc, char *argv)     
{     
    struct stat buf;     
    int FD;     
    FD = open ("/etc/passwd", o_rdonly);     
    Fstat (FD, &buf);     
    printf ("/etc/passwd File Size:%d\n", buf.st_size);     
    return 0;     
}

/* Execute/etc/passwd File size = 705 * *

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.