File: util.c

package info (click to toggle)
mercury 0.9-1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 18,488 kB
  • ctags: 9,800
  • sloc: objc: 146,680; ansic: 51,418; sh: 6,436; lisp: 1,567; cpp: 1,040; perl: 854; makefile: 450; asm: 232; awk: 203; exp: 32; fortran: 3; csh: 1
file content (66 lines) | stat: -rw-r--r-- 1,163 bytes parent folder | download
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
64
65
66
/*
** Copyright (C) 1997 The 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.8 1997/07/27 14:59:31 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.8 1997/07/27 14:59:31 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;
}