From: Juergen Perlinger Date: Sat, 17 Oct 2020 08:39:53 +0000 (+0200) Subject: [Bug 3692] /dev/gpsN requirement prevents KPPS X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=35129154cf3c24f0d7144001aa2611f68fe58491;p=thirdparty%2Fntp.git [Bug 3692] /dev/gpsN requirement prevents KPPS - implement 'ntp_realpath()' for windows, too - increase path buffer for unit tests bk: 5f8aadd9gla_c6ZcLCXfVub2ywkH2A --- diff --git a/libntp/ntp_realpath.c b/libntp/ntp_realpath.c index 716c7b517..116542945 100644 --- a/libntp/ntp_realpath.c +++ b/libntp/ntp_realpath.c @@ -44,7 +44,37 @@ #include "ntp_stdlib.h" /* ================================================================== */ -#if !defined(SYS_WINNT) && !defined(HAVE_FUNC_POSIX_REALPATH) +#if defined(SYS_WINNT) +/* ================================================================== */ + +#include + +/* On Windows, we assume 2k for a file path is enough. */ +#define NTP_PATH_MAX 2048 + +static char * +realpath1(const char *path, char *resolved) +{ + /* Items in the device name space get passed back AS IS. Everything + * else is fed through '_fullpath()', which is probably the closest + * counterpart to what 'realpath()' is expected to do on Windows... + */ + char * retval = NULL; + + if (!strncmp(path, "\\\\.\\", 4)) { + if (strlcpy(resolved, path, NTP_PATH_MAX) >= NTP_PATH_MAX) + errno = ENAMETOOLONG; + else + retval = resolved; + } else if ((retval = _fullpath(resolved, path, NTP_PATH_MAX)) == NULL) { + errno = ENAMETOOLONG; + } + return retval; +} + +/* ================================================================== */ +#elif !defined(HAVE_FUNC_POSIX_REALPATH) +/* ================================================================== */ #include #include @@ -219,55 +249,31 @@ realpath1(const char *path, char *resolved) return (resolved); } +/* ================================================================== */ #endif /* !defined(SYS_WINNT) && !defined(HAVE_POSIX_REALPATH) */ /* ================================================================== */ char * ntp_realpath(const char * path) { - char *res, *m; +# if defined(HAVE_FUNC_POSIX_REALPATH) -# if defined(SYS_WINNT) - - (void)m; - if (path == NULL) { - errno = EINVAL; - return (NULL); - } - if (path[0] == '\0') { - errno = ENOENT; - return (NULL); - } - - return strdup(path); /* this clearly needs some work! */ - -# elif defined(HAVE_FUNC_POSIX_REALPATH) - - (void)m; return realpath(path, NULL); # else - if (path == NULL) { + char *res = NULL, *m = NULL; + if (path == NULL) errno = EINVAL; - return (NULL); - } - if (path[0] == '\0') { + else if (path[0] == '\0') errno = ENOENT; - return (NULL); - } - - m = malloc(NTP_PATH_MAX); - if (m == NULL) - return (NULL); - - res = realpath1(path, m); - if (res != NULL) - res = realloc(res, strlen(res) + 1); - if (res == NULL) + else if ((m = malloc(NTP_PATH_MAX)) == NULL) + errno = ENOMEM; /* MSVCRT malloc does not set this... */ + else if ((res = realpath1(path, m)) == NULL) free(m); + else + res = realloc(res, strlen(res) + 1); + return (res); # endif - - return (res); } diff --git a/libntp/xsbprintf.c b/libntp/xsbprintf.c index 4586758bc..2f7aa5129 100644 --- a/libntp/xsbprintf.c +++ b/libntp/xsbprintf.c @@ -42,9 +42,9 @@ xvsbprintf( size_t blen = (size_t)(pend - pbuf); rc = vsnprintf(pbuf, blen, pfmt, va); if (rc > 0) { - if ((size_t)rc >= blen) - rc = 0; - pbuf += rc; + if ((size_t)rc >= blen) + rc = 0; + pbuf += rc; } *pbuf = '\0'; /* fear of bad vsnprintf */ *ppbuf = pbuf; diff --git a/ports/winnt/vs2005/libntp.vcproj b/ports/winnt/vs2005/libntp.vcproj index 1c87724a3..f9b589af5 100644 --- a/ports/winnt/vs2005/libntp.vcproj +++ b/ports/winnt/vs2005/libntp.vcproj @@ -416,6 +416,10 @@ RelativePath="..\..\..\libntp\ntp_random.c" > + + diff --git a/ports/winnt/vs2008/libntp/libntp.vcproj b/ports/winnt/vs2008/libntp/libntp.vcproj index 7d1193cd2..06e1ce84b 100644 --- a/ports/winnt/vs2008/libntp/libntp.vcproj +++ b/ports/winnt/vs2008/libntp/libntp.vcproj @@ -1,7 +1,7 @@ + + @@ -652,19 +656,19 @@ > + @@ -254,6 +254,7 @@ + @@ -436,4 +437,4 @@ - + \ No newline at end of file diff --git a/ports/winnt/vs2013/libntp/libntp.vcxproj.filters b/ports/winnt/vs2013/libntp/libntp.vcxproj.filters index 69de8cd05..3c1677c35 100644 --- a/ports/winnt/vs2013/libntp/libntp.vcxproj.filters +++ b/ports/winnt/vs2013/libntp/libntp.vcxproj.filters @@ -1,4 +1,4 @@ - + @@ -341,6 +341,9 @@ Source Files + + Source Files + @@ -595,4 +598,4 @@ Resource Files - + \ No newline at end of file diff --git a/ports/winnt/vs2015/libntp/libntp.vcxproj b/ports/winnt/vs2015/libntp/libntp.vcxproj index 8dc81b622..c0dfeee08 100644 --- a/ports/winnt/vs2015/libntp/libntp.vcxproj +++ b/ports/winnt/vs2015/libntp/libntp.vcxproj @@ -1,4 +1,4 @@ - + @@ -254,6 +254,7 @@ + @@ -436,4 +437,4 @@ - + \ No newline at end of file diff --git a/ports/winnt/vs2015/libntp/libntp.vcxproj.filters b/ports/winnt/vs2015/libntp/libntp.vcxproj.filters index 69de8cd05..3c1677c35 100644 --- a/ports/winnt/vs2015/libntp/libntp.vcxproj.filters +++ b/ports/winnt/vs2015/libntp/libntp.vcxproj.filters @@ -1,4 +1,4 @@ - + @@ -341,6 +341,9 @@ Source Files + + Source Files + @@ -595,4 +598,4 @@ Resource Files - + \ No newline at end of file diff --git a/tests/libntp/realpath.c b/tests/libntp/realpath.c index 996837cb8..ca2f38e91 100644 --- a/tests/libntp/realpath.c +++ b/tests/libntp/realpath.c @@ -61,8 +61,8 @@ void test_DevLinks(void) { # ifdef SYS_WINNT TEST_IGNORE_MESSAGE("not applicable to windows so far"); # else - char nam[80]; - char abs[80]; + char nam[512]; + char abs[512]; struct dirent * ent; DIR * dfs = opendir("/dev");