Share via


_futime, _futime32, _futime64

設定已開啟之檔案的修改時間。

語法

int _futime(
   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

使用 __utimbuf64 結構的 _futime64,可以讀取和修改檔案日期至 3000 年 12 月 31 日 23:59:59 UTC,而呼叫 _futime32 時,如果檔案的日期晚於 2038 年 1 月 18 日 23:59:59 UTC 就會失敗。 1970 年 1 月 1 日午夜是這些函式的日期範圍下限。

根據預設,此函式的全域狀態會限定于應用程式。 若要變更此行為,請參閱 CRT 中的全域狀態。

需求

函式 必要的標頭 選擇性標頭
_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

另請參閱

時間管理