2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 /*------------------------------------------------------------------------
14 * Generically useful functions for package, the AFS workstation
17 *------------------------------------------------------------------------*/
22 /*------------------------------------------------------------------------
26 * Malloc with error checking.
29 * unsigned size : Number of bytes to allocate.
32 * Ptr to new space if successful,
33 * Exit from package on failure.
36 * Nothing interesting.
39 * As described; may exit from package.
40 *------------------------------------------------------------------------*/
51 if ((ptr = malloc(size)) == NULL) {
53 "Error: Out of memory; malloc() failed allocating %d bytes\n",
55 exit(ERR_OUTOFMEMORY);
61 /*------------------------------------------------------------------------
65 * Calloc() with error checking.
68 * unsigned nelem : Number of elements to allocate.
69 * unsigned size : Number of bytes for each.
72 * Ptr to new space on success,
73 * Exit from package on failure.
76 * Nothing interesting.
79 * As described; may exit from package.
80 *------------------------------------------------------------------------*/
92 if ((ptr = calloc(nelem, size)) == NULL) {
93 fprintf(stderr, "Error: Out of memory; calloc(%d, %d) failed\n",
95 exit(ERR_OUTOFMEMORY);
101 /*------------------------------------------------------------------------
105 * Fopen with error checking.
108 * char *filename : Name of file to open.
109 * char *type : Open mode.
112 * Ptr to file descriptor on success,
113 * Exit from package on failure.
116 * Nothign interesting.
119 * As described; may exit from package.
120 *------------------------------------------------------------------------*/
123 efopen(filename, type)
131 if ((f = fopen(filename, type)) == NULL) {
132 fprintf(stderr, "Error: Couldn't open file; fopen(%s, %s) failed\n",
134 exit(ERR_FOPENFAILED);