chiark / gitweb /
debian/control: Add missing build-dependency on flex. Fixes FTBFS. Report from Aurel...
[userv.git] / lib.h
1 /*
2  * userv - lib.c
3  * useful utility routines' imports and exports, used in daemon
4  *
5  * userv is
6  * Copyright 1996-2017 Ian Jackson <ian@davenant.greenend.org.uk>.
7  * Copyright 2000      Ben Harris <bjh21@cam.ac.uk>
8  * Copyright 2016-2017 Peter Benie <pjb1008@cam.ac.uk>
9  *
10  * This is free software; you can redistribute it and/or modify it
11  * under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful, but
16  * WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18  * General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with userv; if not, see <http://www.gnu.org/licenses/>.
22  */
23
24 #ifndef LIB_H
25 #define LIB_H
26
27 char *xstrcat3save(const char *a, const char *b, const char *c);
28 char *xstrsubsave(const char *begin, int len);
29
30 void miscerror(const char *what) NONRETURNING;
31 int makeroom(char **buffer, int *size, int needed);
32 /* makeroom returns -1 if needed was far too large; otherwise returns 0. */
33
34 /* It doesn't appear to be documented whether [v]snprintf put a null
35  * in if they overrun.  GNU libc does, but I don't want to rely on
36  * that.
37  * So here are some functions that always do, regardless - including
38  * versions of strcat and strcpy.  The ...nyt...cat functions take the
39  * maximum length of the resulting buffer as size parameter, rather
40  * than the maximum length of the added portion.
41  *
42  * So,
43  *   ...n...       specify copied length (inc. any null), may or may not null-terminate
44  *   ...ny...      specify copied length (inc. null) and always null-terminate
45  *   ...nyt...cat  specify total buffer length and always null-terminate
46  */
47
48 /* Function names best pronounced with a Russian accent. */
49 void vsnyprintf(char *buffer, size_t size, const char *fmt, va_list al);
50 void snyprintf(char *buffer, size_t size, const char *fmt, ...) PRINTFFORMAT(3,4);
51 void strnycpy(char *dest, const char *src, size_t size);
52
53 void vsnytprintfcat(char *buffer, size_t size, const char *fmt, va_list al);
54 void snytprintfcat(char *buffer, size_t size, const char *fmt, ...) PRINTFFORMAT(3,4);
55 void strnytcat(char *dest, const char *src, size_t size);
56
57 #ifndef HAVE_SETENV
58 int setenv(const char *name, const char *value, int overwrite);
59 #endif /* HAVE_SETENV */
60
61 #endif /* LIB_H */