Mercurial > code
comparison C/port/err.h @ 334:0b576ee64d45
* Create brand new hierarchy
* Rename DynLib to Dynlib
* Remove some warnings
author | David Demelier <markand@malikania.fr> |
---|---|
date | Sun, 08 Mar 2015 14:26:33 +0100 |
parents | port/err.h@bb2694382675 |
children |
comparison
equal
deleted
inserted
replaced
333:412ca7a5e1ea | 334:0b576ee64d45 |
---|---|
1 /* | |
2 * err.h -- formtted error messages (portable version) | |
3 * | |
4 * Copyright (c) 2011, 2012, David Demelier <markand@malikania.fr> | |
5 * | |
6 * Permission to use, copy, modify, and/or distribute this software for any | |
7 * purpose with or without fee is hereby granted, provided that the above | |
8 * copyright notice and this permission notice appear in all copies. | |
9 * | |
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | |
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | |
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | |
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | |
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | |
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
17 */ | |
18 | |
19 #ifndef _ERR_H_ | |
20 #define _ERR_H_ | |
21 | |
22 #include <stdarg.h> | |
23 | |
24 #ifdef __cplusplus | |
25 extern "C" { | |
26 #endif | |
27 | |
28 /* | |
29 * Attribute noreturn may helps. This may produce a warning with GCC 4.5: | |
30 * | |
31 * int a; | |
32 * | |
33 * if ((a = getstate() < 0) | |
34 * errx(1, "State failed"); | |
35 * | |
36 * Because compilator does not know that errx will call exit may produce | |
37 * a warning like `a may be used uninitialized'. | |
38 */ | |
39 | |
40 #if defined(__GNUC__) | |
41 # define __at_noreturn __attribute__ ((noreturn)) | |
42 #elif defined(_MSC_VER) | |
43 # define __at_noreturn __declspec(noreturn) | |
44 #endif | |
45 | |
46 /* | |
47 * err() functions append the format message to the stderr FILE pointer. They | |
48 * also append the system error using strerror(errno). Then the functions exit | |
49 * with the error code given as first argument. | |
50 */ | |
51 | |
52 void err(int, const char *, ...) __at_noreturn; | |
53 void verr(int, const char *, va_list) __at_noreturn; | |
54 | |
55 /* | |
56 * errx() functions are similar to err() except that they do not append the | |
57 * system error message. | |
58 */ | |
59 | |
60 void errx(int, const char *, ...) __at_noreturn; | |
61 void verrx(int, const char *, va_list) __at_noreturn; | |
62 | |
63 /* | |
64 * warn() functions are similar to err() but they do not call exit(). | |
65 */ | |
66 | |
67 void warn(const char *, ...); | |
68 void vwarn(const char *, va_list); | |
69 | |
70 /* | |
71 * warnx() functions are similar to warn() except that they do not append the | |
72 * system error message. | |
73 */ | |
74 | |
75 void warnx(const char *, ...); | |
76 void vwarnx(const char *, va_list); | |
77 | |
78 #ifdef __cplusplus | |
79 } | |
80 #endif | |
81 | |
82 #endif /* _ERR_H_ */ |