/* [<][>][^][v][top][bottom][index][help] */
DEFINITIONS
This source file includes following definitions.
- err
- errx
- warnx
- flock
1 /*
2 Unix SMB/CIFS implementation.
3
4 some replacement functions for parts of roken that don't fit easily into
5 our build system
6
7 Copyright (C) Andrew Tridgell 2005
8
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23 #include "config.h"
24 #include <stdio.h>
25 #include <unistd.h>
26 #include <fcntl.h>
27 #include "err.h"
28 #include "roken.h"
29
30 #ifndef HAVE_ERR
31 void err(int eval, const char *format, ...)
/* [<][>][^][v][top][bottom][index][help] */
32 {
33 va_list ap;
34 va_start(ap, format);
35 vfprintf(stderr, format, ap);
36 perror("");
37 va_end(ap);
38 exit(eval);
39 }
40 #endif
41
42 #ifndef HAVE_ERRX
43 void errx(int eval, const char *format, ...)
/* [<][>][^][v][top][bottom][index][help] */
44 {
45 va_list ap;
46 va_start(ap, format);
47 vfprintf(stderr, format, ap);
48 va_end(ap);
49 exit(eval);
50 }
51 #endif
52
53 #ifndef HAVE_WARNX
54 void warnx(const char *format, ...)
/* [<][>][^][v][top][bottom][index][help] */
55 {
56 va_list ap;
57 va_start(ap, format);
58 vfprintf(stderr, format, ap);
59 va_end(ap);
60 }
61 #endif
62
63 #ifndef HAVE_FLOCK
64 int flock(int fd, int op)
/* [<][>][^][v][top][bottom][index][help] */
65 {
66 struct flock lock;
67 lock.l_whence = 0;
68 lock.l_start = 0;
69 lock.l_len = 0;
70 lock.l_pid = 0;
71
72 switch (op & (LOCK_UN|LOCK_SH|LOCK_EX)) {
73 case LOCK_UN:
74 lock.l_type = F_UNLCK;
75 return fcntl(fd, F_SETLK, &lock);
76 case LOCK_SH:
77 lock.l_type = F_RDLCK;
78 return fcntl(fd, (op&LOCK_NB)?F_SETLK:F_SETLKW, &lock);
79 case LOCK_EX:
80 lock.l_type = F_WRLCK;
81 return fcntl(fd, (op&LOCK_NB)?F_SETLK:F_SETLKW, &lock);
82 }
83 errno = EINVAL;
84 return -1;
85 }
86 #endif