From 7169e31121e8c8cc729b55154deb722ae495b316 Mon Sep 17 00:00:00 2001 From: Darren Tucker Date: Mon, 28 Oct 2019 16:00:45 +1100 Subject: Move utimensat definition into timespec section. Since utimensat uses struct timespec, move it to the section where we define struct timespec when needed. --- openbsd-compat/bsd-misc.h | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'openbsd-compat/bsd-misc.h') diff --git a/openbsd-compat/bsd-misc.h b/openbsd-compat/bsd-misc.h index cb158cd5c..23c18d676 100644 --- a/openbsd-compat/bsd-misc.h +++ b/openbsd-compat/bsd-misc.h @@ -64,14 +64,6 @@ struct timeval { int utimes(char *, struct timeval *); #endif /* HAVE_UTIMES */ -#ifndef HAVE_UTIMENSAT -/* start with the high bits and work down to minimise risk of overlap */ -# ifndef AT_SYMLINK_NOFOLLOW -# define AT_SYMLINK_NOFOLLOW 0x80000000 -# endif -int utimensat(int, const char *, const struct timespec[2], int); -#endif - #ifndef AT_FDCWD # define AT_FDCWD (-2) #endif @@ -88,16 +80,26 @@ int fchownat(int, const char *, uid_t, gid_t, int); int truncate (const char *, off_t); #endif /* HAVE_TRUNCATE */ -#if !defined(HAVE_NANOSLEEP) && !defined(HAVE_NSLEEP) #ifndef HAVE_STRUCT_TIMESPEC struct timespec { time_t tv_sec; long tv_nsec; }; -#endif + +#if !defined(HAVE_NANOSLEEP) && !defined(HAVE_NSLEEP) int nanosleep(const struct timespec *, struct timespec *); #endif +#ifndef HAVE_UTIMENSAT +/* start with the high bits and work down to minimise risk of overlap */ +# ifndef AT_SYMLINK_NOFOLLOW +# define AT_SYMLINK_NOFOLLOW 0x80000000 +# endif +int utimensat(int, const char *, const struct timespec[2], int); +#endif /* !HAVE_UTIMENSAT */ + +#endif /* !HAVE_STRUCT_TIMESPEC */ + #ifndef HAVE_USLEEP int usleep(unsigned int useconds); #endif -- cgit v1.2.3 From 5fe81da22652f8caa63e9e3a1af519a85d36337e Mon Sep 17 00:00:00 2001 From: Darren Tucker Date: Mon, 28 Oct 2019 21:19:47 +1100 Subject: Fix ifdefs to not mask needed bits. --- openbsd-compat/bsd-misc.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'openbsd-compat/bsd-misc.h') diff --git a/openbsd-compat/bsd-misc.h b/openbsd-compat/bsd-misc.h index 23c18d676..f5b032bbc 100644 --- a/openbsd-compat/bsd-misc.h +++ b/openbsd-compat/bsd-misc.h @@ -85,6 +85,7 @@ struct timespec { time_t tv_sec; long tv_nsec; }; +#endif /* !HAVE_STRUCT_TIMESPEC */ #if !defined(HAVE_NANOSLEEP) && !defined(HAVE_NSLEEP) int nanosleep(const struct timespec *, struct timespec *); @@ -98,8 +99,6 @@ int nanosleep(const struct timespec *, struct timespec *); int utimensat(int, const char *, const struct timespec[2], int); #endif /* !HAVE_UTIMENSAT */ -#endif /* !HAVE_STRUCT_TIMESPEC */ - #ifndef HAVE_USLEEP int usleep(unsigned int useconds); #endif -- cgit v1.2.3 From 1bcd1169c5221688418fa38606e9c69055b72451 Mon Sep 17 00:00:00 2001 From: Darren Tucker Date: Tue, 29 Oct 2019 19:45:03 +1100 Subject: Add implementation of localtime_r. --- configure.ac | 1 + openbsd-compat/bsd-misc.c | 10 ++++++++++ openbsd-compat/bsd-misc.h | 4 ++++ 3 files changed, 15 insertions(+) (limited to 'openbsd-compat/bsd-misc.h') diff --git a/configure.ac b/configure.ac index ea99887fd..9b4a7ee62 100644 --- a/configure.ac +++ b/configure.ac @@ -1763,6 +1763,7 @@ AC_CHECK_FUNCS([ \ inet_ntop \ innetgr \ llabs \ + localtime_r \ login_getcapbool \ md5_crypt \ memmem \ diff --git a/openbsd-compat/bsd-misc.c b/openbsd-compat/bsd-misc.c index 7a26ee40c..829e0c075 100644 --- a/openbsd-compat/bsd-misc.c +++ b/openbsd-compat/bsd-misc.c @@ -426,3 +426,13 @@ int _ssh_compat_fflush(FILE *f) return fflush(f); } #endif + +#ifndef HAVE_LOCALTIME_R +struct tm * +localtime_r(const time_t *timep, struct tm *result) +{ + struct tm *tm = localtime(timep); + *result = *tm; + return result; +} +#endif diff --git a/openbsd-compat/bsd-misc.h b/openbsd-compat/bsd-misc.h index f5b032bbc..5a369d9de 100644 --- a/openbsd-compat/bsd-misc.h +++ b/openbsd-compat/bsd-misc.h @@ -178,4 +178,8 @@ int flock(int, int); # define fflush(x) (_ssh_compat_fflush(x)) #endif +#ifndef HAVE_LOCALTIME_R +struct tm *localtime_r(const time_t *, struct tm *); +#endif + #endif /* _BSD_MISC_H */ -- cgit v1.2.3 From 79d46de9fbea0f3c0e8ae7cf84effaba089071b0 Mon Sep 17 00:00:00 2001 From: Darren Tucker Date: Fri, 1 Nov 2019 15:22:32 +1100 Subject: Use sftp_realpath if no native realpath. --- configure.ac | 1 + openbsd-compat/bsd-misc.h | 4 ++++ 2 files changed, 5 insertions(+) (limited to 'openbsd-compat/bsd-misc.h') diff --git a/configure.ac b/configure.ac index 8489384fb..a9cbfed0c 100644 --- a/configure.ac +++ b/configure.ac @@ -1783,6 +1783,7 @@ AC_CHECK_FUNCS([ \ raise \ readpassphrase \ reallocarray \ + realpath \ recvmsg \ recallocarray \ rresvport_af \ diff --git a/openbsd-compat/bsd-misc.h b/openbsd-compat/bsd-misc.h index 5a369d9de..429ade047 100644 --- a/openbsd-compat/bsd-misc.h +++ b/openbsd-compat/bsd-misc.h @@ -182,4 +182,8 @@ int flock(int, int); struct tm *localtime_r(const time_t *, struct tm *); #endif +#ifndef HAVE_REALPATH +#define realpath(x, y) (sftp_realpath((x), (y)) +#endif + #endif /* _BSD_MISC_H */ -- cgit v1.2.3 From b56dbfd9d967e5b6ce7be9f81f206112e19e1030 Mon Sep 17 00:00:00 2001 From: Darren Tucker Date: Fri, 1 Nov 2019 18:17:42 +1100 Subject: Add missing bracket in realpath macro. --- openbsd-compat/bsd-misc.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'openbsd-compat/bsd-misc.h') diff --git a/openbsd-compat/bsd-misc.h b/openbsd-compat/bsd-misc.h index 429ade047..7bf7b048a 100644 --- a/openbsd-compat/bsd-misc.h +++ b/openbsd-compat/bsd-misc.h @@ -183,7 +183,7 @@ struct tm *localtime_r(const time_t *, struct tm *); #endif #ifndef HAVE_REALPATH -#define realpath(x, y) (sftp_realpath((x), (y)) +#define realpath(x, y) (sftp_realpath((x), (y))) #endif #endif /* _BSD_MISC_H */ -- cgit v1.2.3 From e0cedcad51fe02683943bf4f1ad2961aa3f35313 Mon Sep 17 00:00:00 2001 From: Darren Tucker Date: Tue, 14 Jan 2020 09:42:52 +1100 Subject: Improve search for 'struct timespec'. Make struct timespec test consistent with existing timeval test. Include time.h for timespec in compat header where required. --- configure.ac | 25 ++++++++++++++++++++++++- openbsd-compat/bsd-misc.h | 2 ++ 2 files changed, 26 insertions(+), 1 deletion(-) (limited to 'openbsd-compat/bsd-misc.h') diff --git a/configure.ac b/configure.ac index a33acac85..b1b3bdacf 100644 --- a/configure.ac +++ b/configure.ac @@ -4025,6 +4025,8 @@ if test "x$ac_cv_have_struct_addrinfo" = "xyes" ; then [define if you have struct addrinfo data type]) fi +AC_HEADER_TIME + AC_CACHE_CHECK([for struct timeval], ac_cv_have_struct_timeval, [ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ #include ]], [[ struct timeval tv; tv.tv_sec = 1;]])], @@ -4037,7 +4039,28 @@ if test "x$ac_cv_have_struct_timeval" = "xyes" ; then have_struct_timeval=1 fi -AC_CHECK_TYPES([struct timespec]) +AC_CACHE_CHECK([for struct timespec], ac_cv_have_struct_timespec, [ + AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ + #ifdef TIME_WITH_SYS_TIME + # include + # include + #else + # ifdef HAVE_SYS_TIME_H + # include + # else + # include + # endif + #endif + ]], + [[ struct timespec ts; ts.tv_sec = 1;]])], + [ ac_cv_have_struct_timespec="yes" ], + [ ac_cv_have_struct_timespec="no" + ]) +]) +if test "x$ac_cv_have_struct_timespec" = "xyes" ; then + AC_DEFINE([HAVE_STRUCT_TIMESPEC], [1], [define if you have struct timespec]) + have_struct_timespec=1 +fi # We need int64_t or else certain parts of the compile will fail. if test "x$ac_cv_have_int64_t" = "xno" && \ diff --git a/openbsd-compat/bsd-misc.h b/openbsd-compat/bsd-misc.h index 7bf7b048a..3a7dd6f4c 100644 --- a/openbsd-compat/bsd-misc.h +++ b/openbsd-compat/bsd-misc.h @@ -88,10 +88,12 @@ struct timespec { #endif /* !HAVE_STRUCT_TIMESPEC */ #if !defined(HAVE_NANOSLEEP) && !defined(HAVE_NSLEEP) +# include int nanosleep(const struct timespec *, struct timespec *); #endif #ifndef HAVE_UTIMENSAT +# include /* start with the high bits and work down to minimise risk of overlap */ # ifndef AT_SYMLINK_NOFOLLOW # define AT_SYMLINK_NOFOLLOW 0x80000000 -- cgit v1.2.3