Edit

kc3-lang/gnulib/lib/settime.c

Branch :

  • Show log

    Commit

  • Author : Eric Blake
    Date : 2009-09-02 17:06:43
    Hash : 9de26050
    Message : errno: use consistently * lib/c-stack.c (ENOTSUP): <errno.h> guarantees a definition. * lib/canonicalize-lgpl.c (ENAMETOOLONG): Likewise. * lib/canonicalize.c (ELOOP): Likewise. * lib/inet_ntop.c (EAFNOSUPPORT): Likewise. * lib/inet_pton.c (EAFNOSUPPORT): Likewise. * lib/lchown.c (EOPNOTSUPP): Likewise. * lib/openat-priv.h (ENOSYS, EOPNOTSUPP): Likewise. * lib/savewd.c (ESTALE): Likewise. * lib/settime.c (ENOSYS): Likewise. * lib/utimens.c (ENOSYS): Likewise. * lib/xgethostname.c (ENAMETOOLONG): Likewise. * lib/chdir-safer.c (ELOOP): Likewise. (chdir_no_follow): Use HAVE_READLINK, not ELOOP, as witness. * modules/c-stack (Depends-on): Add errno. * modules/canonicalize (Depends-on): Likewise. * modules/chdir-safer (Depends-on): Likewise. * modules/fdopendir (Depends-on): Likewise. * modules/inet_ntop (Depends-on): Likewise. * modules/inet_pton (Depends-on): Likewise. * modules/lchown (Depends-on): Likewise. * modules/openat (Depends-on): Likewise. * modules/savewd (Depends-on): Likewise. * modules/settime (Depends-on): Likewise. * m4/chdir-safer.m4 (gl_CHDIR_SAFER): Check for readlink. Signed-off-by: Eric Blake <ebb9@byu.net>

  • lib/settime.c
  • /* settime -- set the system clock
    
       Copyright (C) 2002, 2004, 2005, 2006, 2007, 2009 Free Software
       Foundation, Inc.
    
       This program is free software: you can redistribute it and/or modify
       it under the terms of the GNU General Public License as published by
       the Free Software Foundation; either version 3 of the License, or
       (at your option) any later version.
    
       This program is distributed in the hope that it will be useful,
       but WITHOUT ANY WARRANTY; without even the implied warranty of
       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       GNU General Public License for more details.
    
       You should have received a copy of the GNU General Public License
       along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
    
    /* Written by Paul Eggert.  */
    
    #include <config.h>
    
    #include "timespec.h"
    
    #include <sys/time.h>
    #include <unistd.h>
    
    #include <errno.h>
    
    /* Set the system time.  */
    
    int
    settime (struct timespec const *ts)
    {
    #if defined CLOCK_REALTIME && HAVE_CLOCK_SETTIME
      {
        int r = clock_settime (CLOCK_REALTIME, ts);
        if (r == 0 || errno == EPERM)
          return r;
      }
    #endif
    
    #if HAVE_SETTIMEOFDAY
      {
        struct timeval tv;
    
        tv.tv_sec = ts->tv_sec;
        tv.tv_usec = ts->tv_nsec / 1000;
        return settimeofday (&tv, 0);
      }
    #elif HAVE_STIME
      /* This fails to compile on OSF1 V5.1, due to stime requiring
         a `long int*' and tv_sec is `int'.  But that system does provide
         settimeofday.  */
      return stime (&ts->tv_sec);
    #else
      errno = ENOSYS;
      return -1;
    #endif
    }