]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/lib/bsys.c
Ignore UTF-8 marker at the start of .conf files.
[bacula/bacula] / bacula / src / lib / bsys.c
index aa2be79c06b8cef4009eaa0a1c130e45d6b0c6bb..2869a3fa299e22d46c8f1067351b475c07e75fb2 100644 (file)
@@ -176,12 +176,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 +211,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);
@@ -728,3 +744,27 @@ 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;
+}
+
+