]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
[Bug 3692] /dev/gpsN requirement prevents KPPS
authorJuergen Perlinger <perlinger@ntp.org>
Sat, 17 Oct 2020 08:39:53 +0000 (10:39 +0200)
committerJuergen Perlinger <perlinger@ntp.org>
Sat, 17 Oct 2020 08:39:53 +0000 (10:39 +0200)
 - implement 'ntp_realpath()' for windows, too
 - increase path buffer for unit tests

bk: 5f8aadd9gla_c6ZcLCXfVub2ywkH2A

libntp/ntp_realpath.c
libntp/xsbprintf.c
ports/winnt/vs2005/libntp.vcproj
ports/winnt/vs2008/libntp/libntp.vcproj
ports/winnt/vs2013/libntp/libntp.vcxproj
ports/winnt/vs2013/libntp/libntp.vcxproj.filters
ports/winnt/vs2015/libntp/libntp.vcxproj
ports/winnt/vs2015/libntp/libntp.vcxproj.filters
tests/libntp/realpath.c

index 716c7b51783b97560c930fe8bb9732a7c131f325..11654294515313d993f80632475b6c231de3462b 100644 (file)
 #include "ntp_stdlib.h"
 
 /* ================================================================== */
-#if !defined(SYS_WINNT) && !defined(HAVE_FUNC_POSIX_REALPATH)
+#if defined(SYS_WINNT)
+/* ================================================================== */
+
+#include <stdlib.h>
+
+/* 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 <sys/stat.h>
 #include <errno.h>
@@ -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);
 }
index 4586758bc88aa1f704136aaa9a7b4da8383dad69..2f7aa5129845cb900b35d174335acf6e844151ec 100644 (file)
@@ -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;
index 1c87724a3ffa704e3838d9e810ac447c90960dd9..f9b589af58f7236103f23e75df321a89fb867ba5 100644 (file)
                                RelativePath="..\..\..\libntp\ntp_random.c"
                                >
                        </File>
+                       <File
+                               RelativePath="..\..\..\libntp\ntp_realpath.c"
+                               >
+                       </File>
                        <File
                                RelativePath="..\..\..\libntp\ntp_rfc2553.c"
                                >
index 7d1193cd234e84099dca7a95c0d612775145f5ea..06e1ce84be57c665550b84967629b8feb1fa1a6a 100644 (file)
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="Windows-1252"?>
 <VisualStudioProject
        ProjectType="Visual C++"
-       Version="9.00"
+       Version="9,00"
        Name="libntp"
        ProjectGUID="{400FBFCB-462E-40D0-B06B-3B74E3FFFD00}"
        TargetFrameworkVersion="0"
                                RelativePath="..\..\..\..\libntp\ntp_random.c"
                                >
                        </File>
+                       <File
+                               RelativePath="..\..\..\..\libntp\ntp_realpath.c"
+                               >
+                       </File>
                        <File
                                RelativePath="..\..\..\..\libntp\ntp_rfc2553.c"
                                >
                                >
                        </File>
                        <File
-                               RelativePath="..\..\..\..\libntp\timetoa.c"
+                               RelativePath="..\..\..\..\libntp\timespecops.c"
                                >
                        </File>
                        <File
-                               RelativePath="..\..\..\..\libntp\timevalops.c"
+                               RelativePath="..\..\..\..\libntp\timetoa.c"
                                >
                        </File>
                        <File
-                               RelativePath="..\..\..\..\lib\isc\tsmemcmp.c"
+                               RelativePath="..\..\..\..\libntp\timevalops.c"
                                >
                        </File>
                        <File
-                               RelativePath="..\..\..\..\libntp\timespecops.c"
+                               RelativePath="..\..\..\..\lib\isc\tsmemcmp.c"
                                >
                        </File>
                        <File
                                >
                        </File>
                        <File
-                               RelativePath="..\..\include\sys\time.h"
+                               RelativePath="..\..\..\..\lib\isc\win32\include\isc\time.h"
                                >
                        </File>
                        <File
                                >
                        </File>
                        <File
-                               RelativePath="..\..\..\..\lib\isc\win32\include\isc\time.h"
+                               RelativePath="..\..\include\sys\time.h"
                                >
                        </File>
                        <File
index f2b741d38f74dc3fdb4d19f794b10716ecffa4f7..50a86e413445f6fe59bbc3358860ceb37e52bc45 100644 (file)
@@ -1,4 +1,4 @@
-<?xml version="1.0" encoding="utf-8"?>
+<?xml version="1.0" encoding="utf-8"?>
 <Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
   <ItemGroup Label="ProjectConfigurations">
     <ProjectConfiguration Include="DebugXP|Win32">
     <ClCompile Include="..\..\..\..\libntp\ntp_libopts.c" />
     <ClCompile Include="..\..\..\..\libntp\ntp_lineedit.c" />
     <ClCompile Include="..\..\..\..\libntp\ntp_random.c" />
+    <ClCompile Include="..\..\..\..\libntp\ntp_realpath.c" />
     <ClCompile Include="..\..\..\..\libntp\ntp_rfc2553.c" />
     <ClCompile Include="..\..\..\..\libntp\ntp_worker.c" />
     <ClCompile Include="..\..\..\..\libntp\numtoa.c" />
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
   <ImportGroup Label="ExtensionTargets">
   </ImportGroup>
-</Project>
+</Project>
\ No newline at end of file
index 69de8cd05c57c731c322000d4bffb5707f098517..3c1677c3536980adeeed342b2d6945d134ee8c60 100644 (file)
@@ -1,4 +1,4 @@
-<?xml version="1.0" encoding="utf-8"?>
+<?xml version="1.0" encoding="utf-8"?>
 <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
   <ItemGroup>
     <Filter Include="Source Files">
     <ClCompile Include="..\..\..\..\libntp\libssl_compat.c">
       <Filter>Source Files</Filter>
     </ClCompile>
+    <ClCompile Include="..\..\..\..\libntp\ntp_realpath.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="..\..\..\..\sntp\libopts\ag-char-map.h">
       <Filter>Resource Files</Filter>
     </CustomBuild>
   </ItemGroup>
-</Project>
+</Project>
\ No newline at end of file
index 8dc81b622306a5efa63899257752960dc8d58fef..c0dfeee08d98200daca2d5fd6e4e0da71a498450 100644 (file)
@@ -1,4 +1,4 @@
-<?xml version="1.0" encoding="utf-8"?>
+<?xml version="1.0" encoding="utf-8"?>
 <Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
   <ItemGroup Label="ProjectConfigurations">
     <ProjectConfiguration Include="DebugXP|Win32">
     <ClCompile Include="..\..\..\..\libntp\ntp_libopts.c" />
     <ClCompile Include="..\..\..\..\libntp\ntp_lineedit.c" />
     <ClCompile Include="..\..\..\..\libntp\ntp_random.c" />
+    <ClCompile Include="..\..\..\..\libntp\ntp_realpath.c" />
     <ClCompile Include="..\..\..\..\libntp\ntp_rfc2553.c" />
     <ClCompile Include="..\..\..\..\libntp\ntp_worker.c" />
     <ClCompile Include="..\..\..\..\libntp\numtoa.c" />
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
   <ImportGroup Label="ExtensionTargets">
   </ImportGroup>
-</Project>
+</Project>
\ No newline at end of file
index 69de8cd05c57c731c322000d4bffb5707f098517..3c1677c3536980adeeed342b2d6945d134ee8c60 100644 (file)
@@ -1,4 +1,4 @@
-<?xml version="1.0" encoding="utf-8"?>
+<?xml version="1.0" encoding="utf-8"?>
 <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
   <ItemGroup>
     <Filter Include="Source Files">
     <ClCompile Include="..\..\..\..\libntp\libssl_compat.c">
       <Filter>Source Files</Filter>
     </ClCompile>
+    <ClCompile Include="..\..\..\..\libntp\ntp_realpath.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="..\..\..\..\sntp\libopts\ag-char-map.h">
       <Filter>Resource Files</Filter>
     </CustomBuild>
   </ItemGroup>
-</Project>
+</Project>
\ No newline at end of file
index 996837cb8fdaa30f33799aac53fd958b92381817..ca2f38e910a11497fa391989c2e6f5f7f1a3f7a6 100644 (file)
@@ -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");