[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\n", argv[i]);

            continue;

        }

        if((fd = open(argv[i], O_RDWR | O_TRUNC)) < 0)

        {

            printf ("%s: open error\n", 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\n", 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]$

linux之utime函数解析的更多相关文章

  1. Linux exec族函数解析

    背景 在提到 vfork 函数时,我们提到了这个概念.为了更好地学习与运用,我们对exec族函数进行展开. exec函数族 介绍 有时我们希望子进程去执行另外的程序,exec函数族就提供了一个在进程中 ...

  2. linux之unlink函数解析

    [lingyun@localhost unlink]$ cat unlink.c  /********************************************************* ...

  3. linux之access函数解析

    [lingyun@localhost access_1]$ ls access.c 实例一: [lingyun@localhost access_1]$ cat access.c  /******** ...

  4. linux之ioctl函数解析

    [lingyun@localhost ioctl_1]$ ls ipconfig.c [lingyun@localhost ioctl_1]$ cat ipconfig.c  /*********** ...

  5. linux之umask函数解析

    [lingyun@localhost umask_1]$ vim umask.c  + umask.c                                                 ...

  6. linux之chdir函数解析

    [lingyun@localhost chdir]$ ls chdir.c [lingyun@localhost chdir]$ cat chdir.c  /********************* ...

  7. linux之getcwd函数解析

    [lingyun@localhost getcwd]$ cat getcwd.c /********************************************************** ...

  8. linux之stat函数解析

    [lingyun@localhost stat_1]$ vim stat.c  + stat.c                                                     ...

  9. 关于Linux系统basename函数缺陷的思考

    某模块作为前台进程独立运行时,运行命令携带命令行参数:作为某平台下守护进程子进程运行时,需要将命令行参数固化在代码里.类似如下写法: char *argv[] = {"./DslDriver ...

随机推荐

  1. Redis的AOF功能

    引言:  Redis是基于内存的数据库,同时也提供了若干持久化的方案,允许用户把内存中的数据,写入本地文件系统,以备下次重启或者当机之后继续使用.本文将描述如何基于Redis来设置AOF功能 什么是R ...

  2. Traceview 性能分析工具

    简介 TraceView 是 Android 平台配备一个很好的性能分析的工具.它可以通过图形化的方式让我们了解我们要跟踪的程序的性能,并且能具体到 method.详细内容参考:http://deve ...

  3. PHP微信公众号 access_token缓存

    PHP创建access_token.json文件,将access_token 和 生成时间expires 保存在其中, {"access_token":"xxxx&quo ...

  4. System.Web.HttpContext.Current.Session获取值出错

    在自定义类库CS文件里使用System.Web.HttpContext.Current.Session获取Session时提示错误:未将对象引用设置到对象的实例. 一般情况下通过这种方式获取Sessi ...

  5. (转)PHP中的ob_start用法详解

    用PHP的ob_start();控制您的浏览器cache Output Control 函数可以让你自由控制脚本中数据的输出.它非常地有用,特别是对于:当你想在数据已经输出后,再输出文件头的情况.输出 ...

  6. sql - 复制表

    1,复制表结构和内容 1)这个表: select * into new_table_name from old_table_name ref:SQL复制数据表及表结构

  7. JNI type

    ref: JNI type The mapping between the Java type and C type is: Type Signature Java Type Z boolean B ...

  8. Linux makefile 教程 非常详细,且易懂(转)

    转自:http://blog.chinaunix.net/uid-27717694-id-3696246.html 原文地址:Linux makefile 教程 非常详细,且易懂 作者:Deem_pa ...

  9. [javascript]String添加trim和reverse方法

    function trim() { var start, end; start = 0; end = this.length - 1; while(start <= end && ...

  10. bzoj2071: [POI2004]JAS

    Description 在Byteotia有一个洞穴. 它包含n 个洞室和一些隧道连接他们. 每个洞室之间只有一条唯一的路径连接他们. Hansel 在其中一个洞室藏了宝藏, 但是它不会说出它在哪. ...