1.\" $NetBSD: utimes.2,v 1.23 2008/06/17 17:46:40 christos Exp $ 2.\" 3.\" Copyright (c) 1990, 1993 4.\" The Regents of the University of California. All rights reserved. 5.\" 6.\" Redistribution and use in source and binary forms, with or without 7.\" modification, are permitted provided that the following conditions 8.\" are met: 9.\" 1. Redistributions of source code must retain the above copyright 10.\" notice, this list of conditions and the following disclaimer. 11.\" 2. Redistributions in binary form must reproduce the above copyright 12.\" notice, this list of conditions and the following disclaimer in the 13.\" documentation and/or other materials provided with the distribution. 14.\" 3. Neither the name of the University nor the names of its contributors 15.\" may be used to endorse or promote products derived from this software 16.\" without specific prior written permission. 17.\" 18.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 19.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 22.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28.\" SUCH DAMAGE. 29.\" 30.\" @(#)utimes.2 8.1 (Berkeley) 6/4/93 31.\" 32.Dd June 17, 2008 33.Dt UTIMES 2 34.Os 35.Sh NAME 36.Nm utimes , 37.Nm lutimes , 38.Nm futimes 39.Nd set file access and modification times 40.Sh LIBRARY 41.Lb libc 42.Sh SYNOPSIS 43.In sys/time.h 44.Ft int 45.Fn utimes "const char *path" "const struct timeval times[2]" 46.Ft int 47.Fn lutimes "const char *path" "const struct timeval times[2]" 48.Ft int 49.Fn futimes "int fd" "const struct timeval times[2]" 50.Sh DESCRIPTION 51The access and modification times of the file named by 52.Fa path 53or referenced by 54.Fa fd 55are changed as specified by the argument 56.Fa times . 57.Pp 58If 59.Fa times 60is 61.Dv NULL , 62the access and modification times are set to the current time. 63The caller must be the owner of the file, have permission to 64write the file, or be the super-user. 65.Pp 66If 67.Fa times 68is 69.Pf non- Dv NULL , 70it is assumed to point to an array of two timeval structures. 71The access time is set to the value of the first element, and the 72modification time is set to the value of the second element. 73For file systems that support file birth (creation) times (such as 74UFS2), the birth time will be set to the value of the second element 75if the second element is older than the currently set birth time. 76To set both a birth time and a modification time, two calls are 77required; the first to set the birth time and the second to set 78the (presumably newer) modification time. 79Ideally a new system call will be added that allows the setting of 80all three times at once. 81The caller must be the owner of the file or be the super-user. 82.Pp 83In either case, the inode-change-time of the file is set to the current 84time. 85.Pp 86.Fn lutimes 87is like 88.Fn utimes 89except in the case where the named file is a symbolic link, 90in which case 91.Fn lutimes 92changes the access and modification times of the link, 93while 94.Fn utimes 95changes the times of the file the link references. 96.Sh RETURN VALUES 97Upon successful completion, a value of 0 is returned. 98Otherwise, a value of \-1 is returned and 99.Va errno 100is set to indicate the error. 101.Sh ERRORS 102.Fn utimes 103and 104.Fn lutimes 105will fail if: 106.Bl -tag -width Er 107.It Bq Er EACCES 108Search permission is denied for a component of the path prefix; 109or the 110.Fa times 111argument is 112.Dv NULL 113and the effective user ID of the process does not 114match the owner of the file, and is not the super-user, and write 115access is denied. 116.It Bq Er EFAULT 117.Fa path 118or 119.Fa times 120points outside the process's allocated address space. 121.It Bq Er EIO 122An I/O error occurred while reading or writing the affected inode. 123.It Bq Er ELOOP 124Too many symbolic links were encountered in translating the pathname. 125.It Bq Er ENAMETOOLONG 126A component of a pathname exceeded 127.Dv {NAME_MAX} 128characters, or an entire path name exceeded 129.Dv {PATH_MAX} 130characters. 131.It Bq Er ENOENT 132The named file does not exist. 133.It Bq Er ENOTDIR 134A component of the path prefix is not a directory. 135.It Bq Er EPERM 136The 137.Fa times 138argument is not 139.Dv NULL 140and the calling process's effective user ID 141does not match the owner of the file and is not the super-user. 142.It Bq Er EROFS 143The file system containing the file is mounted read-only. 144.El 145.Pp 146.Fn futimes 147will fail if: 148.Bl -tag -width Er 149.It Bq Er EBADF 150.Fa fd 151does not refer to a valid descriptor. 152.It Bq Er EACCES 153The 154.Fa times 155argument is 156.Dv NULL 157and the effective user ID of the process does not 158match the owner of the file, and is not the super-user, and write 159access is denied. 160.It Bq Er EFAULT 161.Fa times 162points outside the process's allocated address space. 163.It Bq Er EIO 164An I/O error occurred while reading or writing the affected inode. 165.It Bq Er EPERM 166The 167.Fa times 168argument is not 169.Dv NULL 170and the calling process's effective user ID 171does not match the owner of the file and is not the super-user. 172.It Bq Er EROFS 173The file system containing the file is mounted read-only. 174.El 175.Sh SEE ALSO 176.Xr stat 2 , 177.Xr utime 3 , 178.Xr symlink 7 179.Sh HISTORY 180The 181.Fn utimes 182function call appeared in 183.Bx 4.2 . 184The 185.Fn futimes 186function call appeared in 187.Nx 1.2 . 188The 189.Fn lutimes 190function call appeared in 191.Nx 1.3 . 192Birthtime setting support was added in 193.Nx 5.0 . 194