-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherr.c
33 lines (27 loc) · 836 Bytes
/
err.c
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
#include "err.h"
#include "secs.h"
#include <errno.h>
#include <stddef.h>
#include <stdio.h>
#include <time.h>
#include <unistd.h>
static double t0 = 0.0;
void err_reset(void) {
t0 = secs_now();
}
// The handling of `errno` respects the following statement from N1570.
//
// > The value of errno may be set to nonzero
// > by a library function call whether or not there is an error,
// > provided the use of errno is not documented
// > in the description of the function in this International Standard.
void err_msg_with(char const* const func, char const* const file,
size_t const line, char const* const str) {
int const tmp = errno;
double const t1 = secs_now();
if (fprintf(stderr, "[%f] (%zu) <%s> %s:%zu: ",
t1 - t0, (size_t) getpid(), func, file, line) != EOF) {
errno = tmp;
perror(str);
}
}