annotate lib/javaversion.c @ 10778:ddc567d280d1

Treat Haiku like BeOS.
author Ingo Weinhold <ingo_weinhold@gmx.de>
date Mon, 10 Nov 2008 12:30:58 +0100
parents 7c9d441b72fc
children e8d2c6fc33ad
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7018
096754ee89e4 New module 'javaversion'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1 /* Determine the Java version supported by javaexec.
10197
d079dd7b69bc Add termsigp argument to execute() and wait_process().
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
2 Copyright (C) 2006-2008 Free Software Foundation, Inc.
7018
096754ee89e4 New module 'javaversion'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3 Written by Bruno Haible <bruno@clisp.org>, 2006.
096754ee89e4 New module 'javaversion'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
4
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 9161
diff changeset
5 This program is free software: you can redistribute it and/or modify
7018
096754ee89e4 New module 'javaversion'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
6 it under the terms of the GNU General Public License as published by
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 9161
diff changeset
7 the Free Software Foundation; either version 3 of the License, or
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 9161
diff changeset
8 (at your option) any later version.
7018
096754ee89e4 New module 'javaversion'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9
096754ee89e4 New module 'javaversion'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10 This program is distributed in the hope that it will be useful,
096754ee89e4 New module 'javaversion'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
096754ee89e4 New module 'javaversion'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
096754ee89e4 New module 'javaversion'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
13 GNU General Public License for more details.
096754ee89e4 New module 'javaversion'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
14
096754ee89e4 New module 'javaversion'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
15 You should have received a copy of the GNU General Public License
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 9161
diff changeset
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
7018
096754ee89e4 New module 'javaversion'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17
7304
1c4ed7637c24 Include <config.h> unconditionally.
Bruno Haible <bruno@clisp.org>
parents: 7018
diff changeset
18 #include <config.h>
7018
096754ee89e4 New module 'javaversion'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
19
096754ee89e4 New module 'javaversion'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
20 /* Specification. */
096754ee89e4 New module 'javaversion'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
21 #include "javaversion.h"
096754ee89e4 New module 'javaversion'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
22
096754ee89e4 New module 'javaversion'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
23 #include <errno.h>
096754ee89e4 New module 'javaversion'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
24 #include <stdbool.h>
096754ee89e4 New module 'javaversion'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
25 #include <stdio.h>
096754ee89e4 New module 'javaversion'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
26
096754ee89e4 New module 'javaversion'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
27 #if ENABLE_RELOCATABLE
096754ee89e4 New module 'javaversion'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
28 # include "relocatable.h"
096754ee89e4 New module 'javaversion'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
29 #else
096754ee89e4 New module 'javaversion'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
30 # define relocate(pathname) (pathname)
096754ee89e4 New module 'javaversion'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
31 #endif
096754ee89e4 New module 'javaversion'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
32
096754ee89e4 New module 'javaversion'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
33 #include "javaexec.h"
096754ee89e4 New module 'javaversion'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
34 #include "pipe.h"
096754ee89e4 New module 'javaversion'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
35 #include "wait-process.h"
096754ee89e4 New module 'javaversion'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
36 #include "error.h"
096754ee89e4 New module 'javaversion'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
37 #include "gettext.h"
096754ee89e4 New module 'javaversion'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
38
096754ee89e4 New module 'javaversion'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
39 #define _(str) gettext (str)
096754ee89e4 New module 'javaversion'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
40
10722
7c9d441b72fc Fix a clash between the type DATADIR on Windows and the macro DATADIR.
Bruno Haible <bruno@clisp.org>
parents: 10197
diff changeset
41 /* Get PKGDATADIR. */
7c9d441b72fc Fix a clash between the type DATADIR on Windows and the macro DATADIR.
Bruno Haible <bruno@clisp.org>
parents: 10197
diff changeset
42 #include "configmake.h"
7c9d441b72fc Fix a clash between the type DATADIR on Windows and the macro DATADIR.
Bruno Haible <bruno@clisp.org>
parents: 10197
diff changeset
43
7018
096754ee89e4 New module 'javaversion'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
44
096754ee89e4 New module 'javaversion'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
45 struct locals
096754ee89e4 New module 'javaversion'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
46 {
096754ee89e4 New module 'javaversion'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
47 /* OUT */
096754ee89e4 New module 'javaversion'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
48 char *line;
096754ee89e4 New module 'javaversion'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
49 };
096754ee89e4 New module 'javaversion'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
50
096754ee89e4 New module 'javaversion'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
51 static bool
096754ee89e4 New module 'javaversion'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
52 execute_and_read_line (const char *progname,
096754ee89e4 New module 'javaversion'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
53 const char *prog_path, char **prog_argv,
096754ee89e4 New module 'javaversion'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
54 void *private_data)
096754ee89e4 New module 'javaversion'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
55 {
096754ee89e4 New module 'javaversion'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
56 struct locals *l = (struct locals *) private_data;
096754ee89e4 New module 'javaversion'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
57 pid_t child;
096754ee89e4 New module 'javaversion'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
58 int fd[1];
096754ee89e4 New module 'javaversion'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
59 FILE *fp;
096754ee89e4 New module 'javaversion'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
60 char *line;
096754ee89e4 New module 'javaversion'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
61 size_t linesize;
096754ee89e4 New module 'javaversion'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
62 size_t linelen;
096754ee89e4 New module 'javaversion'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
63 int exitstatus;
096754ee89e4 New module 'javaversion'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
64
096754ee89e4 New module 'javaversion'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
65 /* Open a pipe to the JVM. */
096754ee89e4 New module 'javaversion'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
66 child = create_pipe_in (progname, prog_path, prog_argv, DEV_NULL, false,
096754ee89e4 New module 'javaversion'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
67 true, false, fd);
096754ee89e4 New module 'javaversion'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
68
096754ee89e4 New module 'javaversion'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
69 if (child == -1)
096754ee89e4 New module 'javaversion'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
70 return false;
096754ee89e4 New module 'javaversion'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
71
096754ee89e4 New module 'javaversion'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
72 /* Retrieve its result. */
096754ee89e4 New module 'javaversion'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
73 fp = fdopen (fd[0], "r");
096754ee89e4 New module 'javaversion'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
74 if (fp == NULL)
096754ee89e4 New module 'javaversion'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
75 {
096754ee89e4 New module 'javaversion'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
76 error (0, errno, _("fdopen() failed"));
096754ee89e4 New module 'javaversion'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
77 return false;
096754ee89e4 New module 'javaversion'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
78 }
096754ee89e4 New module 'javaversion'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
79
096754ee89e4 New module 'javaversion'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
80 line = NULL; linesize = 0;
096754ee89e4 New module 'javaversion'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
81 linelen = getline (&line, &linesize, fp);
096754ee89e4 New module 'javaversion'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
82 if (linelen == (size_t)(-1))
096754ee89e4 New module 'javaversion'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
83 {
096754ee89e4 New module 'javaversion'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
84 error (0, 0, _("%s subprocess I/O error"), progname);
096754ee89e4 New module 'javaversion'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
85 return false;
096754ee89e4 New module 'javaversion'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
86 }
096754ee89e4 New module 'javaversion'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
87 if (linelen > 0 && line[linelen - 1] == '\n')
096754ee89e4 New module 'javaversion'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
88 line[linelen - 1] = '\0';
096754ee89e4 New module 'javaversion'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
89
096754ee89e4 New module 'javaversion'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
90 fclose (fp);
096754ee89e4 New module 'javaversion'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
91
096754ee89e4 New module 'javaversion'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
92 /* Remove zombie process from process list, and retrieve exit status. */
10197
d079dd7b69bc Add termsigp argument to execute() and wait_process().
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
93 exitstatus =
d079dd7b69bc Add termsigp argument to execute() and wait_process().
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
94 wait_subprocess (child, progname, true, false, true, false, NULL);
7018
096754ee89e4 New module 'javaversion'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
95 if (exitstatus != 0)
096754ee89e4 New module 'javaversion'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
96 {
096754ee89e4 New module 'javaversion'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
97 free (line);
096754ee89e4 New module 'javaversion'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
98 return false;
096754ee89e4 New module 'javaversion'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
99 }
096754ee89e4 New module 'javaversion'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
100
096754ee89e4 New module 'javaversion'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
101 l->line = line;
096754ee89e4 New module 'javaversion'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
102 return false;
096754ee89e4 New module 'javaversion'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
103 }
096754ee89e4 New module 'javaversion'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
104
096754ee89e4 New module 'javaversion'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
105 char *
096754ee89e4 New module 'javaversion'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
106 javaexec_version (void)
096754ee89e4 New module 'javaversion'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
107 {
096754ee89e4 New module 'javaversion'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
108 const char *class_name = "javaversion";
096754ee89e4 New module 'javaversion'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
109 const char *pkgdatadir = relocate (PKGDATADIR);
096754ee89e4 New module 'javaversion'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
110 const char *args[1];
096754ee89e4 New module 'javaversion'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
111 struct locals locals;
096754ee89e4 New module 'javaversion'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
112
096754ee89e4 New module 'javaversion'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
113 args[0] = NULL;
096754ee89e4 New module 'javaversion'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
114 locals.line = NULL;
096754ee89e4 New module 'javaversion'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
115 execute_java_class (class_name, &pkgdatadir, 1, true, NULL, args,
096754ee89e4 New module 'javaversion'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
116 false, false, execute_and_read_line, &locals);
096754ee89e4 New module 'javaversion'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
117
096754ee89e4 New module 'javaversion'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
118 return locals.line;
096754ee89e4 New module 'javaversion'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
119 }