1. 进程虚拟地址空间

2. stat函数

  • 获取文件信息
       #include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h> int stat(const char *pathname, struct stat *statbuf);
int fstat(int fd, struct stat *statbuf);
int lstat(const char *pathname, struct stat *statbuf); #include <fcntl.h> /* Definition of AT_* constants */
#include <sys/stat.h> int fstatat(int dirfd, const char *pathname, struct stat *statbuf,
int flags);
           struct stat {
dev_t st_dev; /* ID of device containing file */
ino_t st_ino; /* Inode number */
mode_t st_mode; /* File type and mode */
nlink_t st_nlink; /* Number of hard links */
uid_t st_uid; /* User ID of owner */
gid_t st_gid; /* Group ID of owner */
dev_t st_rdev; /* Device ID (if special file) */
off_t st_size; /* Total size, in bytes */
blksize_t st_blksize; /* Block size for filesystem I/O */
blkcnt_t st_blocks; /* Number of 512B blocks allocated */ /* Since Linux 2.6, the kernel supports nanosecond
precision for the following timestamp fields.
For the details before Linux 2.6, see NOTES. */ struct timespec st_atim; /* Time of last access */
struct timespec st_mtim; /* Time of last modification */
struct timespec st_ctim; /* Time of last status change */ #define st_atime st_atim.tv_sec /* Backward compatibility */
#define st_mtime st_mtim.tv_sec
#define st_ctime st_ctim.tv_sec
};

stat函数参数

  • pathname 文件名
  • struct stat *buf 传出参数,定义 struct stat sb; &sb

返回值

  • 成功返回0,失败返回-1,设置errno
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <stdio.h> int main(int argc, char *argv[])
{
if (argc != ) {
printf("./a.out filename\n");
return -;
}
struct stat sb;
stat(argv[], &sb); return ; }

stat/lstat函数使用的更多相关文章

  1. C语言:stat,fstat和lstat函数

    这三个函数的功能是一致的,都用于获取文件相关信息,但应用于不同的文件对象.对于函数中给出pathname参数,stat函数返回与此命名文件有关的信息结构,fstat函数获取已在描述符fields上打开 ...

  2. 文件和目录之stat、fstat和lstat函数

    #include <sys/stat.h> int stat( const char *restrict pathname, struct stat *restrict buf ); in ...

  3. stat,fstate,lstat函数

    #include <sys/stat.h> int stat (const char *restrict pathname,struct stat* restrict buf) int f ...

  4. 第九篇:使用 lstat 函数获取文件信息

    前言 在之前的文章中,描述过如何用 fcntl 函数改变文件的状态标记.但,文件还有很多信息,如文件类型,权限设置,设备编号,访问时间等等.如果要获取这些信息,则使用函数 lstat 可以轻松达到这个 ...

  5. 使用 lstat 函数获取文件信息

    前言 在之前的文章中,描述过如何用 fcntl 函数改变文件的状态标记.但,文件还有很多信息,如文件类型,权限设置,设备编号,访问时间等等.如果要获取这些信息,则使用函数 lstat 可以轻松达到这个 ...

  6. lstat函数的使用【学习笔记】

    通过lstat函数获取文件的类型的代码如下. #include "apue.h" int main(int argc,char *argv[]) { int i; struct s ...

  7. PHP lstat() 函数

    定义和用法 lstat() 函数返回关于文件或符号连接的信息. 该函数将返回一个包含下列元素的数组: [0] 或 [dev] - 设备编号 [1] 或 [ino] - inode 编号 [2] 或 [ ...

  8. PHP常用函数大全

    usleep() 函数延迟代码执行若干微秒.unpack() 函数从二进制字符串对数据进行解包.uniqid() 函数基于以微秒计的当前时间,生成一个唯一的 ID.time_sleep_until() ...

  9. PHP常用函数备用

    刚学习php的时候,我也为记忆php函数苦恼不已.认为干嘛记忆这么枯燥无味的东西呢?用的时候查一下手册不就行了吗?但是当时因为身在辅导机构,还是记忆了一大堆自己并不感兴趣的函数. 由此就想起来,小的时 ...

随机推荐

  1. composer 重装常见错误

    install composer error: ------------------------------------ The PHP exe file you specified did not ...

  2. BZOJ 2069: [POI2004]ZAW(Dijkstra + 二进制拆分)

    题意 给定一个有 \(N\) 个点 \(M\) 条边的无向图, 每条无向边 最多只能经过一次 . 对于边 \((u, v)\) , 从 \(u\) 到 \(v\) 的代价为 \(a\) , 从 \(v ...

  3. Hdoj 2108.Shape of HDU 题解

    Problem Description 话说上回讲到海东集团推选老总的事情,最终的结果是XHD以微弱优势当选,从此以后,"徐队"的称呼逐渐被"徐总"所取代,海东 ...

  4. Codeforces | CF1028C 【Rectangles】

    (这道题太简单啦...虽说我锤了一上午都没过...我能说这道题和\(CF1029C\)算是同一道题吗...) 按照时间顺序来说...\(CF1029\)在\(CF1028\)前面(而且\(CF1029 ...

  5. hexo从零开始

    部署Hexo Hexo官方文档 新建一个文件夹,比如,Blog,然后进入该文件夹下: npm install hexo-cli -g hexo version 安装依赖包 npm install 配置 ...

  6. [AH2017/HNOI2017]礼物(FFT)

    题目描述 我的室友最近喜欢上了一个可爱的小女生.马上就要到她的生日了,他决定买一对情侣手 环,一个留给自己,一 个送给她.每个手环上各有 n 个装饰物,并且每个装饰物都有一定的亮度.但是在她生日的前一 ...

  7. CentOS6 部署 Tomcat

    安装java软件 yum install java-1.8.0* -y 设置开机自启,在/etc/init.d/下新建 tomcat 写入以下内容: #!/bin/bash # /etc/rc.d/i ...

  8. Surface Pro 4 系统优化全教程及QA

    甲.如何根据你的需求选择相应版本的surface1.Core M3-6Y30,Core i5-6300U,Core i7-6650U的性能差距有多大?2.HD 515,HD520,Iris 540的性 ...

  9. 【洛谷P2868】Sightseeing Cows

    题目大意:给定一个 N 个点,M 条边的有向图,点有点权,边有边权,求该有向图中的一个环,使得环上点权和与环上边权和之比最大. 题解:0/1 分数规划思想,每次二分一个 mid,在新图上跑 spfa, ...

  10. session会话对象

    一.session会话对象介绍: 会话对象让你能够跨请求保持某些参数,它也会在同一个session实例发出的所有请求之间保持cookie. 二.步骤 1.对session对象进行一次实例化 2.进行登 ...