linux之stat函数解析

[lingyun@localhost stat_1]$ vim stat.c
 + stat.c                                                                                                                    
/*********************************************************************************
 *      Copyright:  (C) 2013 fulinux<fulinux@sina.com> 
 *                  All rights reserved.
 *
 *       Filename:  stat.c
 *    Description:  This file 
 *                 
 *        Version:  1.0.0(08/02/2013~)
 *         Author:  fulinux <fulinux@sina.com>
 *      ChangeLog:  1, Release initial version on "08/02/2013 12:15:08 PM"
 *                 
 ********************************************************************************/


#include <sys/stat.h>
#include <unistd.h>
#include <stdio.h>


int main(void)
{
    struct stat buf;
    stat("/etc/hosts", &buf);
    printf("/etc/hosts file size = %d ", buf.st_size);
}
~                                                                                                                            
~                                                                                                                            
~                                                                                                                            
~                                                                                                                            
~                                                                                                                            
~                                                                                                                            
~                                                                                                                            
~                                                                                                                            
~                                                                                                                            
~                                                                                                                            
~                                                                                                                            
~                                                                                                                            
~                                                                                                                            
~                                                                                                                            
~                                                                                                                            
~                                                                                                                            
~                                                                                                                            
~                                                                                                                            
~                                                                                                                            
~                                                                                                                            
~                                                                                                                            
~                                                                                                                            
~                                                                                                                            
~                                                                                                                            
~                                                                                                                            
 ~/apue/stat/stat_1/stat.c[+]   CWD: /usr/local/src/lingyun/apue/stat/stat_1   Line: 22/23:55                                
"stat.c" [New] 23L, 714C written


[lingyun@localhost stat_1]$ ls
stat.c
[lingyun@localhost stat_1]$ gcc stat.c 
[lingyun@localhost stat_1]$ ./a.out 
/etc/hosts file size = 83
[lingyun@localhost stat_1]$ 

原文地址:https://www.cnblogs.com/jiangu66/p/3233699.html