WHATSNEW: Update release date.
[Samba/gbeck.git] / source4 / heimdal_build / replace.c
blob41309fea6eccaf94f7d62808b8d322098af6465e
1 /*
2 Unix SMB/CIFS implementation.
4 some replacement functions for parts of roken that don't fit easily into
5 our build system
7 Copyright (C) Andrew Tridgell 2005
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.
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.
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/>.
23 #include "config.h"
24 #include <stdio.h>
25 #include <unistd.h>
26 #include <fcntl.h>
27 #include "err.h"
28 #include "roken.h"
30 #ifndef HAVE_ERR
31 void err(int eval, const char *format, ...)
33 va_list ap;
34 va_start(ap, format);
35 vfprintf(stderr, format, ap);
36 perror("");
37 va_end(ap);
38 exit(eval);
40 #endif
42 #ifndef HAVE_ERRX
43 void errx(int eval, const char *format, ...)
45 va_list ap;
46 va_start(ap, format);
47 vfprintf(stderr, format, ap);
48 va_end(ap);
49 exit(eval);
51 #endif
53 #ifndef HAVE_WARNX
54 void warnx(const char *format, ...)
56 va_list ap;
57 va_start(ap, format);
58 vfprintf(stderr, format, ap);
59 va_end(ap);
61 #endif
63 #ifndef HAVE_FLOCK
64 int flock(int fd, int op)
66 struct flock lock;
67 lock.l_whence = 0;
68 lock.l_start = 0;
69 lock.l_len = 0;
70 lock.l_pid = 0;
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);
83 errno = EINVAL;
84 return -1;
86 #endif