This is global.c in view mode; [Download] [Up]
/* Global stuff every program needs.
Copyright 1993 by Michael L.H. Brouwer (michael@urc.tue.nl)
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, or (at your option) any later
version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
675 Mass Ave, Cambridge, MA 02139, USA.
$Modified: Tue Mar 23 17:48:38 1993 by michael $
$Id: global.c,v 1.6 1993/04/04 22:46:10 michael Exp $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <errno.h>
#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include "global.h"
const char *prog;
/* Initialize the prog variable. */
void
init_prog (const char *p)
{
prog = strrchr (p, '/');
prog = prog ? prog + 1 : p;
} /* init_prog */
/* Report an error in the following format:
`myprogram: <printf of arguments>:: system error message'
always returns -1. */
int
errorf (char *fmt, ...)
{
va_list ap;
fprintf (stderr, "%s: ", prog);
va_start (ap, fmt);
vfprintf (stderr, fmt, ap);
va_end (ap);
perror (":");
return -1;
} /* errorf */
/* Report an error in the following format:
`myprogram: <printf of arguments>:: system error message'
and exit with code 1. */
void
fatalf (char *fmt, ...)
{
va_list ap;
fprintf (stderr, "%s: ", prog);
va_start (ap, fmt);
vfprintf (stderr, fmt, ap);
va_end (ap);
perror (":");
exit (1);
} /* fatalf */
/* Malloc size bytes of mem. Call fatal if something goes wrong. */
void *
xmalloc (size_t size)
{
void *mem;
mem = malloc (size);
if (!mem && size)
fatalf ("xmalloc %ld", (long) size);
return mem;
} /* xmalloc */
void *
xrealloc (void *old, size_t size)
{
void *mem;
mem = realloc (old, size);
if (!mem && size)
fatalf ("xrealloc %ld", (long) size);
return mem;
} /* xrealloc */
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.