Changeset: 85b103ff844c for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=85b103ff844c
Modified Files:
        common/utils/mutils.c
        common/utils/mutils.h
        tools/mserver/mserver5.c
Branch: Apr2011
Log Message:

get_bin_path: move get_mserver_bin_path into mutils

Soon we'll need the same functionality also in monetdbd, so prepare for
sharing the same code.


diffs (108 lines):

diff --git a/common/utils/mutils.c b/common/utils/mutils.c
--- a/common/utils/mutils.c
+++ b/common/utils/mutils.c
@@ -278,3 +278,39 @@
 }
 
 #endif
+
+static char _bin_path[1024];
+char *
+get_bin_path(void)
+{
+       /* getting the path to the executable's binary, isn't all that
+        * simple, unfortunately */
+#if defined(_MSC_VER)          /* Windows */
+       if (GetModuleFileName(NULL, _bin_path,
+                             (DWORD) sizeof(_bin_path)) != 0)
+               return _bin_path;
+#elif defined(HAVE__NSGETEXECUTABLEPATH)  /* Darwin/OSX */
+       uint32_t size = sizeof(_bin_path);
+       if (_NSGetExecutablePath(_bin_path, &size) == 0)
+               return _bin_path;
+#elif defined(HAVE_SYS_SYSCTL_H) && defined(KERN_PROC_PATHNAME)  /* BSD */
+       int mib[4];
+       size_t cb = sizeof(_bin_path);
+       mib[0] = CTL_KERN;
+       mib[1] = KERN_PROC;
+       mib[2] = KERN_PROC_PATHNAME;
+       mib[3] = -1;
+       if (sysctl(mib, 4, _bin_path, &cb, NULL, 0) == 0)
+               return _bin_path;
+#elif defined(HAVE_GETEXECNAME)  /* Solaris */
+       const char *execn = getexecname();
+       /* copy, such that the caller can actually modify this string */
+       snprintf(_bin_path, sizeof(_bin_path), "%s", execn);
+#else  /* try Linux approach */
+       if (readlink("/proc/self/exe",
+                               _bin_path, sizeof(_bin_path)) != -1)
+                       return _bin_path;
+#endif
+       /* could use argv[0] (passed) to deduce location based on PATH */
+       return NULL;
+}
diff --git a/common/utils/mutils.h b/common/utils/mutils.h
--- a/common/utils/mutils.h
+++ b/common/utils/mutils.h
@@ -72,4 +72,6 @@
 
 mutils_export int MT_lockf(char *filename, int mode, off_t off, off_t len);
 
+mutils_export char *get_bin_path(void);
+
 #endif /* _MUTILS_H_ */
diff --git a/tools/mserver/mserver5.c b/tools/mserver/mserver5.c
--- a/tools/mserver/mserver5.c
+++ b/tools/mserver/mserver5.c
@@ -200,42 +200,6 @@
        mal_exit();
 }
 
-static char _mserver_bin_path[1024];
-static char *
-get_mserver_bin_path(void)
-{
-       /* getting the path to the executable's binary, isn't all that
-        * simple, unfortunately */
-#if defined(_MSC_VER)          /* Windows */
-       if (GetModuleFileName(NULL, _mserver_bin_path,
-                             (DWORD) sizeof(_mserver_bin_path)) != 0)
-               return _mserver_bin_path;
-#elif defined(HAVE__NSGETEXECUTABLEPATH)  /* Darwin/OSX */
-       uint32_t size = sizeof(_mserver_bin_path);
-       if (_NSGetExecutablePath(_mserver_bin_path, &size) == 0)
-               return _mserver_bin_path;
-#elif defined(HAVE_SYS_SYSCTL_H) && defined(KERN_PROC_PATHNAME)  /* BSD */
-       int mib[4];
-       size_t cb = sizeof(_mserver_bin_path);
-       mib[0] = CTL_KERN;
-       mib[1] = KERN_PROC;
-       mib[2] = KERN_PROC_PATHNAME;
-       mib[3] = -1;
-       if (sysctl(mib, 4, _mserver_bin_path, &cb, NULL, 0) == 0)
-               return _mserver_bin_path;
-#elif defined(HAVE_GETEXECNAME)  /* Solaris */
-       const char *execn = getexecname();
-       /* copy, such that the caller can actually modify this string */
-       snprintf(_mserver_bin_path, sizeof(_mserver_bin_path), "%s", execn);
-#else  /* try Linux approach */
-       if (readlink("/proc/self/exe",
-                               _mserver_bin_path, sizeof(_mserver_bin_path)) 
!= -1)
-                       return _mserver_bin_path;
-#endif
-       /* could use argv[0] (passed) to deduce location based on PATH */
-       return NULL;
-}
-
 int
 main(int argc, char **av)
 {
@@ -474,7 +438,7 @@
                char *libdirs[] = { "lib", "lib64", "lib/64", "lib32", NULL };
                size_t i;
                struct stat sb;
-               char *binpath = get_mserver_bin_path();
+               char *binpath = get_bin_path();
                if (binpath != NULL) {
                        binpath = dirname(binpath);
                        binpath = dirname(binpath);
_______________________________________________
Checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to