chiark / gitweb /
Fix builtin version msg.
[userv.git] / lib.h
1 /*
2  * userv - lib.c
3  * useful utility routines' imports and exports, used in daemon
4  *
5  * Copyright (C)1996-1997 Ian Jackson
6  *
7  * This is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with userv; if not, write to the Free Software
19  * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20  */
21
22 #ifndef LIB_H
23 #define LIB_H
24
25 char *xstrcat3save(const char *a, const char *b, const char *c);
26 char *xstrsave(const char *s);
27 char *xstrsubsave(const char *begin, int len);
28
29 void miscerror(const char *what) NONRETURNING;
30 void syscallerror(const char *what) NONRETURNING;
31 void *xmalloc(size_t s);
32 void *xrealloc(void *p, size_t s);
33 int makeroom(char **buffer, int *size, int needed);
34 /* makeroom returns -1 if needed was far too large; otherwise returns 0. */
35
36 /* It doesn't appear to be documented whether [v]snprintf put a null
37  * in if they overrun.  GNU libc does, but I don't want to rely on
38  * that.
39  * So here are some functions that always do, regardless - including
40  * versions of strcat and strcpy.  The ...nyt...cat functions take the
41  * maximum length of the resulting buffer as size parameter, rather
42  * than the maximum length of the added portion.
43  *
44  * So,
45  *   ...n...       specify copied length (inc. any null), may or may not null-terminate
46  *   ...ny...      specify copied length (inc. null) and always null-terminate
47  *   ...nyt...cat  specify total buffer length and always null-terminate
48  */
49
50 /* Function names best pronounced with a Russian accent. */
51 void vsnyprintf(char *buffer, size_t size, const char *fmt, va_list al);
52 void snyprintf(char *buffer, size_t size, const char *fmt, ...) PRINTFFORMAT(3,4);
53 void strnycpy(char *dest, const char *src, size_t size);
54
55 void vsnytprintfcat(char *buffer, size_t size, const char *fmt, va_list al);
56 void snytprintfcat(char *buffer, size_t size, const char *fmt, ...) PRINTFFORMAT(3,4);
57 void strnytcat(char *dest, const char *src, size_t size);
58
59 #endif /* LIB_H */