Linux stat function

Source: Internet
Author: User

The implementation is as follows:

#include <stdio.h>#include<unistd.h>#include<fcntl.h>#include<sys/stat.h>#include<stdlib.h>#include<time.h>Char* FormatDate (Char*str, time_t val) {    //localtime () converts the information in the time_t structure referred to by the parameter TIMEP to the time and date representation used by the real worldStrftime (str, $,"%d.%m.%y%h:%m:%s", LocalTime (&val)); returnstr;}intMain () {structstat Fdstat; Const Char* filename ="Test.txt";//your filename    Chardate[ $]; if(Stat (filename, &fdstat) = =-1) {printf ("Open error\n"); Exit (0); } printf ("I-node number:[%d]\n", Fdstat.st_ino); printf ("st_nlink:[%d]\n", Fdstat.st_nlink); printf ("st_uid:[%d]\n", Fdstat.st_uid); printf ("st_gid:[%d]\n", Fdstat.st_gid); printf ("st_blocks:[%d]\n", fdstat.st_blocks); printf ("st_size:[%d]\n", fdstat.st_size); printf ("st_atime:[%d]\n", Fdstat.st_atime); printf ("st_mtime:[%d]\n", Fdstat.st_mtime); printf ("Access:%s\n", FormatDate (date, fdstat.st_atime)); printf ("Modify:%s\n", FormatDate (date, fdstat.st_mtime)); printf ("Change :%s\n", FormatDate (date, fdstat.st_ctime)); return 0;}

Linux stat function

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.