src/share/tools/launcher/jli_util.c

changeset 5109
aabf54ccedb1
parent 2369
aa6e219afbf1
equal deleted inserted replaced
5108:f0bc60565ba8 5109:aabf54ccedb1
1
2 /*
3 * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 *
6 * This code is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 only, as
8 * published by the Free Software Foundation.
9 *
10 * This code is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * version 2 for more details (a copy is included in the LICENSE file that
14 * accompanied this code).
15 *
16 * You should have received a copy of the GNU General Public License version
17 * 2 along with this work; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19 *
20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21 * or visit www.oracle.com if you need additional information or have any
22 * questions.
23 *
24 */
25
26 #include <stdio.h>
27 #include <string.h>
28 #include "jli_util.h"
29
30 #ifdef GAMMA
31 #ifdef TARGET_OS_FAMILY_windows
32 #define strdup _strdup
33 #endif
34 #endif
35
36 /*
37 * Returns a pointer to a block of at least 'size' bytes of memory.
38 * Prints error message and exits if the memory could not be allocated.
39 */
40 void *
41 JLI_MemAlloc(size_t size)
42 {
43 void *p = malloc(size);
44 if (p == 0) {
45 perror("malloc");
46 exit(1);
47 }
48 return p;
49 }
50
51 /*
52 * Equivalent to realloc(size).
53 * Prints error message and exits if the memory could not be reallocated.
54 */
55 void *
56 JLI_MemRealloc(void *ptr, size_t size)
57 {
58 void *p = realloc(ptr, size);
59 if (p == 0) {
60 perror("realloc");
61 exit(1);
62 }
63 return p;
64 }
65
66 /*
67 * Wrapper over strdup(3C) which prints an error message and exits if memory
68 * could not be allocated.
69 */
70 char *
71 JLI_StringDup(const char *s1)
72 {
73 char *s = strdup(s1);
74 if (s == NULL) {
75 perror("strdup");
76 exit(1);
77 }
78 return s;
79 }
80
81 /*
82 * Very equivalent to free(ptr).
83 * Here to maintain pairing with the above routines.
84 */
85 void
86 JLI_MemFree(void *ptr)
87 {
88 free(ptr);
89 }

mercurial