Add Russian translation provided by Валерий Крувялис <valkru@mail.ru>
[xiph-mirror.git] / w3d / tools / psnr / error.c
blob9281acd9b217e6e9f52ece6115b00f1674cea883
1 /* very simple error handling functions */
3 #include <stdarg.h>
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <errno.h>
8 #include "error.h"
10 /* print "ERROR: " followed by error msg "fmt", a printf style format string */
11 void
12 error(char *fmt, ...)
14 va_list ap;
16 (void) fflush(stdout);
17 fprintf(stderr, "ERROR: ");
19 va_start(ap, fmt);
20 (void) vfprintf(stderr, fmt, ap);
21 va_end(ap);
23 (void) putc('\n', stderr);
26 /* call error and die */
27 void
28 fatal(char *fmt, ...)
30 va_list ap;
32 (void) fflush(stdout);
33 fprintf(stderr, "ERROR: ");
35 va_start(ap, fmt);
36 (void) vfprintf(stderr, fmt, ap);
37 va_end(ap);
39 (void) putc('\n', stderr);
40 exit(EXIT_FAILURE);
43 void *
44 emalloc(size_t size)
46 register void *p = malloc(size);
48 if (p == 0)
49 fatal("out of memory");
50 return p;
53 void *
54 erealloc(void *ptr, size_t size)
56 if (0 == ptr)
57 return emalloc(size);
58 if (0 == size) {
59 free(ptr);
60 return 0;
62 ptr = realloc(ptr, size);
63 if (0 == ptr)
64 fatal("out of memory");
66 return ptr;
69 FILE *
70 efopen(const char *path, const char *mode)
72 FILE *p = fopen(path, mode);
73 if (p == 0) {
74 perror("efopen");
75 error("unable to open file: %s", path);
77 return p;