3 * useful utility routines, used in daemon, but not very dependent on it
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>
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.
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.
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/>.
31 #include <sys/types.h>
38 char *xstrcat3save(const char *a, const char *b, const char *c) {
41 r= xmalloc(strlen(a)+strlen(b)+strlen(c)+1);
48 char *xstrsubsave(const char *begin, int len) {
57 int makeroom(char **buffer, int *size, int needed) {
58 if (needed > MAX_GENERAL_STRING) return -1;
59 if (*size >= needed) return 0;
60 *buffer= xrealloc(*buffer,needed);
65 void vsnyprintf(char *buffer, size_t size, const char *fmt, va_list al) {
66 vsnprintf(buffer,size,fmt,al);
70 void snyprintf(char *buffer, size_t size, const char *fmt, ...) {
73 vsnyprintf(buffer,size,fmt,al);
77 void strnycpy(char *dest, const char *src, size_t size) {
78 strncpy(dest,src,size-1);
82 void strnytcat(char *dest, const char *src, size_t size) {
85 strnycpy(dest+l,src,size-l);
88 void vsnytprintfcat(char *buffer, size_t size, const char *fmt, va_list al) {
91 vsnyprintf(buffer+l,size-l,fmt,al);
94 void snytprintfcat(char *buffer, size_t size, const char *fmt, ...) {
97 vsnytprintfcat(buffer,size,fmt,al);
102 int setenv(const char *name, const char *value, int overwrite) {
105 assert(overwrite==1);
106 buffer= xmalloc(strlen(name)+strlen(value)+2);
108 sprintf(buffer,"%s=%s",name,value);
109 return putenv(buffer);
111 #endif /* HAVE_SETENV */