]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/lib/bsys.c
Fix problem of accents with new Win32 code.
[bacula/bacula] / bacula / src / lib / bsys.c
index e15dcee1dcdfbf1c8652f3f396c00b91fca79b14..548ab97b2a6fbdb4ba562230f641f709ada893cd 100644 (file)
@@ -8,7 +8,7 @@
  *   Version $Id$
  */
 /*
-   Copyright (C) 2000-2005 Kern Sibbald
+   Copyright (C) 2000-2006 Kern Sibbald
 
    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License
@@ -113,6 +113,16 @@ char *bstrncat(char *dest, POOL_MEM &src, int maxlen)
    return dest;
 }
 
+/*
+ * Allows one or both pointers to be NULL
+ */
+bool bstrcmp(const char *s1, const char *s2)
+{
+   if (s1 == s2) return true;
+   if (s1 == NULL || s2 == NULL) return false;
+   return strcmp(s1, s2) == 0;
+}
+
 /*
  * Get character length of UTF-8 string
  *
@@ -173,7 +183,8 @@ void *bmalloc(size_t size)
 
   buf = malloc(size);
   if (buf == NULL) {
-     Emsg1(M_ABORT, 0, _("Out of memory: ERR=%s\n"), strerror(errno));
+     berrno be;
+     Emsg1(M_ABORT, 0, _("Out of memory: ERR=%s\n"), be.strerror());
   }
   return buf;
 }
@@ -189,7 +200,8 @@ void *b_malloc(const char *file, int line, size_t size)
   buf = malloc(size);
 #endif
   if (buf == NULL) {
-     e_msg(file, line, M_ABORT, 0, _("Out of memory: ERR=%s\n"), strerror(errno));
+     berrno be;
+     e_msg(file, line, M_ABORT, 0, _("Out of memory: ERR=%s\n"), be.strerror());
   }
   return buf;
 }
@@ -199,7 +211,8 @@ void *brealloc (void *buf, size_t size)
 {
    buf = realloc(buf, size);
    if (buf == NULL) {
-      Emsg1(M_ABORT, 0, _("Out of memory: ERR=%s\n"), strerror(errno));
+      berrno be;
+      Emsg1(M_ABORT, 0, _("Out of memory: ERR=%s\n"), be.strerror());
    }
    return buf;
 }
@@ -211,7 +224,8 @@ void *bcalloc (size_t size1, size_t size2)
 
    buf = calloc(size1, size2);
    if (buf == NULL) {
-      Emsg1(M_ABORT, 0, _("Out of memory: ERR=%s\n"), strerror(errno));
+      berrno be;
+      Emsg1(M_ABORT, 0, _("Out of memory: ERR=%s\n"), be.strerror());
    }
    return buf;
 }
@@ -482,6 +496,21 @@ static struct s_state_hdr state_hdr = {
    0
 };
 
+#ifdef HAVE_WIN32
+#undef open
+#undef read
+#undef write
+#undef lseek
+#undef close
+#undef O_BINARY 
+#define open _open
+#define read _read
+#define write _write
+#define lseek _lseeki64
+#define close _close
+#define O_BINARY _O_BINARY
+#endif
+
 /*
  * Open and read the state file for the daemon
  */
@@ -497,7 +526,7 @@ void read_state_file(char *dir, const char *progname, int port)
    Mmsg(&fname, "%s/%s.%d.state", dir, progname, port);
    /* If file exists, see what we have */
 // Dmsg1(10, "O_BINARY=%d\n", O_BINARY);
-   if ((sfd = open(fname, O_RDONLY|O_BINARY, 0)) < 0) {
+   if ((sfd = open(fname, O_RDONLY|O_BINARY)) < 0) {
       Dmsg3(010, "Could not open state file. sfd=%d size=%d: ERR=%s\n",
                     sfd, sizeof(hdr), strerror(errno));
       goto bail_out;
@@ -510,6 +539,7 @@ void read_state_file(char *dir, const char *progname, int port)
    if (hdr.version != state_hdr.version) {
       Dmsg2(010, "Bad hdr version. Wanted %d got %d\n",
          state_hdr.version, hdr.version);
+      goto bail_out;
    }
    hdr.id[13] = 0;
    if (strcmp(hdr.id, state_hdr.id) != 0) {
@@ -542,6 +572,7 @@ void write_state_file(char *dir, const char *progname, int port)
 
    Mmsg(&fname, "%s/%s.%d.state", dir, progname, port);
    /* Create new state file */
+   unlink(fname);
    if ((sfd = open(fname, O_CREAT|O_WRONLY|O_BINARY, 0640)) < 0) {
       berrno be;
       Dmsg2(000, "Could not create state file. %s ERR=%s\n", fname, be.strerror());
@@ -658,7 +689,7 @@ char *bfgets(char *s, int size, FILE *fd)
             *p = 0;
          }
          else { /* Mac (\r only) */
-            ungetc(ch, fd); /* Push next character back to fd */
+            (void)ungetc(ch, fd); /* Push next character back to fd */
          }
          break;
       }