Movatterモバイル変換


[0]ホーム

URL:


man7.org > Linux >man-pages

Linux/UNIX system programming training


futimens(3p) — Linux manual page

PROLOG |NAME |SYNOPSIS |DESCRIPTION |RETURN VALUE |ERRORS |EXAMPLES |APPLICATION USAGE |RATIONALE |FUTURE DIRECTIONS |SEE ALSO |COPYRIGHT

FUTIMENS(3P)            POSIX Programmer's ManualFUTIMENS(3P)

PROLOG        top

       This manual page is part of the POSIX Programmer's Manual.  The       Linux implementation of this interface may differ (consult the       corresponding Linux manual page for details of Linux behavior), or       the interface may not be implemented on Linux.

NAME        top

       futimens, utimensat, utimes — set file access and modification       times

SYNOPSIS        top

       #include <sys/stat.h>       int futimens(intfd, const struct timespectimes[2]);       #include <fcntl.h>       int utimensat(intfd, const char *path, const struct timespectimes[2],           intflag);       #include <sys/time.h>       int utimes(const char *path, const struct timevaltimes[2]);

DESCRIPTION        top

       Thefutimens() andutimensat() functions shall set the access and       modification times of a file to the values of thetimes argument.       Thefutimens() function changes the times of the file associated       with the file descriptorfd.  Theutimensat() function changes the       times of the file pointed to by thepath argument, relative to the       directory associated with the file descriptorfd.  Both functions       allow time specifications accurate to the nanosecond.       Forfutimens() andutimensat(), thetimes argument is an array of       twotimespecstructures. The first array member represents the       date and time of last access, and the second member represents the       date and time of last modification. The times in thetimespec       structure are measured in seconds and nanoseconds since the Epoch.       The file's relevant timestamp shall be set to the greatest value       supported by the file system that is not greater than the       specified time.       If thetv_nsec field of atimespecstructure has the special value       UTIME_NOW, the file's relevant timestamp shall be set to the       greatest value supported by the file system that is not greater       than the current time. If thetv_nsec field has the special value       UTIME_OMIT, the file's relevant timestamp shall not be changed. In       either case, thetv_sec field shall be ignored.       If thetimes argument is a null pointer, both the access and       modification timestamps shall be set to the greatest value       supported by the file system that is not greater than the current       time. Ifutimensat() is passed a relative path in thepath       argument, the file to be used shall be relative to the directory       associated with the file descriptorfd instead of the current       working directory. If the access mode of the open file description       associated with the file descriptor is not O_SEARCH, the function       shall check whether directory searches are permitted using the       current permissions of the directory underlying the file       descriptor. If the access mode is O_SEARCH, the function shall not       perform the check.       Ifutimensat() is passed the special value AT_FDCWD in thefd       parameter, the current working directory shall be used.       Only a process with the effective user ID equal to the user ID of       the file, or with write access to the file, or with appropriate       privileges may usefutimens() orutimensat() with a null pointer       as thetimes argument or with bothtv_nsec fields set to the       special value UTIME_NOW. Only a process with the effective user ID       equal to the user ID of the file or with appropriate privileges       may usefutimens() orutimensat() with a non-nulltimes argument       that does not have bothtv_nsec fields set to UTIME_NOW and does       not have bothtv_nsec fields set to UTIME_OMIT. If bothtv_nsec       fields are set to UTIME_OMIT, no ownership or permissions check       shall be performed for the file, but other error conditions may       still be detected (including[EACCES]errors related to the path       prefix).       Values for theflag argument ofutimensat() are constructed by a       bitwise-inclusive OR of flags from the following list, defined in<fcntl.h>:       AT_SYMLINK_NOFOLLOW             Ifpath names a symbolic link, then the access and             modification times of the symbolic link are changed.       Upon successful completion,futimens() andutimensat() shall mark       the last file status change timestamp for update, with the       exception that if bothtv_nsec fields are set to UTIME_OMIT, the       file status change timestamp need not be marked for update.       Theutimes() function shall be equivalent to theutimensat()       function with the special value AT_FDCWD as thefd argument and       theflag argument set to zero, except that thetimes argument is atimevalstructure rather than atimespecstructure, and accuracy       is only to the microsecond, not nanosecond, and rounding towards       the nearest second may occur.

RETURN VALUE        top

       Upon successful completion, these functions shall return 0.       Otherwise, these functions shall return -1 and seterrno to       indicate the error. If -1 is returned, the file times shall not be       affected.

ERRORS        top

       These functions shall fail if:EACCESThetimes argument is a null pointer, or bothtv_nsec              values are UTIME_NOW, and the effective user ID of the              process does not match the owner of the file and write              access is denied.EINVALEither of thetimes argument structures specified atv_nsec              value that was neither UTIME_NOW nor UTIME_OMIT, and was a              value less than zero or greater than or equal to 1000              million.EINVALA new file timestamp would be a value whosetv_sec              component is not a value supported by the file system.EPERMThetimes argument is not a null pointer, does not have              bothtv_nsec fields set to UTIME_NOW, does not have bothtv_nsec fields set to UTIME_OMIT, the calling process'              effective user ID does not match the owner of the file, and              the calling process does not have appropriate privileges.EROFSThe file system containing the file is read-only.       Thefutimens() function shall fail if:EBADFThefd argument is not a valid file descriptor.       Theutimensat() function shall fail if:EACCESThe access mode of the open file description associated              withfd is not O_SEARCH and the permissions of the              directory underlyingfd do not permit directory searches.EBADFThepath argument does not specify an absolute path and thefd argument is neither AT_FDCWD nor a valid file descriptor              open for reading or searching.ENOTDIR              Thepath argument is not an absolute path andfd is a file              descriptor associated with a non-directory file.       Theutimensat() andutimes() functions shall fail if:EACCESSearch permission is denied by a component of the path              prefix.ELOOPA loop exists in symbolic links encountered during              resolution of thepath argument.ENAMETOOLONG              The length of a component of a pathname is longer than              {NAME_MAX}.ENOENTA component ofpath does not name an existing file orpath              is an empty string.ENOTDIR              A component of the path prefix names an existing file that              is neither a directory nor a symbolic link to a directory,              or thepath argument contains at least one non-<slash>              character and ends with one or more trailing <slash>              characters and the last pathname component names an              existing file that is neither a directory nor a symbolic              link to a directory.       Theutimensat() andutimes() functions may fail if:ELOOPMore than {SYMLOOP_MAX} symbolic links were encountered              during resolution of thepath argument.ENAMETOOLONG              The length of a pathname exceeds {PATH_MAX}, or pathname              resolution of a symbolic link produced an intermediate              result with a length that exceeds {PATH_MAX}.       Theutimensat() function may fail if:EINVALThe value of theflag argument is not valid.The following sections are informative.

EXAMPLES        top

       None.

APPLICATION USAGE        top

       None.

RATIONALE        top

       The purpose of theutimensat() function is to set the access and       modification time of files in directories other than the current       working directory without exposure to race conditions. Any part of       the path of a file could be changed in parallel to a call toutimes(), resulting in unspecified behavior. By opening a file       descriptor for the target directory and using theutimensat()       function it can be guaranteed that the changed file is located       relative to the desired directory.       The standard developers considered including a special case for       the permissions required byutimensat() when onetv_nsec field is       UTIME_NOW and the other is UTIME_OMIT. One possibility would be to       include this case in with the cases wheretimes is a null pointer       or both fields are UTIME_NOW, where the call is allowed if the       process has write permission for the file. However, associating       write permission with an update to just the last data access       timestamp (which is normally updated byread()) did not seem       appropriate. The other possibility would be to specify that this       one case is allowed if the process has read permission, but this       was felt to be too great a departure from theutime() andutimes()       functions on whichutimensat() is based. If an application needs       to set the last data access timestamp to the current time for a       file on which it has read permission but is not the owner, it can       do so by opening the file, reading one or more bytes (or reading a       directory entry, if the file is a directory), and then closing it.

FUTURE DIRECTIONS        top

       None.

SEE ALSO        top

read(3p),utime(3p)       The Base Definitions volume of POSIX.1‐2017,fcntl.h(0p),sys_stat.h(0p),sys_time.h(0p)

COPYRIGHT        top

       Portions of this text are reprinted and reproduced in electronic       form from IEEE Std 1003.1-2017, Standard for Information       Technology -- Portable Operating System Interface (POSIX), The       Open Group Base Specifications Issue 7, 2018 Edition, Copyright       (C) 2018 by the Institute of Electrical and Electronics Engineers,       Inc and The Open Group.  In the event of any discrepancy between       this version and the original IEEE and The Open Group Standard,       the original IEEE and The Open Group Standard is the referee       document. The original Standard can be obtained online athttp://www.opengroup.org/unix/online.html .       Any typographical or formatting errors that appear in this page       are most likely to have been introduced during the conversion of       the source files to man page format. To report such errors, seehttps://www.kernel.org/doc/man-pages/reporting_bugs.html .IEEE/The Open Group                2017FUTIMENS(3P)

Pages that refer to this page:fcntl.h(0p)sys_stat.h(0p)sys_time.h(0p)utime.h(0p)touch(1p)time(3p)utime(3p)utimensat(3p)



HTML rendering created 2025-09-06 byMichael Kerrisk, author ofThe Linux Programming Interface.

For details of in-depthLinux/UNIX system programming training courses that I teach, lookhere.

Hosting byjambit GmbH.

Cover of TLPI


[8]ページ先頭

©2009-2025 Movatter.jp