• linux之utime函数解析


    [lingyun@localhost utime]$ ls
    hello  utime.c  world
    [lingyun@localhost utime]$ cat utime.c 
    /*********************************************************************************
     *      Copyright:  (C) 2013 fulinux<fulinux@sina.com> 
     *                  All rights reserved.
     *
     *       Filename:  utime.c
     *    Description:  This file 
     *                 
     *        Version:  1.0.0(08/04/2013~)
     *         Author:  fulinux <fulinux@sina.com>
     *      ChangeLog:  1, Release initial version on "08/04/2013 05:49:04 PM"
     *                 
     ********************************************************************************/
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <unistd.h>
    #include <fcntl.h>
    #include <utime.h>
    #include <sys/stat.h>




    /********************************************************************************
     *  Description:
     *   Input Args:
     *  Output Args:
     * Return Value:
     ********************************************************************************/
    int main (int argc, char **argv)
    {
        int     i, fd;
        struct stat statbuf;
        struct utimbuf timebuf;


        for(i = 1; i < argc; i++)
        {
            if(stat(argv[i], &statbuf) < 0)
            {
                printf ("%s: stat error ", argv[i]);
                continue;
            }
            if((fd = open(argv[i], O_RDWR | O_TRUNC)) < 0)
            {
                printf ("%s: open error ", argv[i]);
                continue;
            }
            close(fd);
            timebuf.actime  = statbuf.st_atime;
            timebuf.modtime = statbuf.st_mtime;


            if(utime(argv[i], &timebuf) < 0)
            {
                printf ("%s: utime error ", argv[i]);
                continue;
            }
        }
        exit(0);
    } /* ----- End of main() ----- */




    [lingyun@localhost utime]$ gcc utime.c 
    [lingyun@localhost utime]$ ls -l hello world 
    -rw-r--r-- 1 lingyun trainning 0 Aug  4 18:03 hello
    -rw-r--r-- 1 lingyun trainning 0 Aug  4 18:04 world
    [lingyun@localhost utime]$ ls -lu hello world 
    -rw-r--r-- 1 lingyun trainning 0 Aug  4 18:03 hello
    -rw-r--r-- 1 lingyun trainning 0 Aug  4 18:04 world
    [lingyun@localhost utime]$ date
    Sun Aug  4 18:10:44 CST 2013
    [lingyun@localhost utime]$ ./a.out hello world 
    [lingyun@localhost utime]$ ls -l hello world 
    -rw-r--r-- 1 lingyun trainning 0 Aug  4 18:03 hello
    -rw-r--r-- 1 lingyun trainning 0 Aug  4 18:04 world
    [lingyun@localhost utime]$ ls -lu hello world 
    -rw-r--r-- 1 lingyun trainning 0 Aug  4 18:03 hello
    -rw-r--r-- 1 lingyun trainning 0 Aug  4 18:04 world
    [lingyun@localhost utime]$ ls -lc hello world 
    -rw-r--r-- 1 lingyun trainning 0 Aug  4 18:10 hello
    -rw-r--r-- 1 lingyun trainning 0 Aug  4 18:10 world
    [lingyun@localhost utime]$ 

  • 相关阅读:
    中台架构的新一代业务支撑体系是如何实现
    共同探索企业级数据库架构之道路
    综述:图像风格化算法最全盘点 | 内附大量扩展应用
    【加法笔记系列】JS 加法器模拟
    OAuth 及 移动端鉴权调研
    神经引导演绎搜索:两全其美的程序合成方法
    围观神龙架构首次开箱,现场直播暴力拆机
    QA质量意识
    接口测试总结篇
    接口测试用例设计
  • 原文地址:https://www.cnblogs.com/riskyer/p/3236954.html
Copyright © 2020-2023  润新知