annotate lib/classpath.c @ 17102:9e72d3927af1

binary-io, eealloc, mbfile, mbiter, mbutil, xsize: better 'inline' * lib/binary-io.c, lib/eealloc.c, lib/mbfile.c, lib/mbiter.c: * lib/mbuiter.c, lib/xsize.c: New files. * lib/binary-io.h (BINARY_IO_INLINE): * lib/eealloc.h (EEALLOC_INLINE): * lib/mbfile.h (MBFILE_INLINE): * lib/mbiter.h (MBITER_INLINE): * lib/mbuiter.h (MBUITER_INLINE): * lib/xsize.h (XSIZE_INLINE): New macros. Replace all uses of 'static inline' with them. Use _GL_INLINE_HEADER_BEGIN, _GL_INLINE_HEADER_END. * m4/eealloc.m4 (gl_EEALLOC): * m4/mbfile.m4 (gl_MBFILE): * m4/mbiter.m4 (gl_MBITER): * m4/xsize.m4 (gl_XSIZE): Do not require AC_C_INLINE. * modules/binary-io (Files, lib_SOURCES): Add lib/binary-io.c * modules/eealloc (Files, lib_SOURCES): Add lib/eealloc.c. * modules/mbfile (Files, lib_SOURCES): Add lib/mbfile.c. * modules/mbiter (Files, lib_SOURCES): Add lib/mbiter.c. * modules/mbuiter (Files, lib_SOURCES): Add lib/mbuiter.c. * modules/xsize (Files, lib_SOURCES): Add lib/xsize.c. * modules/binary-io, modules/eealloc, modules/mbfile: * modules/mbiter, modules/mbuiter: (Depends-on): Add extern-inline.
author Paul Eggert <eggert@cs.ucla.edu>
date Wed, 29 Aug 2012 23:13:42 -0700
parents ec738d6aeef5
children e542fd46ad6f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5608
32021ae605cc New module 'classpath'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1 /* Java CLASSPATH handling.
16201
8250f2777afc maint: update all copyright year number ranges
Jim Meyering <meyering@redhat.com>
parents: 14079
diff changeset
2 Copyright (C) 2001-2003, 2006, 2009-2012 Free Software Foundation, Inc.
5608
32021ae605cc New module 'classpath'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3 Written by Bruno Haible <haible@clisp.cons.org>, 2001.
32021ae605cc New module 'classpath'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
4
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 7603
diff changeset
5 This program is free software: you can redistribute it and/or modify
5608
32021ae605cc New module 'classpath'.
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: 7603
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: 7603
diff changeset
8 (at your option) any later version.
5608
32021ae605cc New module 'classpath'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9
32021ae605cc New module 'classpath'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10 This program is distributed in the hope that it will be useful,
32021ae605cc New module 'classpath'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
32021ae605cc New module 'classpath'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32021ae605cc New module 'classpath'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
13 GNU General Public License for more details.
32021ae605cc New module 'classpath'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
14
32021ae605cc New module 'classpath'.
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: 7603
diff changeset
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
5608
32021ae605cc New module 'classpath'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17
7304
1c4ed7637c24 Include <config.h> unconditionally.
Bruno Haible <bruno@clisp.org>
parents: 6792
diff changeset
18 #include <config.h>
5608
32021ae605cc New module 'classpath'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
19
32021ae605cc New module 'classpath'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
20 /* Specification. */
32021ae605cc New module 'classpath'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
21 #include "classpath.h"
32021ae605cc New module 'classpath'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
22
32021ae605cc New module 'classpath'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
23 #include <stdio.h>
32021ae605cc New module 'classpath'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
24 #include <stdlib.h>
32021ae605cc New module 'classpath'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
25 #include <string.h>
32021ae605cc New module 'classpath'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
26
32021ae605cc New module 'classpath'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
27 #include "xsetenv.h"
32021ae605cc New module 'classpath'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
28 #include "xalloc.h"
32021ae605cc New module 'classpath'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
29
32021ae605cc New module 'classpath'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
30 /* Name of environment variable. */
32021ae605cc New module 'classpath'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
31 #ifndef CLASSPATHVAR
32021ae605cc New module 'classpath'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
32 # define CLASSPATHVAR "CLASSPATH"
32021ae605cc New module 'classpath'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
33 #endif
32021ae605cc New module 'classpath'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
34
32021ae605cc New module 'classpath'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
35 /* Separator in PATH like lists of pathnames. */
6792
3d3367284a08 Cygwin portability.
Bruno Haible <bruno@clisp.org>
parents: 5848
diff changeset
36 #if ((defined _WIN32 || defined __WIN32__) && !defined __CYGWIN__) || defined __EMX__ || defined __DJGPP__
16214
ec738d6aeef5 Talk about "native Windows API", not "Win32".
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
37 /* Native Windows, OS/2, DOS */
5608
32021ae605cc New module 'classpath'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
38 # define PATH_SEPARATOR ';'
32021ae605cc New module 'classpath'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
39 #else
32021ae605cc New module 'classpath'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
40 /* Unix */
5822
704da670783e (PATH_SEPARATOR): Remove insignificant trailing blank.
Jim Meyering <jim@meyering.net>
parents: 5608
diff changeset
41 # define PATH_SEPARATOR ':'
5608
32021ae605cc New module 'classpath'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
42 #endif
32021ae605cc New module 'classpath'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
43
32021ae605cc New module 'classpath'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
44 /* Return the new CLASSPATH value. The given classpaths are prepended to
32021ae605cc New module 'classpath'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
45 the current CLASSPATH value. If use_minimal_classpath, the current
32021ae605cc New module 'classpath'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
46 CLASSPATH is ignored. */
32021ae605cc New module 'classpath'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
47 char *
32021ae605cc New module 'classpath'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
48 new_classpath (const char * const *classpaths, unsigned int classpaths_count,
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
49 bool use_minimal_classpath)
5608
32021ae605cc New module 'classpath'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
50 {
32021ae605cc New module 'classpath'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
51 const char *old_classpath;
32021ae605cc New module 'classpath'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
52 unsigned int length;
32021ae605cc New module 'classpath'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
53 unsigned int i;
32021ae605cc New module 'classpath'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
54 char *result;
32021ae605cc New module 'classpath'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
55 char *p;
32021ae605cc New module 'classpath'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
56
32021ae605cc New module 'classpath'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
57 old_classpath = (use_minimal_classpath ? NULL : getenv (CLASSPATHVAR));
32021ae605cc New module 'classpath'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
58 if (old_classpath == NULL)
32021ae605cc New module 'classpath'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
59 old_classpath = "";
32021ae605cc New module 'classpath'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
60
32021ae605cc New module 'classpath'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
61 length = 0;
32021ae605cc New module 'classpath'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
62 for (i = 0; i < classpaths_count; i++)
32021ae605cc New module 'classpath'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
63 length += strlen (classpaths[i]) + 1;
32021ae605cc New module 'classpath'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
64 length += strlen (old_classpath);
32021ae605cc New module 'classpath'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
65 if (classpaths_count > 0 && old_classpath[0] == '\0')
32021ae605cc New module 'classpath'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
66 length--;
32021ae605cc New module 'classpath'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
67
7603
23f14c284219 Simplify xmalloc expressions. Add overflow check in xmalloc arguments.
Bruno Haible <bruno@clisp.org>
parents: 7304
diff changeset
68 result = XNMALLOC (length + 1, char);
5608
32021ae605cc New module 'classpath'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
69 p = result;
32021ae605cc New module 'classpath'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
70 for (i = 0; i < classpaths_count; i++)
32021ae605cc New module 'classpath'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
71 {
32021ae605cc New module 'classpath'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
72 memcpy (p, classpaths[i], strlen (classpaths[i]));
32021ae605cc New module 'classpath'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
73 p += strlen (classpaths[i]);
32021ae605cc New module 'classpath'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
74 *p++ = PATH_SEPARATOR;
32021ae605cc New module 'classpath'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
75 }
32021ae605cc New module 'classpath'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
76 if (old_classpath[0] != '\0')
32021ae605cc New module 'classpath'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
77 {
32021ae605cc New module 'classpath'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
78 memcpy (p, old_classpath, strlen (old_classpath));
32021ae605cc New module 'classpath'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
79 p += strlen (old_classpath);
32021ae605cc New module 'classpath'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
80 }
32021ae605cc New module 'classpath'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
81 else
32021ae605cc New module 'classpath'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
82 {
32021ae605cc New module 'classpath'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
83 if (classpaths_count > 0)
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
84 p--;
5608
32021ae605cc New module 'classpath'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
85 }
32021ae605cc New module 'classpath'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
86 *p = '\0';
32021ae605cc New module 'classpath'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
87
32021ae605cc New module 'classpath'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
88 return result;
32021ae605cc New module 'classpath'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
89 }
32021ae605cc New module 'classpath'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
90
32021ae605cc New module 'classpath'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
91 /* Set CLASSPATH and returns a safe copy of its old value. */
32021ae605cc New module 'classpath'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
92 char *
32021ae605cc New module 'classpath'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
93 set_classpath (const char * const *classpaths, unsigned int classpaths_count,
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
94 bool use_minimal_classpath, bool verbose)
5608
32021ae605cc New module 'classpath'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
95 {
32021ae605cc New module 'classpath'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
96 const char *old_CLASSPATH = getenv (CLASSPATHVAR);
32021ae605cc New module 'classpath'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
97 char *result = (old_CLASSPATH != NULL ? xstrdup (old_CLASSPATH) : NULL);
32021ae605cc New module 'classpath'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
98 char *new_CLASSPATH =
32021ae605cc New module 'classpath'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
99 new_classpath (classpaths, classpaths_count, use_minimal_classpath);
32021ae605cc New module 'classpath'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
100
32021ae605cc New module 'classpath'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
101 if (verbose)
32021ae605cc New module 'classpath'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
102 printf (CLASSPATHVAR "=%s ", new_CLASSPATH);
32021ae605cc New module 'classpath'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
103
32021ae605cc New module 'classpath'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
104 xsetenv (CLASSPATHVAR, new_CLASSPATH, 1);
32021ae605cc New module 'classpath'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
105
32021ae605cc New module 'classpath'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
106 free (new_CLASSPATH);
32021ae605cc New module 'classpath'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
107
32021ae605cc New module 'classpath'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
108 return result;
32021ae605cc New module 'classpath'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
109 }
32021ae605cc New module 'classpath'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
110
32021ae605cc New module 'classpath'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
111 /* Restore CLASSPATH to its previous value. */
32021ae605cc New module 'classpath'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
112 void
32021ae605cc New module 'classpath'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
113 reset_classpath (char *old_classpath)
32021ae605cc New module 'classpath'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
114 {
32021ae605cc New module 'classpath'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
115 if (old_classpath != NULL)
32021ae605cc New module 'classpath'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
116 {
32021ae605cc New module 'classpath'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
117 xsetenv (CLASSPATHVAR, old_classpath, 1);
32021ae605cc New module 'classpath'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
118 free (old_classpath);
32021ae605cc New module 'classpath'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
119 }
32021ae605cc New module 'classpath'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
120 else
32021ae605cc New module 'classpath'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
121 unsetenv (CLASSPATHVAR);
32021ae605cc New module 'classpath'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
122 }