Skip to content

Commit

Permalink
Add compat for utimensat(2) for touch builtin.
Browse files Browse the repository at this point in the history
This is taken from FreeBSD head r301763 at tools/build/utimensat.c
  • Loading branch information
bdrewery committed Mar 8, 2017
1 parent 1e799ff commit f9b13a5
Show file tree
Hide file tree
Showing 9 changed files with 169 additions and 21 deletions.
3 changes: 2 additions & 1 deletion Makefile.am
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ sh_CFLAGS= -DSHELL -DNO_HISTORY \
-I$(top_srcdir)/src \ -I$(top_srcdir)/src \
-I$(top_srcdir)/external/sh -I$(top_srcdir)/external/sh
sh_LDADD= sh_LDADD=
sh_SOURCES= external/sh_compat/compat.c \ sh_SOURCES= external/sh_compat/strchrnul.c \
external/sh_compat/utimensat.c \
external/sh/alias.c \ external/sh/alias.c \
external/sh/arith_yacc.c \ external/sh/arith_yacc.c \
external/sh/arith_yylex.c \ external/sh/arith_yylex.c \
Expand Down
48 changes: 34 additions & 14 deletions Makefile.in
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -222,7 +222,8 @@ rexec_LINK = $(CCLD) $(rexec_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \
am_rm_OBJECTS = src/libexec/poudriere/rm/rm.$(OBJEXT) am_rm_OBJECTS = src/libexec/poudriere/rm/rm.$(OBJEXT)
rm_OBJECTS = $(am_rm_OBJECTS) rm_OBJECTS = $(am_rm_OBJECTS)
rm_LDADD = $(LDADD) rm_LDADD = $(LDADD)
am_sh_OBJECTS = external/sh_compat/sh-compat.$(OBJEXT) \ am_sh_OBJECTS = external/sh_compat/sh-strchrnul.$(OBJEXT) \
external/sh_compat/sh-utimensat.$(OBJEXT) \
external/sh/sh-alias.$(OBJEXT) \ external/sh/sh-alias.$(OBJEXT) \
external/sh/sh-arith_yacc.$(OBJEXT) \ external/sh/sh-arith_yacc.$(OBJEXT) \
external/sh/sh-arith_yylex.$(OBJEXT) \ external/sh/sh-arith_yylex.$(OBJEXT) \
Expand Down Expand Up @@ -629,7 +630,8 @@ sh_CFLAGS = -DSHELL -DNO_HISTORY -include \
-I$(top_srcdir)/external/sh -I$(top_srcdir)/src/poudriere-sh -I$(top_srcdir)/external/sh -I$(top_srcdir)/src/poudriere-sh
# cachec # cachec
sh_LDADD = -lrt sh_LDADD = -lrt
sh_SOURCES = external/sh_compat/compat.c external/sh/alias.c \ sh_SOURCES = external/sh_compat/strchrnul.c \
external/sh_compat/utimensat.c external/sh/alias.c \
external/sh/arith_yacc.c external/sh/arith_yylex.c \ external/sh/arith_yacc.c external/sh/arith_yylex.c \
external/sh/bltin/echo.c external/sh/builtins.c \ external/sh/bltin/echo.c external/sh/builtins.c \
external/sh/cd.c external/sh/error.c external/sh/eval.c \ external/sh/cd.c external/sh/error.c external/sh/eval.c \
Expand Down Expand Up @@ -1094,7 +1096,10 @@ external/sh_compat/$(am__dirstamp):
external/sh_compat/$(DEPDIR)/$(am__dirstamp): external/sh_compat/$(DEPDIR)/$(am__dirstamp):
@$(MKDIR_P) external/sh_compat/$(DEPDIR) @$(MKDIR_P) external/sh_compat/$(DEPDIR)
@: > external/sh_compat/$(DEPDIR)/$(am__dirstamp) @: > external/sh_compat/$(DEPDIR)/$(am__dirstamp)
external/sh_compat/sh-compat.$(OBJEXT): \ external/sh_compat/sh-strchrnul.$(OBJEXT): \
external/sh_compat/$(am__dirstamp) \
external/sh_compat/$(DEPDIR)/$(am__dirstamp)
external/sh_compat/sh-utimensat.$(OBJEXT): \
external/sh_compat/$(am__dirstamp) \ external/sh_compat/$(am__dirstamp) \
external/sh_compat/$(DEPDIR)/$(am__dirstamp) external/sh_compat/$(DEPDIR)/$(am__dirstamp)
external/sh/$(am__dirstamp): external/sh/$(am__dirstamp):
Expand Down Expand Up @@ -1404,7 +1409,8 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@external/sh/$(DEPDIR)/sh-trap.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@external/sh/$(DEPDIR)/sh-trap.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@external/sh/$(DEPDIR)/sh-var.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@external/sh/$(DEPDIR)/sh-var.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@external/sh/bltin/$(DEPDIR)/sh-echo.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@external/sh/bltin/$(DEPDIR)/sh-echo.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@external/sh_compat/$(DEPDIR)/sh-compat.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@external/sh_compat/$(DEPDIR)/sh-strchrnul.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@external/sh_compat/$(DEPDIR)/sh-utimensat.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@src/libexec/poudriere/cachec/$(DEPDIR)/cachec.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@src/libexec/poudriere/cachec/$(DEPDIR)/cachec.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@src/libexec/poudriere/cachec/$(DEPDIR)/sh-cachec.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@src/libexec/poudriere/cachec/$(DEPDIR)/sh-cachec.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@src/libexec/poudriere/cached/$(DEPDIR)/cached-cached.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@src/libexec/poudriere/cached/$(DEPDIR)/cached-cached.Po@am__quote@
Expand Down Expand Up @@ -1766,19 +1772,33 @@ src/libexec/poudriere/rexec/rexec-rexec.obj: src/libexec/poudriere/rexec/rexec.c
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(rexec_CFLAGS) $(CFLAGS) -c -o src/libexec/poudriere/rexec/rexec-rexec.obj `if test -f 'src/libexec/poudriere/rexec/rexec.c'; then $(CYGPATH_W) 'src/libexec/poudriere/rexec/rexec.c'; else $(CYGPATH_W) '$(srcdir)/src/libexec/poudriere/rexec/rexec.c'; fi` @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(rexec_CFLAGS) $(CFLAGS) -c -o src/libexec/poudriere/rexec/rexec-rexec.obj `if test -f 'src/libexec/poudriere/rexec/rexec.c'; then $(CYGPATH_W) 'src/libexec/poudriere/rexec/rexec.c'; else $(CYGPATH_W) '$(srcdir)/src/libexec/poudriere/rexec/rexec.c'; fi`


external/sh_compat/sh-compat.o: external/sh_compat/compat.c external/sh_compat/sh-strchrnul.o: external/sh_compat/strchrnul.c
@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(sh_CFLAGS) $(CFLAGS) -MT external/sh_compat/sh-compat.o -MD -MP -MF external/sh_compat/$(DEPDIR)/sh-compat.Tpo -c -o external/sh_compat/sh-compat.o `test -f 'external/sh_compat/compat.c' || echo '$(srcdir)/'`external/sh_compat/compat.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(sh_CFLAGS) $(CFLAGS) -MT external/sh_compat/sh-strchrnul.o -MD -MP -MF external/sh_compat/$(DEPDIR)/sh-strchrnul.Tpo -c -o external/sh_compat/sh-strchrnul.o `test -f 'external/sh_compat/strchrnul.c' || echo '$(srcdir)/'`external/sh_compat/strchrnul.c
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) external/sh_compat/$(DEPDIR)/sh-compat.Tpo external/sh_compat/$(DEPDIR)/sh-compat.Po @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) external/sh_compat/$(DEPDIR)/sh-strchrnul.Tpo external/sh_compat/$(DEPDIR)/sh-strchrnul.Po
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='external/sh_compat/compat.c' object='external/sh_compat/sh-compat.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='external/sh_compat/strchrnul.c' object='external/sh_compat/sh-strchrnul.o' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(sh_CFLAGS) $(CFLAGS) -c -o external/sh_compat/sh-strchrnul.o `test -f 'external/sh_compat/strchrnul.c' || echo '$(srcdir)/'`external/sh_compat/strchrnul.c

external/sh_compat/sh-strchrnul.obj: external/sh_compat/strchrnul.c
@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(sh_CFLAGS) $(CFLAGS) -MT external/sh_compat/sh-strchrnul.obj -MD -MP -MF external/sh_compat/$(DEPDIR)/sh-strchrnul.Tpo -c -o external/sh_compat/sh-strchrnul.obj `if test -f 'external/sh_compat/strchrnul.c'; then $(CYGPATH_W) 'external/sh_compat/strchrnul.c'; else $(CYGPATH_W) '$(srcdir)/external/sh_compat/strchrnul.c'; fi`
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) external/sh_compat/$(DEPDIR)/sh-strchrnul.Tpo external/sh_compat/$(DEPDIR)/sh-strchrnul.Po
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='external/sh_compat/strchrnul.c' object='external/sh_compat/sh-strchrnul.obj' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(sh_CFLAGS) $(CFLAGS) -c -o external/sh_compat/sh-strchrnul.obj `if test -f 'external/sh_compat/strchrnul.c'; then $(CYGPATH_W) 'external/sh_compat/strchrnul.c'; else $(CYGPATH_W) '$(srcdir)/external/sh_compat/strchrnul.c'; fi`

external/sh_compat/sh-utimensat.o: external/sh_compat/utimensat.c
@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(sh_CFLAGS) $(CFLAGS) -MT external/sh_compat/sh-utimensat.o -MD -MP -MF external/sh_compat/$(DEPDIR)/sh-utimensat.Tpo -c -o external/sh_compat/sh-utimensat.o `test -f 'external/sh_compat/utimensat.c' || echo '$(srcdir)/'`external/sh_compat/utimensat.c
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) external/sh_compat/$(DEPDIR)/sh-utimensat.Tpo external/sh_compat/$(DEPDIR)/sh-utimensat.Po
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='external/sh_compat/utimensat.c' object='external/sh_compat/sh-utimensat.o' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(sh_CFLAGS) $(CFLAGS) -c -o external/sh_compat/sh-compat.o `test -f 'external/sh_compat/compat.c' || echo '$(srcdir)/'`external/sh_compat/compat.c @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(sh_CFLAGS) $(CFLAGS) -c -o external/sh_compat/sh-utimensat.o `test -f 'external/sh_compat/utimensat.c' || echo '$(srcdir)/'`external/sh_compat/utimensat.c


external/sh_compat/sh-compat.obj: external/sh_compat/compat.c external/sh_compat/sh-utimensat.obj: external/sh_compat/utimensat.c
@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(sh_CFLAGS) $(CFLAGS) -MT external/sh_compat/sh-compat.obj -MD -MP -MF external/sh_compat/$(DEPDIR)/sh-compat.Tpo -c -o external/sh_compat/sh-compat.obj `if test -f 'external/sh_compat/compat.c'; then $(CYGPATH_W) 'external/sh_compat/compat.c'; else $(CYGPATH_W) '$(srcdir)/external/sh_compat/compat.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(sh_CFLAGS) $(CFLAGS) -MT external/sh_compat/sh-utimensat.obj -MD -MP -MF external/sh_compat/$(DEPDIR)/sh-utimensat.Tpo -c -o external/sh_compat/sh-utimensat.obj `if test -f 'external/sh_compat/utimensat.c'; then $(CYGPATH_W) 'external/sh_compat/utimensat.c'; else $(CYGPATH_W) '$(srcdir)/external/sh_compat/utimensat.c'; fi`
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) external/sh_compat/$(DEPDIR)/sh-compat.Tpo external/sh_compat/$(DEPDIR)/sh-compat.Po @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) external/sh_compat/$(DEPDIR)/sh-utimensat.Tpo external/sh_compat/$(DEPDIR)/sh-utimensat.Po
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='external/sh_compat/compat.c' object='external/sh_compat/sh-compat.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='external/sh_compat/utimensat.c' object='external/sh_compat/sh-utimensat.obj' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(sh_CFLAGS) $(CFLAGS) -c -o external/sh_compat/sh-compat.obj `if test -f 'external/sh_compat/compat.c'; then $(CYGPATH_W) 'external/sh_compat/compat.c'; else $(CYGPATH_W) '$(srcdir)/external/sh_compat/compat.c'; fi` @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(sh_CFLAGS) $(CFLAGS) -c -o external/sh_compat/sh-utimensat.obj `if test -f 'external/sh_compat/utimensat.c'; then $(CYGPATH_W) 'external/sh_compat/utimensat.c'; else $(CYGPATH_W) '$(srcdir)/external/sh_compat/utimensat.c'; fi`


external/sh/sh-alias.o: external/sh/alias.c external/sh/sh-alias.o: external/sh/alias.c
@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(sh_CFLAGS) $(CFLAGS) -MT external/sh/sh-alias.o -MD -MP -MF external/sh/$(DEPDIR)/sh-alias.Tpo -c -o external/sh/sh-alias.o `test -f 'external/sh/alias.c' || echo '$(srcdir)/'`external/sh/alias.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(sh_CFLAGS) $(CFLAGS) -MT external/sh/sh-alias.o -MD -MP -MF external/sh/$(DEPDIR)/sh-alias.Tpo -c -o external/sh/sh-alias.o `test -f 'external/sh/alias.c' || echo '$(srcdir)/'`external/sh/alias.c
Expand Down
2 changes: 1 addition & 1 deletion configure
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -3743,7 +3743,7 @@ fi






for ac_func in strftime_l strchrnul for ac_func in strftime_l strchrnul utimensat
do : do :
as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var" ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
Expand Down
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ AM_MAINTAINER_MODE([disable])
AC_PROG_CC([cc clang gcc]) AC_PROG_CC([cc clang gcc])
AC_PROG_RANLIB AC_PROG_RANLIB


AC_CHECK_FUNCS([strftime_l strchrnul]) AC_CHECK_FUNCS([strftime_l strchrnul utimensat])


AC_CHECK_HEADERS_ONCE([sys/types.h]) AC_CHECK_HEADERS_ONCE([sys/types.h])
AC_CHECK_HEADERS_ONCE([sys/stat.h]) AC_CHECK_HEADERS_ONCE([sys/stat.h])
Expand Down
15 changes: 13 additions & 2 deletions external/sh_compat/compat.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -3,7 +3,18 @@


#include "config.h" #include "config.h"


#ifndef HAVE_UTIMENSAT
#include <sys/stat.h>
#endif /* !HAVE_UTIMENSAT */

#ifndef HAVE_STRCHRNUL #ifndef HAVE_STRCHRNUL
char *strchrnul(const char*, int); char *strchrnul(const char*, int);
#endif #endif /* !HAVE_STRCHRNUL */
#endif #ifndef HAVE_UTIMENSAT
#ifndef UTIME_NOW
#define UTIME_NOW -1
#define UTIME_OMIT -2
#endif /* !UTIME_NOW */
int utimensat(int, const char *, const struct timespec *, int);
#endif /* !HAVE_UTIMENSAT */
#endif /* !_SH_COMPAT_COMPAT_H */
File renamed without changes.
110 changes: 110 additions & 0 deletions external/sh_compat/utimensat.c
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,110 @@
/*-
* Copyright (c) 2015 Jilles Tjoelker
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/

#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");

#include <sys/stat.h>

#include <errno.h>
#include <fcntl.h>
#include <time.h>

#ifndef UTIME_NOW
#define UTIME_NOW -1
#define UTIME_OMIT -2
#endif

#ifndef HAVE_UTIMENSAT
int
utimensat(int fd, const char *path, const struct timespec times[2], int flag)
{
struct timeval now, tv[2], *tvp;
struct stat sb;
int osreldate;

if ((flag & ~AT_SYMLINK_NOFOLLOW) != 0) {
errno = EINVAL;
return (-1);
}
if (times == NULL || (times[0].tv_nsec == UTIME_NOW &&
times[1].tv_nsec == UTIME_NOW))
tvp = NULL;
else if (times[0].tv_nsec == UTIME_OMIT &&
times[1].tv_nsec == UTIME_OMIT)
return (0);
else {
if ((times[0].tv_nsec < 0 || times[0].tv_nsec > 999999999) &&
times[0].tv_nsec != UTIME_NOW &&
times[0].tv_nsec != UTIME_OMIT) {
errno = EINVAL;
return (-1);
}
if ((times[1].tv_nsec < 0 || times[1].tv_nsec > 999999999) &&
times[1].tv_nsec != UTIME_NOW &&
times[1].tv_nsec != UTIME_OMIT) {
errno = EINVAL;
return (-1);
}
tv[0].tv_sec = times[0].tv_sec;
tv[0].tv_usec = times[0].tv_nsec / 1000;
tv[1].tv_sec = times[1].tv_sec;
tv[1].tv_usec = times[1].tv_nsec / 1000;
tvp = tv;
if (times[0].tv_nsec == UTIME_OMIT ||
times[1].tv_nsec == UTIME_OMIT) {
if (fstatat(fd, path, &sb, flag) == -1)
return (-1);
if (times[0].tv_nsec == UTIME_OMIT) {
tv[0].tv_sec = sb.st_atim.tv_sec;
tv[0].tv_usec = sb.st_atim.tv_nsec / 1000;
}
if (times[1].tv_nsec == UTIME_OMIT) {
tv[1].tv_sec = sb.st_mtim.tv_sec;
tv[1].tv_usec = sb.st_mtim.tv_nsec / 1000;
}
}
if (times[0].tv_nsec == UTIME_NOW ||
times[1].tv_nsec == UTIME_NOW) {
if (gettimeofday(&now, NULL) == -1)
return (-1);
if (times[0].tv_nsec == UTIME_NOW)
tv[0] = now;
if (times[1].tv_nsec == UTIME_NOW)
tv[1] = now;
}
}
if ((flag & AT_SYMLINK_NOFOLLOW) == 0)
return (futimesat(fd, path, tvp));
else if ((flag & AT_SYMLINK_NOFOLLOW) != 0 &&
(fd == AT_FDCWD || path[0] == '/'))
return (lutimes(path, tvp));
else {
errno = ENOTSUP;
return (-1);
}
}
#endif
7 changes: 5 additions & 2 deletions external/update_sh.sh
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -47,5 +47,8 @@ sed -i '' -e 's,[[:<:]]st_mtim[[:>:]],st_mtimespec,g' "${DESTDIR}/test.c"
mv "${DESTDIR}/builtins.def" "${DESTDIR}/builtins.def.sh" mv "${DESTDIR}/builtins.def" "${DESTDIR}/builtins.def.sh"


git add -A "${DESTDIR}" git add -A "${DESTDIR}"
echo "sh_SOURCES= external/sh_compat/compat.c \\" cat <<EOF
find "${DESTDIR}" -name '*.c'|sed -e 's,$, \\,'|sort sh_SOURCES= external/sh_compat/strchrnul.c \\
external/sh_compat/utimensat.c \\
EOF
find "${DESTDIR}" -name '*.c'|sed -e 's,^, ,' -e 's,$, \\,'|sort
3 changes: 3 additions & 0 deletions src/config.h.in
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@
/* Define to 1 if you have the <unistd.h> header file. */ /* Define to 1 if you have the <unistd.h> header file. */
#undef HAVE_UNISTD_H #undef HAVE_UNISTD_H


/* Define to 1 if you have the `utimensat' function. */
#undef HAVE_UTIMENSAT

/* Name of package */ /* Name of package */
#undef PACKAGE #undef PACKAGE


Expand Down

0 comments on commit f9b13a5

Please sign in to comment.