summaryrefslogtreecommitdiff
path: root/libjava/prims.cc
diff options
context:
space:
mode:
Diffstat (limited to 'libjava/prims.cc')
-rw-r--r--libjava/prims.cc42
1 files changed, 42 insertions, 0 deletions
diff --git a/libjava/prims.cc b/libjava/prims.cc
index 2536ca47e64..1c3490e7511 100644
--- a/libjava/prims.cc
+++ b/libjava/prims.cc
@@ -1723,3 +1723,45 @@ _Jv_CheckAccess (jclass self_klass, jclass other_klass, jint flags)
&& _Jv_ClassNameSamePackage (self_klass->name,
other_klass->name)));
}
+
+// Prepend GCJ_VERSIONED_LIBDIR to a module search path stored in a C
+// char array, if the path is not already prefixed by
+// GCJ_VERSIONED_LIBDIR. Return a newly JvMalloc'd char buffer. The
+// result should be freed using JvFree.
+char*
+_Jv_PrependVersionedLibdir (char* libpath)
+{
+ char* retval = 0;
+
+ if (libpath && libpath[0] != '\0')
+ {
+ if (! strncmp (libpath,
+ GCJ_VERSIONED_LIBDIR,
+ sizeof (GCJ_VERSIONED_LIBDIR) - 1))
+ {
+ // LD_LIBRARY_PATH is already prefixed with
+ // GCJ_VERSIONED_LIBDIR.
+ retval = (char*) _Jv_Malloc (strlen (libpath) + 1);
+ strcpy (retval, libpath);
+ }
+ else
+ {
+ // LD_LIBRARY_PATH is not prefixed with
+ // GCJ_VERSIONED_LIBDIR.
+ jsize total = (sizeof (GCJ_VERSIONED_LIBDIR) - 1)
+ + (sizeof (PATH_SEPARATOR) - 1) + strlen (libpath) + 1;
+ retval = (char*) _Jv_Malloc (total);
+ strcpy (retval, GCJ_VERSIONED_LIBDIR);
+ strcat (retval, PATH_SEPARATOR);
+ strcat (retval, libpath);
+ }
+ }
+ else
+ {
+ // LD_LIBRARY_PATH was not specified or is empty.
+ retval = (char*) _Jv_Malloc (sizeof (GCJ_VERSIONED_LIBDIR));
+ strcpy (retval, GCJ_VERSIONED_LIBDIR);
+ }
+
+ return retval;
+}