嵌入式复习IO DAY3

获取文件属性(stat)

man 2stat
头文件
#include <sys/types.h>
#include <syts/stat..h>
#include <unistd.h>
函数接口
int stat (const char*pathname,struct stat *statbuf);
功能:获取文件属性
参数 
	const char *pathname: 文件名
	struct stat *statbuf: 获取文件属性的存亡位置
	返回值:成功:0,失败-1,更新errno 
	struct stat {
   dev_t     st_dev;         /* ID of device containing file */
                                   包含的文件的设备ID
   ino_t     st_ino;         /* Inode number */文件的inode号
   mode_t    st_mode;        /* File type and mode */
                                       文件类型和权限
   nlink_t   st_nlink;       /* Number of hard links */
                                      硬链接数
   uid_t     st_uid;         /* User ID of owner */
                                   用户ID
   gid_t     st_gid;         /* Group ID of owner */
                                   组ID
   dev_t     st_rdev;        /* Device ID (if special file) */
                                   设备ID
   off_t     st_size;        /* Total size, in bytes */
                                   大小
   blksize_t st_blksize;     /* Block size for filesystem I/O */                                 文件系统IO块的大小
   blkcnt_t  st_blocks;      /* Number of 512B block allocated */                                 512B块设备的分配数量
   /* 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 */                                     最后状态改变的时间

打印inode号和设备ID
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
int main(int argc, char const *argv[])
{   
    struct stat sb;
    int fd_st = stat("./stat.c",&sb);
    if (fd_st == -1)
    {
        perror("stat err");
        return -1;
    }
    printf("dev:%ld\n",sb.st_dev);
    printf("inode:%ld\n",sb.st_ino);
    return 0;
}

库的概念

就是把一些常用函数的目标文件打包在一起,提供相应的函数接口,便于程序员使用;本质上来说库是一种可执行代码的二进制形式

库的分类

静态库和动态库,本质区别是代码被载入时刻不同
1.静态库在程序编译时会被链接到目标代码中
优点:程序运行时将不再需要静态库;运行时无需加载库,运行速度更快
缺点:静态库中的代码复制到了程序中,因此体积较大;
静态库升级后,程序需要重新编译链接
2.动态库实在程序运行时才被载入代码中
优点:程序在执行时加载动态库,代码体积小
程序升级更简单;
不同应用程序如果调用相同的库,那么在内存里只需要一份该分享库的实例。
缺点:运行时还需要动态库的存在,移植性较差
动态库 静态库
Linux:.os .a
window: .dll .llb

在这里插入图片描述
静态库与动态库的制作待更。。。。。。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值