3 * useful utility routines, used in daemon, but not very dependent on it
5 * Copyright (C)1996-1997,1999 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.
29 #include <sys/types.h>
36 char *xstrcat3save(const char *a, const char *b, const char *c) {
39 r= xmalloc(strlen(a)+strlen(b)+strlen(c)+1);
46 char *xstrsubsave(const char *begin, int len) {
55 int makeroom(char **buffer, int *size, int needed) {
56 if (needed > MAX_GENERAL_STRING) return -1;
57 if (*size >= needed) return 0;
58 *buffer= xrealloc(*buffer,needed);
63 void vsnyprintf(char *buffer, size_t size, const char *fmt, va_list al) {
64 vsnprintf(buffer,size,fmt,al);
68 void snyprintf(char *buffer, size_t size, const char *fmt, ...) {
71 vsnyprintf(buffer,size,fmt,al);
75 void strnycpy(char *dest, const char *src, size_t size) {
76 strncpy(dest,src,size-1);
80 void strnytcat(char *dest, const char *src, size_t size) {
83 strnycpy(dest+l,src,size-l);
86 void vsnytprintfcat(char *buffer, size_t size, const char *fmt, va_list al) {
89 vsnyprintf(buffer+l,size-l,fmt,al);
92 void snytprintfcat(char *buffer, size_t size, const char *fmt, ...) {
95 vsnytprintfcat(buffer,size,fmt,al);
100 int setenv(const char *name, const char *value, int overwrite) {
103 assert(overwrite==1);
104 buffer= xmalloc(strlen(name)+strlen(value)+2);
106 sprintf(buffer,"%s=%s",name,value);
107 return putenv(buffer);
109 #endif /* HAVE_SETENV */