{"id":4961,"date":"2022-12-20T18:37:00","date_gmt":"2022-12-20T21:37:00","guid":{"rendered":"http:\/\/lode.uno\/linux-man\/index.php\/2022\/12\/20\/futimens-man3p\/"},"modified":"2022-12-20T18:37:00","modified_gmt":"2022-12-20T21:37:00","slug":"futimens-man3p","status":"publish","type":"post","link":"https:\/\/lode.uno\/linux-man\/2022\/12\/20\/futimens-man3p\/","title":{"rendered":"FUTIMENS (man3p)"},"content":{"rendered":"<h1 align=\"center\">FUTIMENS<\/h1>\n<p> <a href=\"#PROLOG\">PROLOG<\/a><br \/> <a href=\"#NAME\">NAME<\/a><br \/> <a href=\"#SYNOPSIS\">SYNOPSIS<\/a><br \/> <a href=\"#DESCRIPTION\">DESCRIPTION<\/a><br \/> <a href=\"#RETURN VALUE\">RETURN VALUE<\/a><br \/> <a href=\"#ERRORS\">ERRORS<\/a><br \/> <a href=\"#EXAMPLES\">EXAMPLES<\/a><br \/> <a href=\"#APPLICATION USAGE\">APPLICATION USAGE<\/a><br \/> <a href=\"#RATIONALE\">RATIONALE<\/a><br \/> <a href=\"#FUTURE DIRECTIONS\">FUTURE DIRECTIONS<\/a><br \/> <a href=\"#SEE ALSO\">SEE ALSO<\/a><br \/> <a href=\"#COPYRIGHT\">COPYRIGHT<\/a> <\/p>\n<hr>\n<h2>PROLOG <a name=\"PROLOG\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">This manual page is part of the POSIX Programmer\u2019s 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.<\/p>\n<h2>NAME <a name=\"NAME\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">futimens, utimensat, utimes \u2014 set file access and modification times<\/p>\n<h2>SYNOPSIS <a name=\"SYNOPSIS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">#include <sys\/stat.h><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">int futimens(int <i>fd<\/i>, const struct timespec <i>times<\/i>[2]);<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">#include <fcntl.h><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">int utimensat(int <i>fd<\/i>, const char *<i>path<\/i>, const struct timespec <i>times<\/i>[2], <br \/> int <i>flag<\/i>);<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">#include <sys\/time.h><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">int utimes(const char *<i>path<\/i>, const struct timeval <i>times<\/i>[2]);<\/p>\n<h2>DESCRIPTION <a name=\"DESCRIPTION\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">The <i>futimens<\/i>() and <i>utimensat<\/i>() functions shall set the access and modification times of a file to the values of the <i>times<\/i> argument. The <i>futimens<\/i>() function changes the times of the file associated with the file descriptor <i>fd<\/i>. The <i>utimensat<\/i>() function changes the times of the file pointed to by the <i>path<\/i> argument, relative to the directory associated with the file descriptor <i>fd<\/i>. Both functions allow time specifications accurate to the nanosecond.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">For <i>futimens<\/i>() and <i>utimensat<\/i>(), the <i>times<\/i> argument is an array of two <b>timespec<\/b> 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 <b>timespec<\/b> structure are measured in seconds and nanoseconds since the Epoch. The file\u2019s relevant timestamp shall be set to the greatest value supported by the file system that is not greater than the specified time.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">If the <i>tv_nsec<\/i> field of a <b>timespec<\/b> structure has the special value UTIME_NOW, the file\u2019s relevant timestamp shall be set to the greatest value supported by the file system that is not greater than the current time. If the <i>tv_nsec<\/i> field has the special value UTIME_OMIT, the file\u2019s relevant timestamp shall not be changed. In either case, the <i>tv_sec<\/i> field shall be ignored.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">If the <i>times<\/i> 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 <i>utimensat<\/i>() is passed a relative path in the <i>path<\/i> argument, the file to be used shall be relative to the directory associated with the file descriptor <i>fd<\/i> 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.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">If <i>utimensat<\/i>() is passed the special value AT_FDCWD in the <i>fd<\/i> parameter, the current working directory shall be used.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">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 <i>futimens<\/i>() or <i>utimensat<\/i>() with a null pointer as the <i>times<\/i> argument or with both <i>tv_nsec<\/i> 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 <i>futimens<\/i>() or <i>utimensat<\/i>() with a non-null <i>times<\/i> argument that does not have both <i>tv_nsec<\/i> fields set to UTIME_NOW and does not have both <i>tv_nsec<\/i> fields set to UTIME_OMIT. If both <i>tv_nsec<\/i> 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 <b>[EACCES]<\/b> errors related to the path prefix).<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Values for the <i>flag<\/i> argument of <i>utimensat<\/i>() are constructed by a bitwise-inclusive OR of flags from the following list, defined in <i><fcntl.h><\/i>: <br \/> AT_SYMLINK_NOFOLLOW<\/p>\n<p style=\"margin-left:20%;\">If <i>path<\/i> names a symbolic link, then the access and modification times of the symbolic link are changed.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Upon successful completion, <i>futimens<\/i>() and <i>utimensat<\/i>() shall mark the last file status change timestamp for update, with the exception that if both <i>tv_nsec<\/i> fields are set to UTIME_OMIT, the file status change timestamp need not be marked for update.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The <i>utimes<\/i>() function shall be equivalent to the <i>utimensat<\/i>() function with the special value AT_FDCWD as the <i>fd<\/i> argument and the <i>flag<\/i> argument set to zero, except that the <i>times<\/i> argument is a <b>timeval<\/b> structure rather than a <b>timespec<\/b> structure, and accuracy is only to the microsecond, not nanosecond, and rounding towards the nearest second may occur.<\/p>\n<h2>RETURN VALUE <a name=\"RETURN VALUE\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">Upon successful completion, these functions shall return 0. Otherwise, these functions shall return \u22121 and set <i>errno<\/i> to indicate the error. If \u22121 is returned, the file times shall not be affected.<\/p>\n<h2>ERRORS <a name=\"ERRORS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">These functions shall fail if:<\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"9%\">\n<p><b>EACCES<\/b><\/p>\n<\/td>\n<td width=\"2%\"><\/td>\n<td width=\"78%\">\n<p>The <i>times<\/i> argument is a null pointer, or both <i>tv_nsec<\/i> 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.<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"9%\">\n<p><b>EINVAL<\/b><\/p>\n<\/td>\n<td width=\"2%\"><\/td>\n<td width=\"78%\">\n<p>Either of the <i>times<\/i> argument structures specified a <i>tv_nsec<\/i> value that was neither UTIME_NOW nor UTIME_OMIT, and was a value less than zero or greater than or equal to 1000 million.<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"9%\">\n<p><b>EINVAL<\/b><\/p>\n<\/td>\n<td width=\"2%\"><\/td>\n<td width=\"78%\">\n<p>A new file timestamp would be a value whose <i>tv_sec<\/i> component is not a value supported by the file system.<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"9%\">\n<p><b>EPERM<\/b><\/p>\n<\/td>\n<td width=\"2%\"><\/td>\n<td width=\"78%\">\n<p>The <i>times<\/i> argument is not a null pointer, does not have both <i>tv_nsec<\/i> fields set to UTIME_NOW, does not have both <i>tv_nsec<\/i> fields set to UTIME_OMIT, the calling process\u2019 effective user ID does not match the owner of the file, and the calling process does not have appropriate privileges.<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"9%\">\n<p><b>EROFS<\/b><\/p>\n<\/td>\n<td width=\"2%\"><\/td>\n<td width=\"78%\">\n<p>The file system containing the file is read-only.<\/p>\n<\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:11%; margin-top: 1em\">The <i>futimens<\/i>() function shall fail if:<\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"7%\">\n<p style=\"margin-top: 1em\"><b>EBADF<\/b><\/p>\n<\/td>\n<td width=\"4%\"><\/td>\n<td width=\"72%\">\n<p style=\"margin-top: 1em\">The <i>fd<\/i> argument is not a valid file descriptor.<\/p>\n<\/td>\n<td width=\"6%\"> <\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:11%; margin-top: 1em\">The <i>utimensat<\/i>() function shall fail if:<\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"9%\">\n<p style=\"margin-top: 1em\"><b>EACCES<\/b><\/p>\n<\/td>\n<td width=\"2%\"><\/td>\n<td width=\"78%\">\n<p style=\"margin-top: 1em\">The access mode of the open file description associated with <i>fd<\/i> is not O_SEARCH and the permissions of the directory underlying <i>fd<\/i> do not permit directory searches.<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"9%\">\n<p><b>EBADF<\/b><\/p>\n<\/td>\n<td width=\"2%\"><\/td>\n<td width=\"78%\">\n<p>The <i>path<\/i> argument does not specify an absolute path and the <i>fd<\/i> argument is neither AT_FDCWD nor a valid file descriptor open for reading or searching.<\/p>\n<\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:11%;\"><b>ENOTDIR<\/b><\/p>\n<p style=\"margin-left:22%;\">The <i>path<\/i> argument is not an absolute path and <i>fd<\/i> is a file descriptor associated with a non-directory file.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The <i>utimensat<\/i>() and <i>utimes<\/i>() functions shall fail if:<\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"9%\">\n<p><b>EACCES<\/b><\/p>\n<\/td>\n<td width=\"2%\"><\/td>\n<td width=\"78%\">\n<p>Search permission is denied by a component of the path prefix.<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"9%\">\n<p><b>ELOOP<\/b><\/p>\n<\/td>\n<td width=\"2%\"><\/td>\n<td width=\"78%\">\n<p>A loop exists in symbolic links encountered during resolution of the <i>path<\/i> argument.<\/p>\n<\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:11%;\"><b>ENAMETOOLONG<\/b><\/p>\n<p style=\"margin-left:22%;\">The length of a component of a pathname is longer than {NAME_MAX}.<\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"9%\">\n<p><b>ENOENT<\/b><\/p>\n<\/td>\n<td width=\"2%\"><\/td>\n<td width=\"78%\">\n<p>A component of <i>path<\/i> does not name an existing file or <i>path<\/i> is an empty string.<\/p>\n<\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:11%;\"><b>ENOTDIR<\/b><\/p>\n<p style=\"margin-left:22%;\">A component of the path prefix names an existing file that is neither a directory nor a symbolic link to a directory, or the <i>path<\/i> 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.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The <i>utimensat<\/i>() and <i>utimes<\/i>() functions may fail if:<\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"7%\">\n<p><b>ELOOP<\/b><\/p>\n<\/td>\n<td width=\"4%\"><\/td>\n<td width=\"78%\">\n<p>More than {SYMLOOP_MAX} symbolic links were encountered during resolution of the <i>path<\/i> argument.<\/p>\n<\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:11%;\"><b>ENAMETOOLONG<\/b><\/p>\n<p style=\"margin-left:22%;\">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}.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The <i>utimensat<\/i>() function may fail if:<\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"9%\">\n<p><b>EINVAL<\/b><\/p>\n<\/td>\n<td width=\"2%\"><\/td>\n<td width=\"67%\">\n<p>The value of the <i>flag<\/i> argument is not valid.<\/p>\n<\/td>\n<td width=\"11%\"> <\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:11%; margin-top: 1em\"><i>The following sections are informative.<\/i><\/p>\n<h2>EXAMPLES <a name=\"EXAMPLES\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">None.<\/p>\n<h2>APPLICATION USAGE <a name=\"APPLICATION USAGE\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">None.<\/p>\n<h2>RATIONALE <a name=\"RATIONALE\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">The purpose of the <i>utimensat<\/i>() 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 <i>utimes<\/i>(), resulting in unspecified behavior. By opening a file descriptor for the target directory and using the <i>utimensat<\/i>() function it can be guaranteed that the changed file is located relative to the desired directory.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The standard developers considered including a special case for the permissions required by <i>utimensat<\/i>() when one <i>tv_nsec<\/i> field is UTIME_NOW and the other is UTIME_OMIT. One possibility would be to include this case in with the cases where <i>times<\/i> 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 <i>read<\/i>()) 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 <i>utime<\/i>() and <i>utimes<\/i>() functions on which <i>utimensat<\/i>() 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.<\/p>\n<h2>FUTURE DIRECTIONS <a name=\"FUTURE DIRECTIONS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">None.<\/p>\n<h2>SEE ALSO <a name=\"SEE ALSO\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\"><i>read<\/i>(), <i>utime<\/i>()<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The Base Definitions volume of POSIX.1-2017, <b><fcntl.h><\/b>, <b><sys_stat.h><\/b>, <b><sys_time.h><\/b><\/p>\n<h2>COPYRIGHT <a name=\"COPYRIGHT\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology &#8212; 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 at http:\/\/www.opengroup.org\/unix\/online.html .<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">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, see https:\/\/www.kernel.org\/doc\/man-pages\/reporting_bugs.html .<\/p>\n<hr>\n","protected":false},"excerpt":{"rendered":"<p>  futimens, utimensat, utimes \u2014 set file access and modification times <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3779,1],"tags":[1855,1594],"class_list":["post-4961","post","type-post","status-publish","format-standard","hentry","category-3pm-perl-llamadas-de-bibliotecas","category-sin-categoria","tag-futimens","tag-man3p"],"gutentor_comment":0,"_links":{"self":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/4961","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/comments?post=4961"}],"version-history":[{"count":0,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/4961\/revisions"}],"wp:attachment":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/media?parent=4961"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/categories?post=4961"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/tags?post=4961"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}