Logo Search packages:      
Sourcecode: java-gcj-compat version File versions  Download package


/* java.c -- set LD_LIBRARY_PATH, LD_PRELOAD, java.ext.dirs and exec gij
   Copyright (C) 2005, 2006  Red Hat

This file is part of java-gcj-compat.

java-gcj-compat is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.

java-gcj-compat is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
General Public License for more details.

You should have received a copy of the GNU General Public License
along with java-gcj-compat; see the file COPYING.  If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.

Linking this library statically or dynamically with other modules is
making a combined work based on this library.  Thus, the terms and
conditions of the GNU General Public License cover the whole

As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module.  An independent module is a module which is not derived from
or based on this library.  If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so.  If you do not wish to do so, delete this
exception statement from your version. */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

/* Return argv with -Djava.ext.dirs set properly, however, don't
   change argv if -Djava.ext.dirs is already on the command line.  */
char **
set_java_ext_dir (int argc, char *argv[])
  char **nargv;
  int i = 1;

  while (i < argc && *argv[i] == '-')
      if (strncmp ("-Djava.ext.dirs=", argv[i], 16) == 0)
      return argv;

  nargv = (char **) malloc ((argc + 2) * sizeof(char *));
  nargv[0] = argv[0];
  nargv[1] = "-Djava.ext.dirs=" JAVA_HOME "/lib/ext";
  for (i = 2; i <= argc; i++)
    nargv[i] = argv[i-1];
  nargv[i] = 0;
  return nargv;

main (int argc, char* argv[])
  int error_code = 0;
  char *libpath = NULL;
  char *newpath = NULL;
  int newlen = 0;

  newlen = 0;

  libpath = getenv ("LD_LIBRARY_PATH");

  if (libpath && libpath[0] != '\0')
      newlen += strlen (libpath);
      // for the separating ':'
      newlen += 1;

  newlen += sizeof (JAVA_HOME) - 1;
  newlen += sizeof ("/lib/") - 1;
  newlen += sizeof (ARCH) - 1;

  newpath = (char *) malloc (newlen + 1);

  if (newpath != NULL)
      if (libpath && libpath[0] != '\0')
        snprintf (newpath, newlen + 1,
                  "%s%s%s%s%s", JAVA_HOME, "/lib/", ARCH, ":", libpath);
        snprintf (newpath, newlen + 1, "%s%s%s", JAVA_HOME, "/lib/", ARCH);

  setenv ("LD_LIBRARY_PATH", newpath, 1);

  free (newpath);

  error_code = execv (GCJ_BIN_DIR "/gij", set_java_ext_dir (argc, argv));

  fprintf (stderr, "error spawning gij\n");

  return error_code;

Generated by  Doxygen 1.6.0   Back to index