1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
|
/*
* util.c:
* Various utility functions.
*
* Copyright (c) 2002 Chris Lightfoot. All rights reserved.
* Email: chris@ex-parrot.com; WWW: http://www.ex-parrot.com/~chris/
*
*/
static const char rcsid[] = "$Id: util.c,v 1.1 2002/03/24 17:27:12 chris Exp $";
#include <sys/types.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "iftop.h"
/* xmalloc:
* Malloc, and abort if malloc fails. */
void *xmalloc(size_t n) {
void *v;
v = malloc(n);
if (!v) abort();
return v;
}
/* xcalloc:
* As above. */
void *xcalloc(size_t n, size_t m) {
void *v;
v = calloc(n, m);
if (!v) abort();
return v;
}
/* xrealloc:
* As above. */
void *xrealloc(void *w, size_t n) {
void *v;
v = realloc(w, n);
if (n != 0 && !v) abort();
return v;
}
/* xstrdup:
* As above. */
char *xstrdup(const char *s) {
char *t;
t = strdup(s);
if (!t) abort();
return t;
}
/* xfree:
* Free, ignoring a passed NULL value. */
void xfree(void *v) {
if (v) free(v);
}
|