source: trunk/icedtea-web/launcher/jli_util.c@ 350

Last change on this file since 350 was 348, checked in by dmik, 13 years ago

vendor: Add icedtea-web v1.1.2 to current.

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