#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>
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);
}
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;
RelativePath="..\..\..\libntp\ntp_random.c"
>
</File>
+ <File
+ RelativePath="..\..\..\libntp\ntp_realpath.c"
+ >
+ </File>
<File
RelativePath="..\..\..\libntp\ntp_rfc2553.c"
>
<?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
-<?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
-<?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
-<?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
-<?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
# 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");