File: misc.c

package info (click to toggle)
alevt 1:1.6.2-4
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 956 kB
  • ctags: 662
  • sloc: ansic: 6,284; makefile: 119; perl: 104; sh: 15
file content (72 lines) | stat: -rw-r--r-- 1,021 bytes parent folder | download | duplicates (10)
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
67
68
69
70
71
72
#include <stdio.h>
#include <stdarg.h>
#include "misc.h"

char *prgname = 0;

extern char *strrchr(const char *, int);
NORETURN(exit(int));

void
setprgname(char *str)
{
    char *x = strrchr(str, '/');

    prgname = x ? x+1 : str;
}

static void
print_prgname(void)
{
    if (prgname && *prgname)
	fprintf(stderr, "%s: ", prgname);
}

void
error(const char *str, ...)
{
    va_list args;

    va_start(args, str);
    print_prgname();
    vfprintf(stderr, str, args);
    fputc('\n', stderr);
}

void
ioerror(const char *str)
{
    print_prgname();
    perror(str);
//    fputc('\n', stderr);
}

void
fatal(const char *str, ...)
{
    va_list args;

    va_start(args, str);
    print_prgname();
    vfprintf(stderr, str, args);
    fputc('\n', stderr);
    exit(2);
}

void
fatal_ioerror(const char *str)
{
    print_prgname();
    perror(str);
//    fputc('\n', stderr);
    exit(2);
}


void
out_of_mem(int size)
{
    if (size > 0)
	fatal("out of memory allocating %d bytes.", size);
    fatal("out of memory.");
}