utime函数
utime函数:对一个文件的访问和修改时间
#include <utime.h>
int utime( const char *pathname, const struct utimbuf *times );
返回值:若成功则返回0,若出错则返回-1
此函数所使用的数据结构是:
struct utimbuf {
time_t actime; /* access time */
time_t modtime; /* modification time */
}
程序实例:
#include "apue.h"
#include <fcntl.h>
#include <utime.h>
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)
{
/*取得当前时间*/
err_ret("%s:stat error",argv[i]);
continue;
}
if ((fd=open(argv[i],O_RDWR|O_TRUNC))<0)
{
/*截短*/
err_ret("%s:open error ",argv[i]);
continue;
}
close(fd);
timebuf.actime=statbuf.st_atime;
timebuf.modtime=statbuf.st_mtime;
if(utime(argv[i],&timebuf)<0)
{
/*retset time*/
err_ret("%s: utime error",argv[i]);
continue;
}
}
exit(0);
}
运行结果:

utime函数的更多相关文章
- 程序4-6 utime函数实例
//http://blog.chinaunix.net/uid-24549279-id-71355.html /* ========================================== ...
- 文件和目录之utime函数
一个文件的访问和修改时间可以用utime函数更改. #include <utime.h> int utime( const char *pathname, const struct uti ...
- UNIX环境编程学习笔记(11)——文件I/O之文件时间以及 utime 函数
lienhua342014-09-16 1 文件的时间 每个文件都有三个时间字段,如表 1 所示. 表 1: 文件的三个时间字段 说明 字段 st_atime 文件数据的最后访问时间 st_mtime ...
- 十四、文件和目录——文件时间和utime函数
14.1 文件时间 存在于 stat 结构体中 14.2 文件时间函数 14.2.1 介绍 utime(修改文件的存取时间和更改时间) 相关函数 utimes,stat #include <sy ...
- linux之utime函数解析
[lingyun@localhost utime]$ ls hello utime.c world [lingyun@localhost utime]$ cat utime.c /******* ...
- python第六天 函数 python标准库实例大全
今天学习第一模块的最后一课课程--函数: python的第一个函数: 1 def func1(): 2 print('第一个函数') 3 return 0 4 func1() 1 同时返回多种类型时, ...
- [APUE]文件和目录(中)
一.link.unlink.remove和rename 一个文件可以有多个目录项指向其i节点.使用link函数可以创建一个指向现存文件连接 #include <unistd.h> int ...
- Python标准库之核心模块学习记录
内建函数和异常 包括__builtin__模块和exceptions模块 操作系统接口模块 包括提供文件和进程处理功能的os模块,提供平台独立的文件名处理(分拆目录名,文件名,后缀等)的os.path ...
- UNIX,基础知识,文件IO,文件和目录
2015.1.27星期二,早晨阴天,中午下雪了今天上午老师不上课,程序语句,记一下:main(void){ int c; while((c = getc(stdin)) != EOF) if(putc ...
随机推荐
- IIS7 IIS7.5 IIS8.5 HTTP 错误 500.19 – Internal Server Error解决方案小记
今天配置IIS(win8.1 IIS8.5)的web.config出现如下错误: HTTP 错误 500.19 – Internal Server Error无法访问请求的页面,因为该页的相关配置数据 ...
- Python:if __name__ == '__main__'
很多模块里都会看到这句话,一般用于模块自测时使用. 所有的模块都有一个内置属性 __name__. 一个模块的 __name__ 的值取决于您如何应用模块. 一个Python文件有两种使用方式,直接使 ...
- js 淡入淡出的图片
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- Java中的字符串常量池
ava中字符串对象创建有两种形式,一种为字面量形式,如String str = "droid";,另一种就是使用new这种标准的构造对象的方法,如String str = new ...
- 32、shiro框架入门3.授权
一. 授权,也叫访问控制,即在应用中控制谁能访问哪些资源(如访问页面/编辑数据/页面操作等).在授权中需了解的几个关键对象:主体(Subject).资源(Resource).权限(Permission ...
- Binary Tree Maximum Path Sum
Given a binary tree, find the maximum path sum. The path may start and end at any node in the tree. ...
- mysql处理海量数据时的一些优化查询速度方法
最近一段时间由于工作需要,开始关注针对Mysql数据库的select查询语句的相关优化方法. 由于在参与的实际项目中发现当mysql表的数据量达到百万级时,普通SQL查询效率呈直线下降,而且如果w ...
- spring 下载地址
http://repo.spring.io/release/org/springframework/spring/
- iframe自动适应高度1
js: function iFrameHeight() { var ifm= document.getElementById("iframepage"); var subWeb = ...
- [转载] 4. JebAPI 之 jeb.api.ui
本文转载自: https://www.zybuluo.com/oro-oro/note/145250 JebInstance可以通过getUI()方法来获得jeb.api.ui.JebUI. JebU ...