Put strcasecmp/strncasecmp on the banned list (except for needed calls
[jra/samba/.git] / source3 / lib / util_file.c
index e80267f84b5536fd2ebbcc2411308948398f4ed4..bd505ac921c37f0f89098da39677f4c646bf92e6 100644 (file)
 
 #include "includes.h"
 
+#ifndef MAP_FAILED
+#define MAP_FAILED ((void *)-1)
+#endif
+
+
 static int gotalarm;
 
 /***************************************************************
@@ -40,9 +45,10 @@ BOOL do_file_lock(int fd, int waitsecs, int type)
 {
   SMB_STRUCT_FLOCK lock;
   int             ret;
+  void (*oldsig_handler)(int);
 
   gotalarm = 0;
-  CatchSignal(SIGALRM, SIGNAL_CAST gotalarm_sig);
+  oldsig_handler = CatchSignal(SIGALRM, SIGNAL_CAST gotalarm_sig);
 
   lock.l_type = type;
   lock.l_whence = SEEK_SET;
@@ -51,9 +57,10 @@ BOOL do_file_lock(int fd, int waitsecs, int type)
   lock.l_pid = 0;
 
   alarm(waitsecs);
+  /* Note we must *NOT* use sys_fcntl here ! JRA */
   ret = fcntl(fd, SMB_F_SETLKW, &lock);
   alarm(0);
-  CatchSignal(SIGALRM, SIGNAL_CAST SIG_IGN);
+  CatchSignal(SIGALRM, SIGNAL_CAST oldsig_handler);
 
   if (gotalarm) {
     DEBUG(0, ("do_file_lock: failed to %s file.\n",
@@ -360,7 +367,7 @@ char *file_pload(char *syscmd, size_t *size)
        while ((n = read(fd, buf, sizeof(buf))) > 0) {
                tp = Realloc(p, total + n + 1);
                if (!tp) {
-                       DEBUG(0,("file_pload: failed to exand buffer!\n"));
+                       DEBUG(0,("file_pload: failed to expand buffer!\n"));
                        close(fd);
                        SAFE_FREE(p);
                        return NULL;
@@ -370,6 +377,9 @@ char *file_pload(char *syscmd, size_t *size)
        }
        if (p) p[total] = 0;
 
+       /* FIXME: Perhaps ought to check that the command completed
+        * successfully (returned 0); if not the data may be
+        * truncated. */
        sys_pclose(fd);
 
        if (size) *size = total;
@@ -448,9 +458,10 @@ void *map_file(char *fname, size_t size)
 #endif
        if (!p) {
                p = file_load(fname, &s2);
-               if (!p || s2 != size) {
-                       DEBUG(1,("incorrect size for %s - got %d expected %d\n",
-                                fname, s2, size));
+               if (!p) return NULL;
+               if (s2 != size) {
+                       DEBUG(1,("incorrect size for %s - got %lu expected %lu\n",
+                                fname, (unsigned long)s2, (unsigned long)size));
                        if (p) free(p);
                        return NULL;
                }
@@ -587,7 +598,7 @@ BOOL file_save(const char *fname, void *packet, size_t length)
        if (fd == -1) {
                return False;
        }
-       if (write(fd, packet, length) != length) {
+       if (write(fd, packet, length) != (size_t)length) {
                return False;
        }
        close(fd);