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 ...
随机推荐
- 关于svn获取获取文件时 Unable to connect to a repository at URL"https://..."执行上下文错误:参数错误
错误提示: 下面的六种解决方案都未能解决: 1.不提示输入用户名和密码,不管重装多少次都一样. 2.TortoiseSVN的setting->Saved Data->Authenticat ...
- myeclipse 'no default proposals' when use 'alt + /'.
solution: Window -> Preferences -> Java -> Editor -> Content Assist -> Advanced in th ...
- Lucene.net 从创建索引到搜索的代码范例
关于Lucene.Net的介绍网上已经很多了在这里就不多介绍Lucene.Net主要分为建立索引,维护索引和搜索索引Field.Store的作用是通过全文检查就能返回对应的内容,而不必再通过id去DB ...
- mybatis 一对一关联
首先建表: CREATE TABLE teacher( t_id INT PRIMARY KEY AUTO_INCREMENT, t_name VARCHAR(20) ); CREATE TABLE ...
- 读书笔记 |Google C++编程风格指南
Google C++编程风格指南 ## 0. 背景 每一个C++程序员都知道,C++具有很多强大的语言特性,但这种强大不可避免的导致它的复杂,这种复杂会使得代码更易于出现bug.难于阅读和维护. 本指 ...
- C++中L和_T()之区别(转)
C++中L和_T()之区别 分类: C/C++2011-01-12 11:45 2878人阅读 评论(1) 收藏 举报 c++编译器apic 字符串前面加L表示该字符串是Unicode字符串._T是一 ...
- 《C++游戏开发》笔记十四 平滑过渡的战争迷雾(二) 实现:真正的迷雾来了
本系列文章由七十一雾央编写,转载请注明出处. http://blog.csdn.net/u011371356/article/details/9712321 作者:七十一雾央 新浪微博:http:/ ...
- C++ Primer 5th 第13章 拷贝控制
当一个对象的引用或者指针离开作用域时,析构函数不会执行. 构造函数有初始化部分(初始化列表)和函数体. 析构函数有析构部分和函数,但析构函数的析构部分是隐式的.
- JQuery相关的网络资源
jquery插件列表 国外网站:http://plugins.jquery.com/ 国内网站:http://www.oschina.net/project/tag/273/jquery
- 关于$GLOBALS['ecs']->table()的问题?
$ecs对象定义数据库和表前缀 class ECS { var $db_name = ''; var $prefix = 'ecs_'; function ECS($db_name, $prefix) ...