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 ...
随机推荐
- VB 增强的部件与引用
常用部件 对话框 Microsoft Common Dialog Control 6.0 (sp6) COMDLG32.OCX Forms2.0控件 Microsoft Forms 2. ...
- BaseBean构造
package cn.jsonlu.passguard.model; import cn.jsonlu.passguard.utils.MD5Util; import com.fasterxml.ja ...
- Android中的缓存机制与实现
分步阅读 Android开发本质上就是手机和互联网中的web服务器之间进行通信,就必然需要从服务端获取数据,而反复通过网络获取数据是比较耗时的,特别是访问比较多的时候,会极大影响了性能,Android ...
- Google与微软为jQuery等类库提供的CDN服务
相关链接: Google: http://code.google.com/apis/ajaxlibs/Microsoft: http://www.asp.net/ajaxlibrary/cdn.a ...
- Webview的使用和注意事项
1.webView是一个展示web网页的控件,继承 AbsoluteLayout 2.webview的俩个回调应用层: 1)webViewClient 这个对象的创建 WebViewClient my ...
- 程序里面的system.out.println()输出到其他位置,不输出到tomcat控制台。
设置startup.bat: call "%EXECUTABLE%" run %CMD_LINE_ARGS% >> ..\logs\kongzitai.txt 将sys ...
- makecert 制作数字证书
在MS的SDK6.0中有个证书生成工具makecert.exe, 你可以使用这个工具来生成测试用的证书. 第一步,生成一个自签名的根证书(issuer,签发者). >makecert -n &q ...
- centos U盘安装
1.版本 LiveCD 和 LiveDVD 是可以直接进入运行系统,类似win PE, 进入系统后有一个图标 install - HHD(从硬盘安装). netinstall 是用于网络安装和系统救援 ...
- GetComponents和FindObjectsOfTypeAll区别
本文由博主(YinaPan)原创,转载请注明出处:http://www.cnblogs.com/YinaPan/p/Unity_GetComponent.html GetComponents获得的是当 ...
- 跟我学android-Android应用基本组件介绍(五)
Activity activity 是最基本的模块,我们成为活动,一个activity通常就是一个单独的屏幕,每一个活动都被实现为一个独立的类,且都继承活动的基类.在activity的实现类里显示用户 ...