harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hinde...@apache.org
Subject svn commit: r951009 - /harmony/enhanced/java/trunk/jdktools/modules/samsa/src/main/native/samsa/samsa.c
Date Thu, 03 Jun 2010 14:25:40 GMT
Author: hindessm
Date: Thu Jun  3 14:25:40 2010
New Revision: 951009

URL: http://svn.apache.org/viewvc?rev=951009&view=rev
Log:
These implementations should be portable enough that we don't need the #error
pragmas.

Modified:
    harmony/enhanced/java/trunk/jdktools/modules/samsa/src/main/native/samsa/samsa.c

Modified: harmony/enhanced/java/trunk/jdktools/modules/samsa/src/main/native/samsa/samsa.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/jdktools/modules/samsa/src/main/native/samsa/samsa.c?rev=951009&r1=951008&r2=951009&view=diff
==============================================================================
--- harmony/enhanced/java/trunk/jdktools/modules/samsa/src/main/native/samsa/samsa.c (original)
+++ harmony/enhanced/java/trunk/jdktools/modules/samsa/src/main/native/samsa/samsa.c Thu Jun
 3 14:25:40 2010
@@ -15,6 +15,10 @@
  *  limitations under the License.
  */
 
+#if defined(FREEBSD)
+#include <sys/param.h>
+#endif
+
 #include <stdlib.h>
 #include <stdio.h>
 #include <errno.h>
@@ -85,8 +89,8 @@ typedef struct ToolData {
 } TOOLDATA;
 
 char     *cleanToolName(const char *);
-char     *getExeDir();
-char     *getRoot();
+char     *getExeDir(const char*);
+char     *getRoot(const char*);
 TOOLDATA *getToolData(const char *, const char *, int toolType);
 int getToolType(const char*, const char*);
 char* jarFile(const char*, const char*);
@@ -135,7 +139,7 @@ int main (int argc, char **argv, char **
      *  and the full paths to jars.  This way, we can be called 
      *  from anywhere
      */    
-    root = getRoot();
+    root = getRoot(argv[0]);
 
 //    printf("root = %s\n", root);
     
@@ -411,7 +415,7 @@ char *cleanToolName(const char *name) 
     }
          
     return temp;     
- #elif defined(LINUX) || defined(FREEBSD)
+ #else
  
     /*
      *  if we found a slash (and someone didn't do something 
@@ -423,20 +427,18 @@ char *cleanToolName(const char *name) 
     else { 
         return strdup(name);
     }
- #else
- #error Need to define basename-type function
  #endif
 }
 
 /******************************************************************
- *  getRoot()
+ *  getRoot(const char* argv0)
  * 
  *  returns the root (JDK or JRE) where this executable is located
  *  if it can figure it out or NULL if it can't
  */
-char *getRoot() { 
+char *getRoot(const char* argv0) { 
     
-    char *exeDir = getExeDir();
+    char *exeDir = getExeDir(argv0);
 
     char *last = strrchr(exeDir, PATH_SEPARATOR_CHAR);
     
@@ -449,36 +451,27 @@ char *getRoot() { 
 }
 
 /*****************************************************************
- * getExeDir()
+ * getExeDir(const char* argv0)
  * 
  *  returns directory of running exe
  */
-char *getExeDir() {
+char *getExeDir(const char* argv0) {
 
     char *last = NULL;
     
-#if defined(LINUX)
-    char buffer[PATH_MAX + 1];
-    
-    int size = readlink ("/proc/self/exe", buffer, sizeof(buffer)-2);
-    
-    buffer[size+1] = '\0';
-#elif defined(FREEBSD)
-    Dl_info info;
-    char buffer[PATH_MAX + 1];
-    if (dladdr( (const void*)&main, &info) == 0) {
-        return NULL;
-    }
-    strncpy(buffer, info.dli_fname, PATH_MAX);
-    buffer[PATH_MAX] = '\0';
-
-#elif defined(WIN32)
+#if defined(WIN32)
     char buffer[512];
     DWORD dwRet = GetModuleFileName(NULL, buffer, 512);
         
     // FIXME - handle this right - it could be that 512 isn't enough
 #else
-#error Need to implement executable name code
+    char buffer[PATH_MAX + 1];
+
+    char *rc = realpath(argv0, buffer);
+    if (!rc) {
+      return NULL;
+    }
+    buffer[PATH_MAX] = '\0';
 #endif
 
     last = strrchr(buffer, PATH_SEPARATOR_CHAR);



Mime
View raw message