Mercurial > projects > libpws
comparison compat/err.c @ 2:97097b4b6bfb
Add pwsdump utility
The pwsdum utility can dump PasswordSafe database files to a plaintext format
and convert this format back into a PasswordSafe database.
author | Guido Berhoerster <guido+libpws@berhoerster.name> |
---|---|
date | Wed, 01 Apr 2015 14:57:57 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
1:e1309515d111 | 2:97097b4b6bfb |
---|---|
1 /* | |
2 * Copyright (C) 2011 Guido Berhoerster <guido+libpws@berhoerster.name> | |
3 * | |
4 * Permission is hereby granted, free of charge, to any person obtaining | |
5 * a copy of this software and associated documentation files (the | |
6 * "Software"), to deal in the Software without restriction, including | |
7 * without limitation the rights to use, copy, modify, merge, publish, | |
8 * distribute, sublicense, and/or sell copies of the Software, and to | |
9 * permit persons to whom the Software is furnished to do so, subject to | |
10 * the following conditions: | |
11 * | |
12 * The above copyright notice and this permission notice shall be included | |
13 * in all copies or substantial portions of the Software. | |
14 * | |
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | |
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | |
18 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY | |
19 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | |
20 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | |
21 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
22 */ | |
23 | |
24 #include <stdlib.h> | |
25 #include <stdio.h> | |
26 #include <string.h> | |
27 #include <errno.h> | |
28 | |
29 #include "pws-compat.h" | |
30 | |
31 void | |
32 vwarn(const char *fmt, va_list args) | |
33 { | |
34 int old_errno = errno; | |
35 | |
36 fprintf(stderr, "%s: ", getprogname()); | |
37 if (fmt != NULL) { | |
38 vfprintf(stderr, fmt, args); | |
39 fprintf(stderr, ": "); | |
40 } | |
41 fprintf(stderr, "%s\n", strerror(old_errno)); | |
42 errno = old_errno; | |
43 } | |
44 | |
45 void | |
46 vwarnx(const char *fmt, va_list args) | |
47 { | |
48 fprintf(stderr, "%s: ", getprogname()); | |
49 if (fmt != NULL) { | |
50 vfprintf(stderr, fmt, args); | |
51 } | |
52 fputc('\n', stderr); | |
53 } | |
54 | |
55 void | |
56 verr(int eval, const char *fmt, va_list args) | |
57 { | |
58 vwarn(fmt, args); | |
59 | |
60 exit(eval); | |
61 } | |
62 | |
63 void | |
64 verrx(int eval, const char *fmt, va_list args) | |
65 { | |
66 vwarnx(fmt, args); | |
67 | |
68 exit(eval); | |
69 } | |
70 | |
71 void | |
72 err(int eval, const char *fmt, ...) | |
73 { | |
74 va_list args; | |
75 | |
76 va_start(args, fmt); | |
77 vwarn(fmt, args); | |
78 va_end(args); | |
79 | |
80 exit(eval); | |
81 } | |
82 | |
83 void | |
84 errx(int eval, const char *fmt, ...) | |
85 { | |
86 va_list args; | |
87 | |
88 va_start(args, fmt); | |
89 vwarnx(fmt, args); | |
90 va_end(args); | |
91 | |
92 exit(eval); | |
93 } | |
94 | |
95 void | |
96 warn(const char *fmt, ...) | |
97 { | |
98 va_list args; | |
99 | |
100 va_start(args, fmt); | |
101 vwarn(fmt, args); | |
102 va_end(args); | |
103 } | |
104 | |
105 void | |
106 warnx(const char *fmt, ...) | |
107 { | |
108 va_list args; | |
109 | |
110 va_start(args, fmt); | |
111 vwarnx(fmt, args); | |
112 va_end(args); | |
113 } |