server: handle pcre2 now returning -1 for "no match"
[rb-79.git] / macros.h
blobbbeb176a569e4669f88561ec2216076f6eb66c18
1 /*
2 * Copyright (c) 2017-2018, De Rais <derais@cock.li>
4 * Permission to use, copy, modify, and/or distribute this software for
5 * any purpose with or without fee is hereby granted, provided that the
6 * above copyright notice and this permission notice appear in all
7 * copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
10 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
11 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
12 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
13 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
14 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
15 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16 * PERFORMANCE OF THIS SOFTWARE.
18 #define UNUSED(x) (void) (sizeof(x))
20 #define STR2(x) #x
21 #define STR(x) STR2(x)
22 #define L(x) __FILE__ ":" STR(__LINE__) ": " x
24 #define NUM_OF(x) (sizeof(x) / sizeof((x)[0]))
26 #define UBSAFES(x) ((x) ? (x) : "[None]")
28 extern const char *program_name;
30 #define PERROR_MESSAGE(x) perror(L(x))
31 #define ERROR_MESSAGE(...) \
32 do { \
33 fprintf(stderr, "%s", UBSAFES(program_name)); \
34 fprintf(stderr, ": ERROR: " __FILE__ ":" STR( \
35 __LINE__) ": " __VA_ARGS__); \
36 fprintf(stderr, "\n"); \
37 } while (0)
39 #ifdef WRITE_LOGS
40 #define LOG(...) \
41 do { \
42 fprintf(stderr, "%s", UBSAFES(program_name)); \
43 fprintf(stderr, ": %-25s", \
44 "LOG: " __FILE__ ":" STR( \
45 __LINE__) ":"); \
46 fprintf(stderr, __VA_ARGS__); \
47 fprintf(stderr, "\n"); \
48 } while (0)
49 #else
50 #define LOG(...)
51 #endif