3 * useful utility routines, used in daemon, but not very dependent on it
5 * Copyright (C)1996-1997 Ian Jackson
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.
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.
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.
28 #include <sys/types.h>
34 char *xstrcat3save(const char *a, const char *b, const char *c) {
37 r= xmalloc(strlen(a)+strlen(b)+strlen(c)+1);
44 char *xstrsave(const char *s) {
47 r= xmalloc(strlen(s)+1);
52 char *xstrsubsave(const char *begin, int len) {
61 void *xmalloc(size_t s) {
63 p= malloc(s?s:1); if (!p) syscallerror("malloc");
67 void *xrealloc(void *p, size_t s) {
68 p= realloc(p,s); if (!p) syscallerror("realloc");
72 int makeroom(char **buffer, int *size, int needed) {
73 if (needed > MAX_GENERAL_STRING) return -1;
74 if (*size >= needed) return 0;
75 *buffer= xrealloc(*buffer,needed);
80 void vsnyprintf(char *buffer, size_t size, const char *fmt, va_list al) {
81 vsnprintf(buffer,size,fmt,al);
85 void snyprintf(char *buffer, size_t size, const char *fmt, ...) {
88 vsnyprintf(buffer,size,fmt,al);
92 void strnycpy(char *dest, const char *src, size_t size) {
93 strncpy(dest,src,size-1);
97 void strnytcat(char *dest, const char *src, size_t size) {
100 strnycpy(dest+l,src,size-l);
103 void vsnytprintfcat(char *buffer, size_t size, const char *fmt, va_list al) {
106 vsnyprintf(buffer+l,size-l,fmt,al);
109 void snytprintfcat(char *buffer, size_t size, const char *fmt, ...) {
112 vsnytprintfcat(buffer,size,fmt,al);