+++ /dev/null
-/* -*-c-*-
- *
- * $Id: utils.c,v 1.1 1997/07/21 13:47:42 mdw Exp $
- *
- * Miscellaneous useful bits of code.
- *
- * (c) 1997 Mark Wooding
- */
-
-/*----- Licencing notice --------------------------------------------------*
- *
- * This file is part of `become'
- *
- * `Become' 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 of the License, or
- * (at your option) any later version.
- *
- * `Become' 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 `become'; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-/*----- Revision history --------------------------------------------------*
- *
- * $Log: utils.c,v $
- * Revision 1.1 1997/07/21 13:47:42 mdw
- * Initial revision
- *
- */
-
-/*----- Header files ------------------------------------------------------*/
-
-/* --- ANSI headers --- */
-
-#include <stdarg.h>
-#include <stdio.h>
-#include <stdlib.h>
-
-/* --- Local headers --- */
-
-#include "config.h"
-#include "utils.h"
-
-/*----- Static data -------------------------------------------------------*/
-
-static const char *myname = 0; /* What's my name? */
-
-/*----- Program name handling ---------------------------------------------*/
-
-/* --- @quis@ --- *
- *
- * Arguments: ---
- *
- * Returns: Pointer to the program name.
- *
- * Use: Returns the program name.
- */
-
-const char *quis(void)
-{
- return (myname);
-}
-
-/* --- @ego@ --- *
- *
- * Arguments: @const char *p@ = pointer to program name
- *
- * Returns: ---
- *
- * Use: Tells the utils library what the program's name is.
- */
-
-#ifndef PATHSEP
-# if defined(__riscos)
-# define PATHSEP '.'
-# elif defined(__unix) || defined(unix)
-# define PATHSEP '/'
-# else
-# define PATHSEP '\\'
-# endif
-#endif
-
-void ego(const char *p)
-{
- const char *q = p;
- while (*q) {
- if (*q++ == PATHSEP)
- p = q;
- }
- myname = p;
-}
-
-/*----- Error reporting ---------------------------------------------------*/
-
-/* --- @moan@ --- *
- *
- * Arguments: @const char *f@ = a @printf@-style format string
- * @...@ = other arguments
- *
- * Returns: ---
- *
- * Use: Reports an error.
- */
-
-void moan(const char *f, ...)
-{
- va_list ap;
- va_start(ap, f);
- fprintf(stderr, "%s: ", myname);
- vfprintf(stderr, f, ap);
- va_end(ap);
- putc('\n', stderr);
-}
-
-/* --- @die@ --- *
- *
- * Arguments: @const char *f@ = a @printf@-style format string
- * @...@ = other arguments
- *
- * Returns: Never.
- *
- * Use: Reports an error and hari-kiris. Like @moan@ above, only
- * more permanent.
- */
-
-void die(const char *f, ...)
-{
- va_list ap;
- va_start(ap, f);
- fprintf(stderr, "%s: ", myname);
- vfprintf(stderr, f, ap);
- va_end(ap);
- putc('\n', stderr);
- exit(EXIT_FAILURE);
-}
-
-/*----- Memory management functions ---------------------------------------*/
-
-/* --- @xmalloc@ --- *
- *
- * Arguments: @size_t sz@ = size of block to allocate
- *
- * Returns: Pointer to allocated block.
- *
- * Use: Allocates memory. If the memory isn't available, we don't
- * hang aroung long enough for a normal function return.
- */
-
-void *xmalloc(size_t sz)
-{
- void *p = malloc(sz);
- if (!p)
- die("not enough memory");
- return (p);
-}
-
-/* --- @xstrdup@ --- *
- *
- * Arguments: @const char *s@ = pointer to a string
- *
- * Returns: Pointer to a copy of the string.
- *
- * Use: Copies a string (like @strdup@ would, if it existed).
- */
-
-char *xstrdup(const char *s)
-{
- size_t sz = strlen(s) + 1;
- char *p = xmalloc(sz);
- memcpy(p, s, sz);
- return (p);
-}
-
-/* --- @xrealloc@ --- *
- *
- * Arguments: @void *p@ = pointer to a block of memory
- * @size_t sz@ = new size desired for the block
- *
- * Returns: Pointer to the resized memory block (which is almost
- * certainly not in the same place any more).
- *
- * Use: Resizes a memory block.
- */
-
-void *xrealloc(void *p, size_t sz)
-{
- p = realloc(p, sz);
- if (!p)
- die("not enough memory");
- return (p);
-}
-
-/*----- That's all, folks -------------------------------------------------*/