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. Ddos 分布式拒绝服务 (报告)

    Ddos  译:分布式拒绝服务 两日之余的 Ddos 学习: 也看完了市场上(当时的我查到的市场)唯一 书<破坏之王>: 使用了些好找或不好找的攻击软件:几经测试与实践: 1.结果:最多造 ...

  2. 【arc073e】Ball Coloring(线段树,贪心)

    [arc073e]Ball Coloring(线段树,贪心) 题面 AtCoder 洛谷 题解 大型翻车现场,菊队完美压中男神的模拟题 首先钦定全局最小值为红色,剩下的袋子按照其中较大值排序. 枚举前 ...

  3. hexo+next主题目录解析

    默认目录结构: . ├── .deploy ├── public ├── scaffolds ├── scripts ├── source | ├── _drafts | └── _posts ├── ...

  4. LNOI2014LCA(树链剖分+离线操作+前缀和)

    题意:给一棵有根树,有多组询问,询问为l r z,求下标为l到r之间的点和z的lca的深度和. 如果我们一个一个求.emmmmm... 考虑答案怎么产生,仔细想一想,如果我们把l到r的所有点到根都加上 ...

  5. js定时器setInterval()与setTimeout()

    js定时器setInterval()与setTimeout() 1.setTimeout(Expression,DelayTime),在DelayTime过后,将执行一次Expression,setT ...

  6. QML学习笔记(五)— 做一个简单的待做事项列表

    做一个简单的QML待做事项列表,能够动态添加和删除和编辑数据 GitHub:八至 作者:狐狸家的鱼 本文链接:QML学习笔记(五)— 做一个待做事项列表 主要用到QML:ListView 效果 全部代 ...

  7. 生成SSH密钥添加到GitHub

    将自己的过程和踩坑写下来 一.检查是否有SSH 1.打开Git的目录文件,下图是我电脑中git的文件目录 2.点击git-bash.exe,输入ssh查看电脑中是否已存在ssh,会出现以下结果,证明已 ...

  8. MariaDB安装及基本配置

    MariaDB安装及基本配置(CentOS6.9) 数据库基础概念 数据库(Database, DB)是按照数据结构来组织.存储和管理数据的建立在计算机存储设备上的仓库. DBMS: Database ...

  9. Django 配置QQ邮箱连接

    首先要在settings.py内进行配置 # 邮件服务配置文件 EMAIL_USE_SSL = True # 邮箱服务 EMAIL_HOST = 'smtp.qq.com' # 端口号 EMAIL_P ...

  10. flutte项目命令行打包

    进入自己flutter项目根目录,运行以下命令 flutter build apk #打包安卓 flutter build ios #打包ios 然后会给出一个路径,就是打包完成的apk的位置 bui ...