chiark / gitweb /
debian/control: Add missing build-dependency on flex. Fixes FTBFS. Report from Aurel...
[userv.git] / lib.c
diff --git a/lib.c b/lib.c
index 4af9b804dae2a26a22885eb29735025b97564953..8b31ec9be1a81e09ce282c8e6b80d09682798eff 100644 (file)
--- a/lib.c
+++ b/lib.c
@@ -2,11 +2,12 @@
  * userv - lib.c
  * useful utility routines, used in daemon, but not very dependent on it
  *
  * userv - lib.c
  * useful utility routines, used in daemon, but not very dependent on it
  *
- * Copyright (C)1996-1997 Ian Jackson
+ * userv is copyright Ian Jackson and other contributors.
+ * See README for full authorship information.
  *
  * This is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License as published by
  *
  * This is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * the Free Software Foundation; either version 3 of the License, or
  * (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful, but
  * (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful, but
@@ -15,8 +16,7 @@
  * General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
  * General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
- * along with userv; if not, write to the Free Software
- * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * along with userv; if not, see <http://www.gnu.org/licenses/>.
  */
 
 #include <errno.h>
  */
 
 #include <errno.h>
 #include <stdarg.h>
 #include <stdio.h>
 #include <string.h>
 #include <stdarg.h>
 #include <stdio.h>
 #include <string.h>
+#include <assert.h>
+#include <sys/types.h>
 
 #include "config.h"
 
 #include "config.h"
+#include "common.h"
 #include "lib.h"
 #include "lib.h"
+#include "both.h"
 
 
-char *xmstrcat3save(const char *a, const char *b, const char *c) {
+char *xstrcat3save(const char *a, const char *b, const char *c) {
   char *r;
 
   r= xmalloc(strlen(a)+strlen(b)+strlen(c)+1);
   char *r;
 
   r= xmalloc(strlen(a)+strlen(b)+strlen(c)+1);
@@ -39,15 +43,7 @@ char *xmstrcat3save(const char *a, const char *b, const char *c) {
   return r;
 }
 
   return r;
 }
 
-char *xmstrsave(const char *s) {
-  char *r;
-
-  r= xmalloc(strlen(s)+1);
-  strcpy(r,s);
-  return r;
-}
-
-char *xmstrsubsave(const char *begin, int len) {
+char *xstrsubsave(const char *begin, int len) {
   char *r;
   
   r= xmalloc(len+1);
   char *r;
   
   r= xmalloc(len+1);
@@ -56,27 +52,12 @@ char *xmstrsubsave(const char *begin, int len) {
   return r;
 }
 
   return r;
 }
 
-void *xmalloc(size_t s) {
-  void *p;
-  p= malloc(s?s:1); if (!p) syscallerror("malloc");
-  return p;
-}
-
-void *xrealloc(void *p, size_t s) {
-  p= realloc(p,s); if (!p) syscallerror("realloc");
-  return p;
-}
-
-char *xstrdup(const char *str) {
-  char *r;
-  r= xmalloc(strlen(str)+1);
-  strcpy(r,str); return r;
-}
-
-void makeroom(char **buffer, int *size, int needed) {
-  if (*size >= needed) return;
+int makeroom(char **buffer, int *size, int needed) {
+  if (needed > MAX_GENERAL_STRING) return -1;
+  if (*size >= needed) return 0;
   *buffer= xrealloc(*buffer,needed);
   *size= needed;
   *buffer= xrealloc(*buffer,needed);
   *size= needed;
+  return 0;
 }
 
 void vsnyprintf(char *buffer, size_t size, const char *fmt, va_list al) {
 }
 
 void vsnyprintf(char *buffer, size_t size, const char *fmt, va_list al) {
@@ -114,3 +95,15 @@ void snytprintfcat(char *buffer, size_t size, const char *fmt, ...) {
   vsnytprintfcat(buffer,size,fmt,al);
   va_end(al);
 }
   vsnytprintfcat(buffer,size,fmt,al);
   va_end(al);
 }
+
+#ifndef HAVE_SETENV
+int setenv(const char *name, const char *value, int overwrite) {
+  char *buffer= 0;
+  
+  assert(overwrite==1);
+  buffer= xmalloc(strlen(name)+strlen(value)+2);
+
+  sprintf(buffer,"%s=%s",name,value);
+  return putenv(buffer);
+}
+#endif /* HAVE_SETENV */