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\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函数解析的更多相关文章
- Linux exec族函数解析
背景 在提到 vfork 函数时,我们提到了这个概念.为了更好地学习与运用,我们对exec族函数进行展开. exec函数族 介绍 有时我们希望子进程去执行另外的程序,exec函数族就提供了一个在进程中 ...
- linux之unlink函数解析
[lingyun@localhost unlink]$ cat unlink.c /********************************************************* ...
- linux之access函数解析
[lingyun@localhost access_1]$ ls access.c 实例一: [lingyun@localhost access_1]$ cat access.c /******** ...
- linux之ioctl函数解析
[lingyun@localhost ioctl_1]$ ls ipconfig.c [lingyun@localhost ioctl_1]$ cat ipconfig.c /*********** ...
- linux之umask函数解析
[lingyun@localhost umask_1]$ vim umask.c + umask.c ...
- linux之chdir函数解析
[lingyun@localhost chdir]$ ls chdir.c [lingyun@localhost chdir]$ cat chdir.c /********************* ...
- linux之getcwd函数解析
[lingyun@localhost getcwd]$ cat getcwd.c /********************************************************** ...
- linux之stat函数解析
[lingyun@localhost stat_1]$ vim stat.c + stat.c ...
- 关于Linux系统basename函数缺陷的思考
某模块作为前台进程独立运行时,运行命令携带命令行参数:作为某平台下守护进程子进程运行时,需要将命令行参数固化在代码里.类似如下写法: char *argv[] = {"./DslDriver ...
随机推荐
- AS 进行单元测试
以下为本人在AndroidStudio 2.0 上实测后得出的结论,不像网上那一堆堆的误人子弟的文章,都是过时的或者根本就是不对的. 简介 和eclipse需要配置清单文件不同,AndroidStud ...
- MediaCodec文档翻译
MediaCodec|文档翻译 classoverView mediacodec类可以用来调用系统底层的编码/解码软件. mediacodec一般是这么用的: MediaCodec codec = M ...
- 国内优秀npm镜像
淘宝npm镜像 淘宝npm镜像:http://npm.taobao.org/ 1.临时使用 npm --registry https://registry.npm.taobao.org install ...
- 昨天做了一个使用javamail发送文件的demo
记录一下过程. 两种版本第一个demo是纯java文件.一个就可以,是我在网上搜索到的,第二个demo是我在ssh框中中写的jsp页面demo 1.java版本: package com.zq.www ...
- (转)PHP中构造函数和析构函数解析
--http://www.jb51.net/article/56047.htm 构造函数 void __construct ([ mixed $args [, $... ]] ) PHP 5 允行开发 ...
- 关于asp.net中cookie在调试过程中读写正常发布后乱码问题
最近在做的项目发布后出现了乱码的问题,既然出现了乱码很大的可能性是跟编码有关系,所以首先的解决方案就是重新对cookie进行编码, 在写入的cookie的时候编码,在读取的时候解码 在写入cookie ...
- XMPP基础
概要 1.即时通讯技术简介2.XMPP诞生的由来3.XMPP特点4.XMPP的基本结构5.XMPP工作原理6.XMPP的优缺点7.OSI七层模型8.IP地址.端口号.传输协议9.TCP和UDP的区别1 ...
- hibernate_validator_08
内置的约束条件 Hibernate Validator包含了一些基本的使用比较广的约束,下面是一些Hibernate Validator给出的最常用的约束.另外Hibernate Validator还 ...
- jquery如何将获取的颜色值转换为十六进制形式
jquery如何将获取的颜色值转换为十六进制形式:大家或许已经注意到了,在谷歌.火狐和IE8以上浏览器中,获取的颜色值是RGB形式,例如rgb(255,255,0),感觉非常不适应,或者在实际编码中不 ...
- 说一说&&符
今天添加检测代码,还得添加好几套,好蛋疼. 为了省点事,全写在HTML的行间onclick里,为此专门琢磨了一下&&的用法. 一般用&&(除了逻辑判断里),是为了简写i ...