]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/lib/bsys.c
kes Add dynamic dll entry point for SHGetFolderPath to Win32 code.
[bacula/bacula] / bacula / src / lib / bsys.c
index 9b0dd5f6245de8b15abea274a1793cf0f46879b0..c35dde977061e5309dcd36e1e6cd5c0520597b86 100644 (file)
@@ -8,19 +8,32 @@
  *   Version $Id$
  */
 /*
-   Copyright (C) 2000-2006 Kern Sibbald
+   Bacula® - The Network Backup Solution
 
-   This program is free software; you can redistribute it and/or
-   modify it under the terms of the GNU General Public License
-   version 2 as amended with additional clauses defined in the
-   file LICENSE in the main source directory.
+   Copyright (C) 2000-2006 Free Software Foundation Europe e.V.
 
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
-   the file LICENSE for additional details.
+   The main author of Bacula is Kern Sibbald, with contributions from
+   many others, a complete list can be found in the file AUTHORS.
+   This program is Free Software; you can redistribute it and/or
+   modify it under the terms of version two of the GNU General Public
+   License as published by the Free Software Foundation plus additions
+   that are listed in the file LICENSE.
 
- */
+   This program is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+   General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+   02110-1301, USA.
+
+   Bacula® is a registered trademark of John Walker.
+   The licensor of Bacula is the Free Software Foundation Europe
+   (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
+   Switzerland, email:ftf@fsfeurope.org.
+*/
 
 
 #include "bacula.h"
@@ -176,12 +189,16 @@ int cstrlen(const char *str)
 
 
 
-#ifndef DEBUG
+#ifndef bmalloc
 void *bmalloc(size_t size)
 {
   void *buf;
 
+#ifdef SMARTALLOC
+  buf = sm_malloc(file, line, size);
+#else
   buf = malloc(size);
+#endif
   if (buf == NULL) {
      berrno be;
      Emsg1(M_ABORT, 0, _("Out of memory: ERR=%s\n"), be.strerror());
@@ -207,6 +224,18 @@ void *b_malloc(const char *file, int line, size_t size)
 }
 
 
+void bfree(void *buf)
+{
+#ifdef SMARTALLOC
+  sm_free(__FILE__, __LINE__, buf);
+#else
+  free(buf);
+#endif
+}
+
+
+
+
 void *brealloc (void *buf, size_t size)
 {
    buf = realloc(buf, size);
@@ -497,21 +526,6 @@ 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
  */
@@ -704,8 +718,8 @@ char *bfgets(char *s, int size, FILE *fd)
       do {
          errno = 0;
          ch = fgetc(fd);
-      } while (ch == -1 && (errno == EINTR || errno == EAGAIN));
-      if (ch == -1) {
+      } while (ch == EOF && ferror(fd) && (errno == EINTR || errno == EAGAIN));
+      if (ch == EOF) {
          if (i == 0) {
             return NULL;
          } else {
@@ -716,13 +730,10 @@ char *bfgets(char *s, int size, FILE *fd)
       *p = 0;
       if (ch == '\r') { /* Support for Mac/Windows file format */
          ch = fgetc(fd);
-         if (ch == '\n') { /* Windows (\r\n) */
-            *p++ = ch;
-            *p = 0;
-         }
-         else { /* Mac (\r only) */
+         if (ch != '\n') { /* Mac (\r only) */
             (void)ungetc(ch, fd); /* Push next character back to fd */
          }
+         p[-1] = '\n';
          break;
       }
       if (ch == '\n') {
@@ -743,3 +754,26 @@ void make_unique_filename(POOLMEM **name, int Id, char *what)
 {
    Mmsg(name, "%s/%s.%s.%d.tmp", working_directory, my_name, what, Id);
 }
+
+char *escape_filename(const char *file_path)
+{
+   if (file_path == NULL || strpbrk(file_path, "\"\\") == NULL) {
+      return NULL;
+   }
+
+   char *escaped_path = (char *)bmalloc(2 * (strlen(file_path) + 1));
+   char *cur_char = escaped_path;
+
+   while (*file_path) {
+      if (*file_path == '\\' || *file_path == '"') {
+         *cur_char++ = '\\';
+      }
+
+      *cur_char++ = *file_path++;
+   }
+
+   *cur_char = '\0';
+
+   return escaped_path;
+}
+