Mercurial > hg > octave-nkf > gnulib-hg
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 |
rev | line source |
---|---|
7018 | 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 | 3 Written by Bruno Haible <bruno@clisp.org>, 2006. |
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 | 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 | 9 |
10 This program is distributed in the hope that it will be useful, | |
11 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 GNU General Public License for more details. | |
14 | |
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 | 17 |
7304
1c4ed7637c24
Include <config.h> unconditionally.
Bruno Haible <bruno@clisp.org>
parents:
7018
diff
changeset
|
18 #include <config.h> |
7018 | 19 |
20 /* Specification. */ | |
21 #include "javaversion.h" | |
22 | |
23 #include <errno.h> | |
24 #include <stdbool.h> | |
25 #include <stdio.h> | |
26 | |
27 #if ENABLE_RELOCATABLE | |
28 # include "relocatable.h" | |
29 #else | |
30 # define relocate(pathname) (pathname) | |
31 #endif | |
32 | |
33 #include "javaexec.h" | |
34 #include "pipe.h" | |
35 #include "wait-process.h" | |
36 #include "error.h" | |
37 #include "gettext.h" | |
38 | |
39 #define _(str) gettext (str) | |
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 | 44 |
45 struct locals | |
46 { | |
47 /* OUT */ | |
48 char *line; | |
49 }; | |
50 | |
51 static bool | |
52 execute_and_read_line (const char *progname, | |
53 const char *prog_path, char **prog_argv, | |
54 void *private_data) | |
55 { | |
56 struct locals *l = (struct locals *) private_data; | |
57 pid_t child; | |
58 int fd[1]; | |
59 FILE *fp; | |
60 char *line; | |
61 size_t linesize; | |
62 size_t linelen; | |
63 int exitstatus; | |
64 | |
65 /* Open a pipe to the JVM. */ | |
66 child = create_pipe_in (progname, prog_path, prog_argv, DEV_NULL, false, | |
67 true, false, fd); | |
68 | |
69 if (child == -1) | |
70 return false; | |
71 | |
72 /* Retrieve its result. */ | |
73 fp = fdopen (fd[0], "r"); | |
74 if (fp == NULL) | |
75 { | |
76 error (0, errno, _("fdopen() failed")); | |
77 return false; | |
78 } | |
79 | |
80 line = NULL; linesize = 0; | |
81 linelen = getline (&line, &linesize, fp); | |
82 if (linelen == (size_t)(-1)) | |
83 { | |
84 error (0, 0, _("%s subprocess I/O error"), progname); | |
85 return false; | |
86 } | |
87 if (linelen > 0 && line[linelen - 1] == '\n') | |
88 line[linelen - 1] = '\0'; | |
89 | |
90 fclose (fp); | |
91 | |
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 | 95 if (exitstatus != 0) |
96 { | |
97 free (line); | |
98 return false; | |
99 } | |
100 | |
101 l->line = line; | |
102 return false; | |
103 } | |
104 | |
105 char * | |
106 javaexec_version (void) | |
107 { | |
108 const char *class_name = "javaversion"; | |
109 const char *pkgdatadir = relocate (PKGDATADIR); | |
110 const char *args[1]; | |
111 struct locals locals; | |
112 | |
113 args[0] = NULL; | |
114 locals.line = NULL; | |
115 execute_java_class (class_name, &pkgdatadir, 1, true, NULL, args, | |
116 false, false, execute_and_read_line, &locals); | |
117 | |
118 return locals.line; | |
119 } |