Linux服务器编程之:utime()函数

简介: 1.依赖的头文件 #include<sys/types.h> #include<utime.h> 2函数声明 int utime(const char *filename, const struct utimbuf *times); #include<sys/time.h> int utimes(const char *filename,co

1.依赖的头文件

#include<sys/types.h>

#include<utime.h>

2函数声明

int utime(const char *filename, const struct utimbuf *times);

#include<sys/time.h>

int utimes(const char *filename,const struct timeval times[2]);

函数说明:

The  utime()  system  call changes the access and modification times of
       the inode specified by filename to the actime  and  modtime  fields  of
       times respectively.

       翻译:调用utime来修改inode中的信息,传递的值有:文件名,访问时间和更改时间。

If  times  is  NULL, then the access and modification times of the file
       are set to the current time.

      翻译:如果时间为NULL,访问时间和修改时间默认设置成了当前时间。


      成功放回0,失败返回1

3.下面是    utimbuf这个结构体:

     struct utimbuf

     {

              time_t atime;          /*access time :访问时间*/

              time_t modtime;     /*modification time : 更改时间*/

     };

4.utimes()调用也

The utimes() system call is similar, but the times argument  refers  to
       an  array  rather  than  a  structure.   The elements of this array are
       timeval structures, which allow a precision of 1 microsecond for speci‐
       fying timestamps.  The timeval structure is:

           struct timeval {
               long tv_sec;        /* seconds */
               long tv_usec;       /* microseconds */
           };

       times[0]  specifies the new access time, and times[1] specifies the new
       modification time.  If times is NULL, then analogously to utime(),  the
       access and modification times of the file are set to the current time.

utimes()的调用也相似,但是这个时间指定的是一个数组,而不是一个结构体,数组的每个元素师一个timeval结构体

这个结构体中允许一个为timestamps所用的精确的微秒值(微秒,百万分之一秒),其中timeval结构体如下:

       struct timeval

       {

             long tv_sec;          /*seconds 秒*/

             long tv_usec;        /*microseconds 微秒,百万分之一秒*/

       }

times[0]这个元素指定的是访问时间,times[1]指定的是修改时间。如果时间为NULL,那么,类似(analogously)utime(),

访问时间和修改时间被设置成当前时间。









目录
相关文章
|
5天前
|
安全 Java 数据处理
Python网络编程基础(Socket编程)多线程/多进程服务器编程
【4月更文挑战第11天】在网络编程中,随着客户端数量的增加,服务器的处理能力成为了一个重要的考量因素。为了处理多个客户端的并发请求,我们通常需要采用多线程或多进程的方式。在本章中,我们将探讨多线程/多进程服务器编程的概念,并通过一个多线程服务器的示例来演示其实现。
|
7天前
|
Java Linux
Springboot 解决linux服务器下获取不到项目Resources下资源
Springboot 解决linux服务器下获取不到项目Resources下资源
|
10天前
|
Linux
linux下搭建tftp服务器教程
在Linux中搭建TFTP服务器,需安装`tftp-server`(如`tftpd-hpa`)。步骤包括:更新软件包列表,安装`tftpd-hpa`,启动并设置开机自启,配置服务器(编辑`/etc/default/tftpd-hpa`),添加选项,然后重启服务。完成后,可用`tftp`命令进行文件传输。例如,从IP`192.168.1.100`下载`file.txt`: ``` tftp 192.168.1.100 &lt;&lt;EOF binary put file.txt quit EOF ```
26 4
|
14天前
|
Linux
关于Linux目录访问函数总结
关于Linux目录访问函数总结
11 1
|
9天前
|
网络协议 Python
pythonTCP客户端编程连接服务器
【4月更文挑战第6天】本教程介绍了TCP客户端如何连接服务器,包括指定服务器IP和端口、发送连接请求、处理异常、进行数据传输及关闭连接。在Python中,使用`socket`模块创建Socket对象,然后通过`connect()`方法尝试连接服务器 `(server_ip, server_port)`。成功连接后,利用`send()`和`recv()`进行数据交互,记得在通信完成后调用`close()`关闭连接,确保资源释放和程序稳定性。
|
21天前
|
存储 算法 Linux
【Linux系统编程】Linux 文件系统探究:深入理解 struct dirent、DIR 和 struct stat结构
【Linux系统编程】Linux 文件系统探究:深入理解 struct dirent、DIR 和 struct stat结构
34 0
|
3天前
|
Linux 数据安全/隐私保护
Linux基础与服务器架构综合小实践
【4月更文挑战第9天】Linux基础与服务器架构综合小实践
312 6
|
14天前
|
传感器 Linux API
嵌入式Linux串口编程简介
嵌入式Linux串口编程简介
13 1
|
14天前
|
Linux 测试技术 C语言
【Linux】应用编程之C语言文件操作
【Linux】应用编程之C语言文件操作
|
14天前
|
Ubuntu Linux 虚拟化
【Linux】ubuntu安装samba服务器
【Linux】ubuntu安装samba服务器