# futimens

## PROLOG



           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



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


## SYNOPSIS



           #include <sys/stat.h>
    
           int futimens(int _fd_ , const struct timespec _times_[2]);
    
           #include <fcntl.h>
    
           int utimensat(int _fd_ , const char *_path_ , const struct timespec _times_[2],
               int _flag_);
    
           #include <sys/time.h>
    
           int utimes(const char *_path_ , const struct timeval _times_[2]);
    


## DESCRIPTION



           The _futimens_() and _utimensat_() functions shall set the access and
           modification times of a file to the values of the _times_ argument.
           The _futimens_() function changes the times of the file associated
           with the file descriptor _fd_.  The _utimensat_() function changes the
           times of the file pointed to by the _path_ argument, relative to the
           directory associated with the file descriptor _fd_.  Both functions
           allow time specifications accurate to the nanosecond.
    
           For _futimens_() and _utimensat_(), the _times_ argument is an array of
           two **timespec** structures. 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 the **timespec**
           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 the _tv_nsec_ field of a **timespec** structure 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 the _tv_nsec_ field has the special value
           UTIME_OMIT, the file's relevant timestamp shall not be changed. In
           either case, the _tv_sec_ field shall be ignored.
    
           If the _times_ 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. If _utimensat_() is passed a relative path in the _path_
           argument, the file to be used shall be relative to the directory
           associated with the file descriptor _fd_ 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.
    
           If _utimensat_() is passed the special value AT_FDCWD in the _fd_
           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 use _futimens_() or _utimensat_() with a null pointer
           as the _times_ argument or with both _tv_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 use _futimens_() or _utimensat_() with a non-null _times_ argument
           that does not have both _tv_nsec_ fields set to UTIME_NOW and does
           not have both _tv_nsec_ fields set to UTIME_OMIT. If both _tv_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 the _flag_ argument of _utimensat_() are constructed by a
           bitwise-inclusive OR of flags from the following list, defined in
           _< fcntl.h>_:
    
           AT_SYMLINK_NOFOLLOW
                 If _path_ names a symbolic link, then the access and
                 modification times of the symbolic link are changed.
    
           Upon successful completion, _futimens_() and _utimensat_() shall mark
           the last file status change timestamp for update, with the
           exception that if both _tv_nsec_ fields are set to UTIME_OMIT, the
           file status change timestamp need not be marked for update.
    
           The _utimes_() function shall be equivalent to the _utimensat_()
           function with the special value AT_FDCWD as the _fd_ argument and
           the _flag_ argument set to zero, except that the _times_ argument is a
           **timeval** structure rather than a **timespec** structure, and accuracy
           is only to the microsecond, not nanosecond, and rounding towards
           the nearest second may occur.
    


## RETURN VALUE



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


## ERRORS



           These functions shall fail if:
    
           **EACCES** The _times_ argument is a null pointer, or both _tv_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.
    
           **EINVAL** Either of the _times_ argument structures specified a _tv_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.
    
           **EINVAL** A new file timestamp would be a value whose _tv_sec_
                  component is not a value supported by the file system.
    
           **EPERM** The _times_ argument is not a null pointer, does not have
                  both _tv_nsec_ fields set to UTIME_NOW, does not have both
                  _tv_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.
    
           **EROFS** The file system containing the file is read-only.
    
           The _futimens_() function shall fail if:
    
           **EBADF** The _fd_ argument is not a valid file descriptor.
    
           The _utimensat_() function shall fail if:
    
           **EACCES** The access mode of the open file description associated
                  with _fd_ is not O_SEARCH and the permissions of the
                  directory underlying _fd_ do not permit directory searches.
    
           **EBADF** The _path_ argument does not specify an absolute path and the
                  _fd_ argument is neither AT_FDCWD nor a valid file descriptor
                  open for reading or searching.
    
           **ENOTDIR**
                  The _path_ argument is not an absolute path and _fd_ is a file
                  descriptor associated with a non-directory file.
    
           The _utimensat_() and _utimes_() functions shall fail if:
    
           **EACCES** Search permission is denied by a component of the path
                  prefix.
    
           **ELOOP** A loop exists in symbolic links encountered during
                  resolution of the _path_ argument.
    
           **ENAMETOOLONG**
                  The length of a component of a pathname is longer than
                  {NAME_MAX}.
    
           **ENOENT** A component of _path_ does not name an existing file or _path_
                  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 the _path_ 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.
    
           The _utimensat_() and _utimes_() functions may fail if:
    
           **ELOOP** More than {SYMLOOP_MAX} symbolic links were encountered
                  during resolution of the _path_ 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}.
    
           The _utimensat_() function may fail if:
    
           **EINVAL** The value of the _flag_ argument is not valid.
    
           _The following sections are informative._
    


## EXAMPLES



           None.
    


## APPLICATION USAGE



           None.
    


## RATIONALE



           The purpose of the _utimensat_() 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 to
           _utimes_(), resulting in unspecified behavior. By opening a file
           descriptor for the target directory and using the _utimensat_()
           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 by _utimensat_() when one _tv_nsec_ field is
           UTIME_NOW and the other is UTIME_OMIT. One possibility would be to
           include this case in with the cases where _times_ 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 by _read_()) 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 the _utime_() and _utimes_()
           functions on which _utimensat_() 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



           None.
    


* * *