设置打开的文件的修改时间。
语法
int _futime( // See note in remarks section about linkage
int fd,
struct _utimbuf *filetime
);
int _futime32(
int fd,
struct __utimbuf32 *filetime
);
int _futime64(
int fd,
struct __utimbuf64 *filetime
);
参数
fd
打开的文件的文件描述符。
filetime
指向包含新修改日期的结构的指针。
返回值
如果成功,则返回 0。 出现错误时,会调用无效参数处理程序,如参数验证中所述。 如果允许执行继续,函数将返回 -1,并且将 errno 设置为 EBADF(指示文件描述符无效),或设置为 EINVAL(指示参数无效)。
注解
_futime 例程在与 fd 关联的打开文件上设置修改日期和访问时间。
_futime 等同于 _utime,只不过其参数是打开的文件的文件描述符,而不是文件的名称或文件的路径名称。
_utimbuf 结构包含新修改日期和访问时间的字段。 这两个字段必须包含有效的值。
_utimbuf32 和 _utimbuf64 等同于 _utimbuf,只不过分别用于 32 位和 64 位的时间类型。
_futime 和 _utimbuf 使用 64 位时间类型,_futime 的行为等同于 _futime64。 若要强制旧的非标准行为,请定义 _USE_32BIT_TIME_T。 这样做,会导致 _futime 的行为等同于 _futime32,并致使 _utimbuf 结构使用 32 位时间类型,使其等效于 __utimbuf32。
_futime64 使用 __utimbuf64 结构,可以读取和修改日期截至 3000 年 12 月 31 日 23:59:59 UTC 的文件;如果文件日期晚于 2038 年 1 月 18 日 23:59:59 UTC,则对 _futime32 的调用失败。 1970 年 1 月 1 日午夜是这些函数的日期范围下限。
默认情况下,此函数的全局状态范围限定为应用程序。 若要更改此行为,请参阅 CRT 中的全局状态。
注释
如果使用 Windows SDK 版本 10.0.26100.6901 和 Visual Studio 2026 或更高版本, _futime 则不再 static inline (内部链接)。
inline 而是(外部链接)。
若要返回到以前的行为, #define _STATIC_INLINE_UCRT_FUNCTIONS=1 请先包括任何 CRT 标头。 默认情况下,_STATIC_INLINE_UCRT_FUNCTIONS 设置为 0。
此更改增加了与 C++ 标准的 UCRT 一致性,并提高了与C++模块的兼容性。
要求
| 函数 | 必需的标头 | 可选标头 |
|---|---|---|
_futime |
<sys/utime.h> |
<errno.h> |
_futime32 |
<sys/utime.h> |
<errno.h> |
_futime64 |
<sys/utime.h> |
<errno.h> |
有关兼容性的详细信息,请参阅 兼容性。
示例
// crt_futime.c
// This program uses _futime to set the
// file-modification time to the current time.
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <io.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/utime.h>
#include <share.h>
int main( void )
{
int hFile;
// Show file time before and after.
system( "dir crt_futime.c_input" );
_sopen_s( &hFile, "crt_futime.c_input", _O_RDWR, _SH_DENYNO, 0 );
if( _futime( hFile, NULL ) == -1 )
perror( "_futime failed\n" );
else
printf( "File time modified\n" );
_close (hFile);
system( "dir crt_futime.c_input" );
}
输入:crt_futime.c_input
Arbitrary file contents.
示例输出
Volume in drive Z has no label.
Volume Serial Number is 5C68-57C1
Directory of Z:\crt
03/25/2004 10:40 AM 24 crt_futime.c_input
1 File(s) 24 bytes
0 Dir(s) 24,268,476,416 bytes free
Volume in drive Z has no label.
Volume Serial Number is 5C68-57C1
Directory of Z:\crt
03/25/2004 10:41 AM 24 crt_futime.c_input
1 File(s) 24 bytes
0 Dir(s) 24,268,476,416 bytes free
File time modified