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.
32 char *xmstrcat3save(const char *a, const char *b, const char *c) {
35 r= xmalloc(strlen(a)+strlen(b)+strlen(c)+1);
42 char *xmstrsave(const char *s) {
45 r= xmalloc(strlen(s)+1);
50 char *xmstrsubsave(const char *begin, int len) {
59 void *xmalloc(size_t s) {
61 p= malloc(s?s:1); if (!p) syscallerror("malloc");
65 void *xrealloc(void *p, size_t s) {
66 p= realloc(p,s); if (!p) syscallerror("realloc");
70 char *xstrdup(const char *str) {
72 r= xmalloc(strlen(str)+1);
73 strcpy(r,str); return r;
76 void makeroom(char **buffer, int *size, int needed) {
77 if (*size >= needed) return;
78 *buffer= xrealloc(*buffer,needed);
82 void vsnyprintf(char *buffer, size_t size, const char *fmt, va_list al) {
83 vsnprintf(buffer,size,fmt,al);
87 void snyprintf(char *buffer, size_t size, const char *fmt, ...) {
90 vsnyprintf(buffer,size,fmt,al);
94 void strnycpy(char *dest, const char *src, size_t size) {
95 strncpy(dest,src,size-1);
99 void strnytcat(char *dest, const char *src, size_t size) {
102 strnycpy(dest+l,src,size-l);
105 void vsnytprintfcat(char *buffer, size_t size, const char *fmt, va_list al) {
108 vsnyprintf(buffer+l,size-l,fmt,al);
111 void snytprintfcat(char *buffer, size_t size, const char *fmt, ...) {
114 vsnytprintfcat(buffer,size,fmt,al);