~ubuntu-branches/ubuntu/feisty/alevt/feisty

« back to all changes in this revision

Viewing changes to misc.c

  • Committer: Bazaar Package Importer
  • Author(s): Thomas Schoepf
  • Date: 2002-03-17 15:09:36 UTC
  • Revision ID: james.westby@ubuntu.com-20020317150936-yglzziwcc0luz55k
Tags: upstream-1.6.0
ImportĀ upstreamĀ versionĀ 1.6.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <stdio.h>
 
2
#include <stdarg.h>
 
3
#include "misc.h"
 
4
 
 
5
char *prgname = 0;
 
6
 
 
7
extern char *strrchr(const char *, int);
 
8
NORETURN(exit(int));
 
9
 
 
10
void
 
11
setprgname(char *str)
 
12
{
 
13
    char *x = strrchr(str, '/');
 
14
 
 
15
    prgname = x ? x+1 : str;
 
16
}
 
17
 
 
18
static void
 
19
print_prgname(void)
 
20
{
 
21
    if (prgname && *prgname)
 
22
        fprintf(stderr, "%s: ", prgname);
 
23
}
 
24
 
 
25
void
 
26
error(const char *str, ...)
 
27
{
 
28
    va_list args;
 
29
 
 
30
    va_start(args, str);
 
31
    print_prgname();
 
32
    vfprintf(stderr, str, args);
 
33
    fputc('\n', stderr);
 
34
}
 
35
 
 
36
void
 
37
ioerror(const char *str)
 
38
{
 
39
    print_prgname();
 
40
    perror(str);
 
41
//    fputc('\n', stderr);
 
42
}
 
43
 
 
44
void
 
45
fatal(const char *str, ...)
 
46
{
 
47
    va_list args;
 
48
 
 
49
    va_start(args, str);
 
50
    print_prgname();
 
51
    vfprintf(stderr, str, args);
 
52
    fputc('\n', stderr);
 
53
    exit(2);
 
54
}
 
55
 
 
56
void
 
57
fatal_ioerror(const char *str)
 
58
{
 
59
    print_prgname();
 
60
    perror(str);
 
61
//    fputc('\n', stderr);
 
62
    exit(2);
 
63
}
 
64
 
 
65
 
 
66
void
 
67
out_of_mem(int size)
 
68
{
 
69
    if (size > 0)
 
70
        fatal("out of memory allocating %d bytes.", size);
 
71
    fatal("out of memory.");
 
72
}