[commit: ghc] master: rts: Move path utilities to separate source file (f084e68)
git at git.haskell.org
git at git.haskell.org
Sun Oct 23 18:05:30 UTC 2016
Repository : ssh://git@git.haskell.org/ghc
On branch : master
Link : http://ghc.haskell.org/trac/ghc/changeset/f084e6845515fbfb774a09ae5d2af1eea8fdc3f0/ghc
>---------------------------------------------------------------
commit f084e6845515fbfb774a09ae5d2af1eea8fdc3f0
Author: Ben Gamari <bgamari.foss at gmail.com>
Date: Sun Oct 23 14:03:48 2016 -0400
rts: Move path utilities to separate source file
Test Plan: Validate
Reviewers: simonmar, austin, erikd
Reviewed By: simonmar
Subscribers: thomie
Differential Revision: https://phabricator.haskell.org/D2614
>---------------------------------------------------------------
f084e6845515fbfb774a09ae5d2af1eea8fdc3f0
rts/Linker.c | 84 +--------------------------------------------------------
rts/PathUtils.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++
rts/PathUtils.h | 43 +++++++++++++++++++++++++++++
3 files changed, 112 insertions(+), 83 deletions(-)
diff --git a/rts/Linker.c b/rts/Linker.c
index 3eeb46e..7600ba8 100644
--- a/rts/Linker.c
+++ b/rts/Linker.c
@@ -28,6 +28,7 @@
#include "Profiling.h"
#include "sm/OSMem.h"
#include "linker/M32Alloc.h"
+#include "PathUtils.h"
#if !defined(mingw32_HOST_OS)
#include "posix/Signals.h"
@@ -45,7 +46,6 @@
#include <string.h>
#include <stdio.h>
#include <assert.h>
-#include <libgen.h>
#ifdef HAVE_SYS_STAT_H
#include <sys/stat.h>
@@ -231,81 +231,6 @@ static ObjectCode* mkOc( pathchar *path, char *image, int imageSize,
int misalignment
);
-// Use wchar_t for pathnames on Windows (#5697)
-#if defined(mingw32_HOST_OS)
-#define pathcmp wcscmp
-#define pathlen wcslen
-#define pathopen _wfopen
-#define pathstat _wstat
-#define struct_stat struct _stat
-#define open wopen
-#define WSTR(s) L##s
-#define pathprintf swprintf
-#define pathsize sizeof(wchar_t)
-#else
-#define pathcmp strcmp
-#define pathlen strlen
-#define pathopen fopen
-#define pathstat stat
-#define struct_stat struct stat
-#define WSTR(s) s
-#define pathprintf snprintf
-#define pathsize sizeof(char)
-#endif
-
-static pathchar* pathdup(pathchar *path)
-{
- pathchar *ret;
-#if defined(mingw32_HOST_OS)
- ret = wcsdup(path);
-#else
- /* sigh, strdup() isn't a POSIX function, so do it the long way */
- ret = stgMallocBytes( strlen(path)+1, "pathdup" );
- strcpy(ret, path);
-#endif
- return ret;
-}
-
-static pathchar* pathdir(pathchar *path)
-{
- pathchar *ret;
-#if defined(mingw32_HOST_OS)
- pathchar *drive, *dirName;
- size_t memberLen = pathlen(path) + 1;
- dirName = stgMallocBytes(pathsize * memberLen, "pathdir(path)");
- ret = stgMallocBytes(pathsize * memberLen, "pathdir(path)");
- drive = stgMallocBytes(pathsize * _MAX_DRIVE, "pathdir(path)");
- _wsplitpath_s(path, drive, _MAX_DRIVE, dirName, pathsize * pathlen(path), NULL, 0, NULL, 0);
- pathprintf(ret, memberLen, WSTR("%" PATH_FMT "%" PATH_FMT), drive, dirName);
- stgFree(drive);
- stgFree(dirName);
-#else
- pathchar* dirName = dirname(path);
- size_t memberLen = pathlen(dirName);
- ret = stgMallocBytes(pathsize * (memberLen + 2), "pathdir(path)");
- strcpy(ret, dirName);
- ret[memberLen ] = '/';
- ret[memberLen+1] = '\0';
-#endif
- return ret;
-}
-
-static pathchar* mkPath(char* path)
-{
-#if defined(mingw32_HOST_OS)
- size_t required = mbstowcs(NULL, path, 0);
- pathchar *ret = stgMallocBytes(sizeof(pathchar) * (required + 1), "mkPath");
- if (mbstowcs(ret, path, required) == (size_t)-1)
- {
- barf("mkPath failed converting char* to wchar_t*");
- }
- ret[required] = '\0';
- return ret;
-#else
- return pathdup(path);
-#endif
-}
-
/* Generic wrapper function to try and Resolve and RunInit oc files */
int ocTryLoad( ObjectCode* oc );
@@ -361,13 +286,6 @@ static void machoInitSymbolsWithoutUnderscore( void );
#endif
#if defined(OBJFORMAT_PEi386)
-/* string utility function */
-static HsBool endsWithPath(pathchar* base, pathchar* str) {
- int blen = pathlen(base);
- int slen = pathlen(str);
- return (blen >= slen) && (0 == pathcmp(base + blen - slen, str));
-}
-
static int checkAndLoadImportLibrary(
pathchar* arch_name,
char* member_name,
diff --git a/rts/PathUtils.c b/rts/PathUtils.c
new file mode 100644
index 0000000..f27e03f
--- /dev/null
+++ b/rts/PathUtils.c
@@ -0,0 +1,68 @@
+#include <string.h>
+#include <stddef.h>
+
+#include <Rts.h>
+#include "RtsUtils.h"
+#include "PathUtils.h"
+
+#include <libgen.h>
+#include <ctype.h>
+
+pathchar* pathdup(pathchar *path)
+{
+ pathchar *ret;
+#if defined(mingw32_HOST_OS)
+ ret = wcsdup(path);
+#else
+ /* sigh, strdup() isn't a POSIX function, so do it the long way */
+ ret = stgMallocBytes( strlen(path)+1, "pathdup" );
+ strcpy(ret, path);
+#endif
+ return ret;
+}
+
+pathchar* pathdir(pathchar *path)
+{
+ pathchar *ret;
+#if defined(mingw32_HOST_OS)
+ pathchar *drive, *dirName;
+ size_t memberLen = pathlen(path) + 1;
+ dirName = stgMallocBytes(pathsize * memberLen, "pathdir(path)");
+ ret = stgMallocBytes(pathsize * memberLen, "pathdir(path)");
+ drive = stgMallocBytes(pathsize * _MAX_DRIVE, "pathdir(path)");
+ _wsplitpath_s(path, drive, _MAX_DRIVE, dirName, pathsize * pathlen(path), NULL, 0, NULL, 0);
+ pathprintf(ret, memberLen, WSTR("%" PATH_FMT "%" PATH_FMT), drive, dirName);
+ stgFree(drive);
+ stgFree(dirName);
+#else
+ pathchar* dirName = dirname(path);
+ size_t memberLen = pathlen(dirName);
+ ret = stgMallocBytes(pathsize * (memberLen + 2), "pathdir(path)");
+ strcpy(ret, dirName);
+ ret[memberLen ] = '/';
+ ret[memberLen+1] = '\0';
+#endif
+ return ret;
+}
+
+pathchar* mkPath(char* path)
+{
+#if defined(mingw32_HOST_OS)
+ size_t required = mbstowcs(NULL, path, 0);
+ pathchar *ret = stgMallocBytes(sizeof(pathchar) * (required + 1), "mkPath");
+ if (mbstowcs(ret, path, required) == (size_t)-1)
+ {
+ barf("mkPath failed converting char* to wchar_t*");
+ }
+ ret[required] = '\0';
+ return ret;
+#else
+ return pathdup(path);
+#endif
+}
+
+HsBool endsWithPath(pathchar* base, pathchar* str) {
+ int blen = pathlen(base);
+ int slen = pathlen(str);
+ return (blen >= slen) && (0 == pathcmp(base + blen - slen, str));
+}
diff --git a/rts/PathUtils.h b/rts/PathUtils.h
new file mode 100644
index 0000000..4821938
--- /dev/null
+++ b/rts/PathUtils.h
@@ -0,0 +1,43 @@
+/* ---------------------------------------------------------------------------
+ *
+ * (c) The GHC Team, 2001-2016
+ *
+ * Platform-independent path manipulation utilities
+ *
+ * --------------------------------------------------------------------------*/
+
+#ifndef PATH_UTILS_H
+#define PATH_UTILS_H
+
+#include "BeginPrivate.h"
+
+// Use wchar_t for pathnames on Windows (#5697)
+#if defined(mingw32_HOST_OS)
+#define pathcmp wcscmp
+#define pathlen wcslen
+#define pathopen _wfopen
+#define pathstat _wstat
+#define struct_stat struct _stat
+#define open wopen
+#define WSTR(s) L##s
+#define pathprintf swprintf
+#define pathsize sizeof(wchar_t)
+#else
+#define pathcmp strcmp
+#define pathlen strlen
+#define pathopen fopen
+#define pathstat stat
+#define struct_stat struct stat
+#define WSTR(s) s
+#define pathprintf snprintf
+#define pathsize sizeof(char)
+#endif
+
+pathchar* pathdup(pathchar *path);
+pathchar* pathdir(pathchar *path);
+pathchar* mkPath(char* path);
+HsBool endsWithPath(pathchar* base, pathchar* str);
+
+#include "EndPrivate.h"
+
+#endif /* PATH_UTILS_H */
More information about the ghc-commits
mailing list