r23795: more v2->v3 conversion
[samba.git] / source4 / lib / replace / replace.c
index 048ea3a998473784ddffcd38870b05d98ab94bf7..1b4a82cb033765f284265e673c44f99b4f6a4931 100644 (file)
@@ -10,7 +10,7 @@
    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
-   version 2 of the License, or (at your option) any later version.
+   version 3 of the License, or (at your option) any later version.
 
    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -154,33 +154,6 @@ time_t rep_mktime(struct tm *t)
 #endif /* !HAVE_MKTIME */
 
 
-#ifndef HAVE_INNETGR
-#if defined(HAVE_SETNETGRENT) && defined(HAVE_GETNETGRENT) && defined(HAVE_ENDNETGRENT)
-/*
- * Search for a match in a netgroup. This replaces it on broken systems.
- */
-int rep_innetgr(const char *group, const char *host, const char *user, 
-                               const char *dom)
-{
-       char *hst, *usr, *dm;
-  
-       setnetgrent(group);
-       while (getnetgrent(&hst, &usr, &dm)) {
-               if (((host == 0) || (hst == 0) || !strcmp(host, hst)) &&
-                   ((user == 0) || (usr == 0) || !strcmp(user, usr)) &&
-                   ((dom == 0) || (dm == 0) || !strcmp(dom, dm))) {
-                       endnetgrent();
-                       return (1);
-               }
-       }
-       endnetgrent();
-       return (0);
-}
-#endif /* HAVE_SETNETGRENT HAVE_GETNETGRENT HAVE_ENDNETGRENT */
-#endif /* HAVE_INNETGR */
-
-
-
 #ifndef HAVE_INITGROUPS
 /****************************************************************************
  some systems don't have an initgroups call 
@@ -338,15 +311,15 @@ char *rep_inet_ntoa(struct in_addr ip)
 #endif
 
 #ifndef HAVE_SETLINEBUF
-int rep_setlinebuf(FILE *stream)
+void rep_setlinebuf(FILE *stream)
 {
-       return setvbuf(stream, (char *)NULL, _IOLBF, 0);
+       setvbuf(stream, (char *)NULL, _IOLBF, 0);
 }
 #endif /* HAVE_SETLINEBUF */
 
 #ifndef HAVE_VSYSLOG
 #ifdef HAVE_SYSLOG
-void rep_vsyslog (int facility_priority, char *format, va_list arglist)
+void rep_vsyslog (int facility_priority, const char *format, va_list arglist)
 {
        char *msg = NULL;
        vasprintf(&msg, format, arglist);
@@ -465,6 +438,10 @@ char *rep_mkdtemp(char *template)
 }
 #endif
 
+/*****************************************************************
+ Watch out: this is not thread safe.
+*****************************************************************/
+
 #ifndef HAVE_PREAD
 ssize_t rep_pread(int __fd, void *__buf, size_t __nbytes, off_t __offset)
 {
@@ -475,6 +452,10 @@ ssize_t rep_pread(int __fd, void *__buf, size_t __nbytes, off_t __offset)
 }
 #endif
 
+/*****************************************************************
+ Watch out: this is not thread safe.
+*****************************************************************/
+
 #ifndef HAVE_PWRITE
 ssize_t rep_pwrite(int __fd, const void *__buf, size_t __nbytes, off_t __offset)
 {
@@ -590,3 +571,54 @@ int rep_setenv(const char *name, const char *value, int overwrite)
 }
 #endif
 
+#ifndef HAVE_UNSETENV
+int rep_unsetenv(const char *name)
+{
+       extern char **environ;
+       size_t len = strlen(name);
+       size_t i, count;
+
+       if (environ == NULL || getenv(name) == NULL) {
+               return 0;
+       }
+
+       for (i=0;environ[i];i++) /* noop */ ;
+
+       count=i;
+       
+       for (i=0;i<count;) {
+               if (strncmp(environ[i], name, len) == 0 && environ[i][len] == '=') {
+                       /* note: we do _not_ free the old variable here. It is unsafe to 
+                          do so, as the pointer may not have come from malloc */
+                       memmove(&environ[i], &environ[i+1], (count-i)*sizeof(char *));
+                       count--;
+               } else {
+                       i++;
+               }
+       }
+
+       return 0;
+}
+#endif
+
+#ifndef HAVE_SOCKETPAIR
+int rep_socketpair(int d, int type, int protocol, int sv[2])
+{
+       if (d != AF_UNIX) {
+               errno = EAFNOSUPPORT;
+               return -1;
+       }
+
+       if (protocol != 0) {
+               errno = EPROTONOSUPPORT;
+               return -1;
+       }
+
+       if (type != SOCK_STREAM) {
+               errno = EOPNOTSUPP;
+               return -1;
+       }
+
+       return pipe(sv);
+}
+#endif