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

Split Close
Expand all
Collapse all
          --- old/usr/src/lib/libc/port/sys/utimesys.c
          +++ new/usr/src/lib/libc/port/sys/utimesys.c
↓ open down ↓ 16 lines elided ↑ open up ↑
  17   17   * information: Portions Copyright [yyyy] [name of copyright owner]
  18   18   *
  19   19   * CDDL HEADER END
  20   20   */
  21   21  
  22   22  /*
  23   23   * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  24   24   * Use is subject to license terms.
  25   25   */
  26   26  
       27 +/*
       28 + * Copyright 2020 OmniOS Community Edition (OmniOSce) Association.
       29 + */
       30 +
  27   31  #include "lint.h"
  28   32  #include <string.h>
  29   33  #include <utime.h>
  30   34  #include <fcntl.h>
  31   35  #include <sys/stat.h>
  32   36  #include <sys/time.h>
  33   37  #include <sys/syscall.h>
  34   38  
  35   39  int
  36   40  futimens(int fd, const timespec_t times[2])
↓ open down ↓ 23 lines elided ↑ open up ↑
  60   64                          return (-1);    /* uucopy() set errno to EFAULT */
  61   65                  ts[0].tv_sec = ltimes.actime;
  62   66                  ts[0].tv_nsec = 0;
  63   67                  ts[1].tv_sec = ltimes.modtime;
  64   68                  ts[1].tv_nsec = 0;
  65   69                  tsp = ts;
  66   70          }
  67   71          return (utimensat(AT_FDCWD, path, tsp, 0));
  68   72  }
  69   73  
  70      -int
  71      -utimes(const char *path, const struct timeval times[2])
       74 +static int
       75 +utimes_impl(const char *path, const struct timeval times[2], int flag)
  72   76  {
  73   77          struct timeval ltimes[2];
  74   78          timespec_t ts[2];
  75   79          timespec_t *tsp;
  76   80  
  77   81          if (times == NULL) {
  78   82                  tsp = NULL;
  79   83          } else {
  80   84                  /* use uucopy() to behave like a system call */
  81   85                  if (uucopy(times, ltimes, sizeof (ltimes)) != 0)
  82   86                          return (-1);    /* uucopy() set errno to EFAULT */
  83   87                  ts[0].tv_sec = ltimes[0].tv_sec;
  84   88                  ts[0].tv_nsec = ltimes[0].tv_usec * 1000;
  85   89                  ts[1].tv_sec = ltimes[1].tv_sec;
  86   90                  ts[1].tv_nsec = ltimes[1].tv_usec * 1000;
  87   91                  tsp = ts;
  88   92          }
  89      -        return (utimensat(AT_FDCWD, path, tsp, 0));
       93 +        return (utimensat(AT_FDCWD, path, tsp, flag));
  90   94  }
  91   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 +
  92  108  #pragma weak _futimesat = futimesat
  93  109  int
  94  110  futimesat(int fd, const char *path, const struct timeval times[2])
  95  111  {
  96  112          struct timeval ltimes[2];
  97  113          timespec_t ts[2];
  98  114          timespec_t *tsp;
  99  115  
 100  116          if (times == NULL) {
 101  117                  tsp = NULL;
↓ open down ↓ 5 lines elided ↑ open up ↑
 107  123                  ts[0].tv_nsec = ltimes[0].tv_usec * 1000;
 108  124                  ts[1].tv_sec = ltimes[1].tv_sec;
 109  125                  ts[1].tv_nsec = ltimes[1].tv_usec * 1000;
 110  126                  tsp = ts;
 111  127          }
 112  128  
 113  129          if (path == NULL)
 114  130                  return (futimens(fd, tsp));
 115  131  
 116  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));
 117  139  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX