Print this page
13111 Want futimes() and lutimes() functions
Change-ID: I3be82d4242255a4100f8c35db373eb9140402fc4


   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.
  25  */
  26 




  27 #include "lint.h"
  28 #include <string.h>
  29 #include <utime.h>
  30 #include <fcntl.h>
  31 #include <sys/stat.h>
  32 #include <sys/time.h>
  33 #include <sys/syscall.h>
  34 
  35 int
  36 futimens(int fd, const timespec_t times[2])
  37 {
  38         return (syscall(SYS_utimesys, 0, fd, times));
  39 }
  40 
  41 int
  42 utimensat(int fd, const char *path, const timespec_t times[2], int flag)
  43 {
  44         return (syscall(SYS_utimesys, 1, fd, path, times, flag));
  45 }
  46 


  50 {
  51         struct utimbuf ltimes;
  52         timespec_t ts[2];
  53         timespec_t *tsp;
  54 
  55         if (times == NULL) {
  56                 tsp = NULL;
  57         } else {
  58                 /* use uucopy() to behave like a system call */
  59                 if (uucopy(times, &ltimes, sizeof (ltimes)) != 0)
  60                         return (-1);    /* uucopy() set errno to EFAULT */
  61                 ts[0].tv_sec = ltimes.actime;
  62                 ts[0].tv_nsec = 0;
  63                 ts[1].tv_sec = ltimes.modtime;
  64                 ts[1].tv_nsec = 0;
  65                 tsp = ts;
  66         }
  67         return (utimensat(AT_FDCWD, path, tsp, 0));
  68 }
  69 
  70 int
  71 utimes(const char *path, const struct timeval times[2])
  72 {
  73         struct timeval ltimes[2];
  74         timespec_t ts[2];
  75         timespec_t *tsp;
  76 
  77         if (times == NULL) {
  78                 tsp = NULL;
  79         } else {
  80                 /* use uucopy() to behave like a system call */
  81                 if (uucopy(times, ltimes, sizeof (ltimes)) != 0)
  82                         return (-1);    /* uucopy() set errno to EFAULT */
  83                 ts[0].tv_sec = ltimes[0].tv_sec;
  84                 ts[0].tv_nsec = ltimes[0].tv_usec * 1000;
  85                 ts[1].tv_sec = ltimes[1].tv_sec;
  86                 ts[1].tv_nsec = ltimes[1].tv_usec * 1000;
  87                 tsp = ts;
  88         }
  89         return (utimensat(AT_FDCWD, path, tsp, 0));
  90 }
  91 












  92 #pragma weak _futimesat = futimesat
  93 int
  94 futimesat(int fd, const char *path, const struct timeval times[2])
  95 {
  96         struct timeval ltimes[2];
  97         timespec_t ts[2];
  98         timespec_t *tsp;
  99 
 100         if (times == NULL) {
 101                 tsp = NULL;
 102         } else {
 103                 /* use uucopy() to behave like a system call */
 104                 if (uucopy(times, ltimes, sizeof (ltimes)) != 0)
 105                         return (-1);    /* uucopy() set errno to EFAULT */
 106                 ts[0].tv_sec = ltimes[0].tv_sec;
 107                 ts[0].tv_nsec = ltimes[0].tv_usec * 1000;
 108                 ts[1].tv_sec = ltimes[1].tv_sec;
 109                 ts[1].tv_nsec = ltimes[1].tv_usec * 1000;
 110                 tsp = ts;
 111         }
 112 
 113         if (path == NULL)
 114                 return (futimens(fd, tsp));
 115 
 116         return (utimensat(fd, path, tsp, 0));






 117 }


   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.
  25  */
  26 
  27 /*
  28  * Copyright 2020 OmniOS Community Edition (OmniOSce) Association.
  29  */
  30 
  31 #include "lint.h"
  32 #include <string.h>
  33 #include <utime.h>
  34 #include <fcntl.h>
  35 #include <sys/stat.h>
  36 #include <sys/time.h>
  37 #include <sys/syscall.h>
  38 
  39 int
  40 futimens(int fd, const timespec_t times[2])
  41 {
  42         return (syscall(SYS_utimesys, 0, fd, times));
  43 }
  44 
  45 int
  46 utimensat(int fd, const char *path, const timespec_t times[2], int flag)
  47 {
  48         return (syscall(SYS_utimesys, 1, fd, path, times, flag));
  49 }
  50 


  54 {
  55         struct utimbuf ltimes;
  56         timespec_t ts[2];
  57         timespec_t *tsp;
  58 
  59         if (times == NULL) {
  60                 tsp = NULL;
  61         } else {
  62                 /* use uucopy() to behave like a system call */
  63                 if (uucopy(times, &ltimes, sizeof (ltimes)) != 0)
  64                         return (-1);    /* uucopy() set errno to EFAULT */
  65                 ts[0].tv_sec = ltimes.actime;
  66                 ts[0].tv_nsec = 0;
  67                 ts[1].tv_sec = ltimes.modtime;
  68                 ts[1].tv_nsec = 0;
  69                 tsp = ts;
  70         }
  71         return (utimensat(AT_FDCWD, path, tsp, 0));
  72 }
  73 
  74 static int
  75 utimes_impl(const char *path, const struct timeval times[2], int flag)
  76 {
  77         struct timeval ltimes[2];
  78         timespec_t ts[2];
  79         timespec_t *tsp;
  80 
  81         if (times == NULL) {
  82                 tsp = NULL;
  83         } else {
  84                 /* use uucopy() to behave like a system call */
  85                 if (uucopy(times, ltimes, sizeof (ltimes)) != 0)
  86                         return (-1);    /* uucopy() set errno to EFAULT */
  87                 ts[0].tv_sec = ltimes[0].tv_sec;
  88                 ts[0].tv_nsec = ltimes[0].tv_usec * 1000;
  89                 ts[1].tv_sec = ltimes[1].tv_sec;
  90                 ts[1].tv_nsec = ltimes[1].tv_usec * 1000;
  91                 tsp = ts;
  92         }
  93         return (utimensat(AT_FDCWD, path, tsp, flag));
  94 }
  95 
  96 int
  97 utimes(const char *path, const struct timeval times[2])
  98 {
  99         return (utimes_impl(path, times, 0));
 100 }
 101 
 102 int
 103 lutimes(const char *path, const struct timeval times[2])
 104 {
 105         return (utimes_impl(path, times, AT_SYMLINK_NOFOLLOW));
 106 }
 107 
 108 #pragma weak _futimesat = futimesat
 109 int
 110 futimesat(int fd, const char *path, const struct timeval times[2])
 111 {
 112         struct timeval ltimes[2];
 113         timespec_t ts[2];
 114         timespec_t *tsp;
 115 
 116         if (times == NULL) {
 117                 tsp = NULL;
 118         } else {
 119                 /* use uucopy() to behave like a system call */
 120                 if (uucopy(times, ltimes, sizeof (ltimes)) != 0)
 121                         return (-1);    /* uucopy() set errno to EFAULT */
 122                 ts[0].tv_sec = ltimes[0].tv_sec;
 123                 ts[0].tv_nsec = ltimes[0].tv_usec * 1000;
 124                 ts[1].tv_sec = ltimes[1].tv_sec;
 125                 ts[1].tv_nsec = ltimes[1].tv_usec * 1000;
 126                 tsp = ts;
 127         }
 128 
 129         if (path == NULL)
 130                 return (futimens(fd, tsp));
 131 
 132         return (utimensat(fd, path, tsp, 0));
 133 }
 134 
 135 int
 136 futimes(int fd, const struct timeval times[2])
 137 {
 138         return (futimesat(fd, NULL, times));
 139 }