-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwarning.c
More file actions
42 lines (35 loc) · 908 Bytes
/
warning.c
File metadata and controls
42 lines (35 loc) · 908 Bytes
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
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include "warning.h"
#include "main.h"
void warning(char *s, ...)
/* vypise varovani na stderr, parametry podobne jako printf, jen
neni treba psat '\n' pro ukonceni radku */
{
va_list vl;
fprintf(stderr, "%s warning: ", gargv[0]);
va_start(vl, s);
vfprintf(stderr, s, vl);
va_end(vl);
fprintf(stderr, "\n");
}
void error(char *s, ...)
/* podobne jako warning, ale ukonci program a
na zacatek radku misto "warning:" napise "error:" */
{
va_list vl;
fprintf(stderr, "%s error: ", gargv[0]);
va_start(vl, s);
vfprintf(stderr, s, vl);
va_end(vl);
fprintf(stderr, "\n");
exit(-1);
}
void *mymalloc(unsigned int size)
/* pouzije malloc, selze-li, skonci na error: memory allocation failed */
{
void *result;
if(!(result = malloc(size))) error("Allocation of size %d failed", size);
return result;
}