Files
mercury/bytecode/util.c
Fergus Henderson a3644ae6cf More cleanup of the bytecode stuff; in particular, add a `MB_' prefix
Estimated hours taken: 2

More cleanup of the bytecode stuff; in particular, add a `MB_' prefix
to most names.

bytecode/*:
	- Prefix all names defined in header files with `MB_'
	  (except for `TRUE', `FALSE', `DEBUGGING', and `XXXdebug').
	- Add macros `MB_new', `MB_new_array', and `MB_resize_array',
	  and use those instead of using `MB_malloc' and `MB_resize'
	  (formerly `mem_malloc' and `mem_resize') or malloc() and realloc()
	  directly.  Uncomment the definition of MB_strdup() now that it
	  calls MB_malloc().
	- Delete the definitions of `uchar', `uint', `ushort', `ulong'
	  (just spell them out, its clearer and more portable that way).
	- Fix the indentation in a few places I missed on my previous pass.
	- Add a `README' file.
1997-04-26 05:57:14 +00:00

67 lines
1.1 KiB
C

/*
** Copyright (C) 1997 University of Melbourne.
** This file may only be copied under the terms of the GNU Library General
** Public License - see the file COPYING.LIB in the Mercury distribution.
**
** $Id: util.c,v 1.7 1997-04-26 05:57:12 fjh Exp $
*/
/* Imports */
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#include "util.h"
#include "mem.h"
/* Local declarations */
static char
rcs_id[] = "$Id: util.c,v 1.7 1997-04-26 05:57:12 fjh Exp $";
/* Implementation */
void
MB_util_error(const char *fmt, ...)
{
va_list arg_p;
fprintf(stderr, "Error: ");
va_start(arg_p, fmt);
vfprintf(stderr, fmt, arg_p);
va_end(argp);
fprintf(stderr, "\n");
}
void
MB_fatal(const char* message)
{
MB_util_error(message);
fprintf(stderr, "NOTE: The program is aborting. "
"Please keep the core file for diagnosis.\n");
abort();
return; /* not reached */
}
char*
MB_strdup(const char* str)
{
int size;
char *str2, *c_p;
size = strlen(str) + 1;
str2 = MB_malloc(size);
for (c_p = str2; *str != '\0'; str++, c_p++)
{
*c_p = *str;
}
*c_p = '\0';
return str2;
}