File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / iftop / util.c
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Tue Feb 21 16:57:34 2012 UTC (12 years, 3 months ago) by misho
Branches: iftop, MAIN
CVS tags: v1_0rc4, v0_17p0, v0_17, HEAD
iftop

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

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>