This source file includes following definitions.
- execute_and_read_line
- javaexec_version
   1 
   2 
   3 
   4 
   5 
   6 
   7 
   8 
   9 
  10 
  11 
  12 
  13 
  14 
  15 
  16 
  17 
  18 #include <config.h>
  19 
  20 
  21 #include "javaversion.h"
  22 
  23 #include <errno.h>
  24 #include <stdbool.h>
  25 #include <stdio.h>
  26 #include <stdlib.h>
  27 
  28 #if ENABLE_RELOCATABLE
  29 # include "relocatable.h"
  30 #else
  31 # define relocate(pathname) (pathname)
  32 # define relocate2(pathname,allocatedp) (*(allocatedp) = NULL, (pathname))
  33 #endif
  34 
  35 #include "javaexec.h"
  36 #include "spawn-pipe.h"
  37 #include "wait-process.h"
  38 #include "error.h"
  39 #include "gettext.h"
  40 
  41 #define _(str) gettext (str)
  42 
  43 
  44 #include "configmake.h"
  45 
  46 
  47 struct locals
  48 {
  49   
  50   char *line;
  51 };
  52 
  53 static bool
  54 execute_and_read_line (const char *progname,
     
  55                        const char *prog_path, const char * const *prog_argv,
  56                        void *private_data)
  57 {
  58   struct locals *l = (struct locals *) private_data;
  59   pid_t child;
  60   int fd[1];
  61   FILE *fp;
  62   char *line;
  63   size_t linesize;
  64   size_t linelen;
  65   int exitstatus;
  66 
  67   
  68   child = create_pipe_in (progname, prog_path, prog_argv, NULL,
  69                           DEV_NULL, false, true, false, fd);
  70 
  71   if (child == -1)
  72     return false;
  73 
  74   
  75   fp = fdopen (fd[0], "r");
  76   if (fp == NULL)
  77     {
  78       error (0, errno, _("fdopen() failed"));
  79       return false;
  80     }
  81 
  82   line = NULL; linesize = 0;
  83   linelen = getline (&line, &linesize, fp);
  84   if (linelen == (size_t)(-1))
  85     {
  86       error (0, 0, _("%s subprocess I/O error"), progname);
  87       return false;
  88     }
  89   if (linelen > 0 && line[linelen - 1] == '\n')
  90     line[linelen - 1] = '\0';
  91 
  92   fclose (fp);
  93 
  94   
  95   exitstatus =
  96     wait_subprocess (child, progname, true, false, true, false, NULL);
  97   if (exitstatus != 0)
  98     {
  99       free (line);
 100       return false;
 101     }
 102 
 103   l->line = line;
 104   return false;
 105 }
 106 
 107 char *
 108 javaexec_version (void)
     
 109 {
 110   const char *class_name = "javaversion";
 111   char *malloc_pkgdatadir;
 112   const char *pkgdatadir = relocate2 (PKGDATADIR, &malloc_pkgdatadir);
 113   const char *args[1];
 114   struct locals locals;
 115 
 116   args[0] = NULL;
 117   locals.line = NULL;
 118   execute_java_class (class_name, &pkgdatadir, 1, true, NULL, args,
 119                       false, false, execute_and_read_line, &locals);
 120 
 121   free (malloc_pkgdatadir);
 122   return locals.line;
 123 }