]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
move mkdirpp code to util.c
authorMiroslav Lichvar <mlichvar@redhat.com>
Wed, 5 Aug 2015 14:30:20 +0000 (16:30 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Wed, 5 Aug 2015 16:07:39 +0000 (18:07 +0200)
Makefile.in
logging.c
mkdirpp.c [deleted file]
mkdirpp.h [deleted file]
sources.c
util.c
util.h

index c2784c407ff38a28df9f7765c98ce5219931923e..79be3c4c32d81ecdec3033c4f4e3571f9f541dfa 100644 (file)
@@ -38,7 +38,7 @@ DESTDIR=
 
 HASH_OBJ = @HASH_OBJ@
 
-OBJS = array.o cmdparse.o conf.o local.o logging.o main.o memory.o mkdirpp.o \
+OBJS = array.o cmdparse.o conf.o local.o logging.o main.o memory.o \
        reference.o regress.o rtc.o sched.o sources.o sourcestats.o stubs.o \
        sys.o smooth.o tempcomp.o util.o $(HASH_OBJ)
 
index 2aff130a7eb5b760d0861773bf98e17dee32e42d..37fb572adc0bda036e00e6d3a9ea0bb9d6487002 100644 (file)
--- a/logging.c
+++ b/logging.c
@@ -31,7 +31,6 @@
 
 #include "conf.h"
 #include "logging.h"
-#include "mkdirpp.h"
 #include "util.h"
 
 /* This is used by DEBUG_LOG macro */
@@ -307,7 +306,7 @@ LOG_CreateLogFileDir(void)
 
   logdir = CNF_GetLogDir();
 
-  if (!mkdir_and_parents(logdir)) {
+  if (!UTI_CreateDirAndParents(logdir)) {
     LOG(LOGS_ERR, LOGF_Logging, "Could not create directory %s", logdir);
   }
 }
diff --git a/mkdirpp.c b/mkdirpp.c
deleted file mode 100644 (file)
index ed4b23d..0000000
--- a/mkdirpp.c
+++ /dev/null
@@ -1,135 +0,0 @@
-/*
-  chronyd/chronyc - Programs for keeping computer clocks accurate.
-
- **********************************************************************
- * Copyright (C) Richard P. Curnow  1997-2002
- * 
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of version 2 of the GNU General Public License as
- * published by the Free Software Foundation.
- * 
- * 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.
- * 
- **********************************************************************
-
-  =======================================================================
-
-  A function for creating a directory and any parent directories that
-  don't exist.
-
-  */
-
-#include "config.h"
-
-#include "sysincl.h"
-
-#include "memory.h"
-#include "mkdirpp.h"
-
-static int
-do_dir(char *p)
-{
-  int status;
-  struct stat buf;
-
-#if defined(TEST)
-  fprintf(stderr, "do_dir(%s)\n", p);
-#endif
-
-  /* See if directory exists */
-  status = stat(p, &buf);
-
-  if (status < 0) {
-    if (errno == ENOENT) {
-      /* Try to create directory */
-      status = mkdir(p, 0755);
-      return status;
-    } else {
-      return status;
-    }
-  }
-
-  if (!S_ISDIR(buf.st_mode)) {
-    return -1;
-  }
-
-  return 0;
-}
-
-/* ================================================== */
-/* Return 0 if the directory couldn't be created, 1 if it could (or
-   already existed) */
-
-int
-mkdir_and_parents(const char *path)
-{
-  char *p;
-  int len;
-  int i, j, k, last;
-  len = strlen(path);
-
-  p = (char *)Malloc(1 + len);
-
-  i = k = 0;
-  while (1) {
-    p[i++] = path[k++];
-    
-    if (path[k] == '/' || !path[k]) {
-      p[i] = 0;
-
-      if (do_dir(p) < 0) {
-        Free(p);
-        return 0;
-      }
-
-      if (!path[k]) {
-        /* End of the string */
-        break;
-      }
-
-      /* check whether its a trailing / or group of / */
-      last = 1;
-      j = k+1;
-      while (path[j]) {
-        if (path[j] != '/') {
-          k = j - 1; /* Pick up a / into p[] thru the assignment at the top of the loop */
-          last = 0;
-          break;
-        }
-        j++;
-      }
-
-      if (last) {
-        break;
-      }
-    }
-
-    if (!path[k]) break;
-
-  }  
-
-  Free(p);
-  return 1;
-
-}
-
-/* ================================================== */
-
-#if defined(TEST)
-int main(int argc, char **argv) {
-  if (argc > 1) {
-    /* Invert sense of result */
-    return mkdir_and_parents(argv[1]) ? 0 : 1;
-  } else {
-    return 1;
-  }
-}
-#endif
-                                  
diff --git a/mkdirpp.h b/mkdirpp.h
deleted file mode 100644 (file)
index 5304833..0000000
--- a/mkdirpp.h
+++ /dev/null
@@ -1,31 +0,0 @@
-/* 
-  chronyd/chronyc - Programs for keeping computer clocks accurate.
-
- **********************************************************************
- * Copyright (C) Richard P. Curnow  1997-2002
- * 
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of version 2 of the GNU General Public License as
- * published by the Free Software Foundation.
- * 
- * 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.
- * 
- **********************************************************************
-
-  =======================================================================
-
-   */
-
-#ifndef GOT_MKDIRPP_H
-#define GOT_MKDIRPP_H
-
-extern int mkdir_and_parents(const char *path);
-
-#endif
index c6a67c57a3574564d50bb1ee87a864121768e905..8ae1e6c9539112ee05406c02b09d34499ad21556 100644 (file)
--- a/sources.c
+++ b/sources.c
@@ -44,7 +44,6 @@
 #include "logging.h"
 #include "reports.h"
 #include "nameserv.h"
-#include "mkdirpp.h"
 #include "sched.h"
 #include "regress.h"
 
@@ -1093,7 +1092,7 @@ SRC_DumpSources(void)
   direc_len = strlen(direc);
   file_len = direc_len + 24;
   filename = MallocArray(char, file_len); /* a bit of slack */
-  if (mkdir_and_parents(direc)) {
+  if (UTI_CreateDirAndParents(direc)) {
     for (i=0; i<n_sources; i++) {
       a = (sources[i]->ref_id) >> 24;
       b = ((sources[i]->ref_id) >> 16) & 0xff;
diff --git a/util.c b/util.c
index 7bee7f064f24b133fe2e68576874954e2feedb33..82bb46a1e8f05c9cf4cf6c40f0ca9d110e5e6e73 100644 (file)
--- a/util.c
+++ b/util.c
@@ -29,6 +29,7 @@
 
 #include "sysincl.h"
 
+#include "memory.h"
 #include "util.h"
 #include "hash.h"
 
@@ -892,3 +893,83 @@ UTI_SetQuitSignalsHandler(void (*handler)(int))
 
   return 1;
 }
+
+/* ================================================== */
+
+static int
+create_dir(char *p)
+{
+  int status;
+  struct stat buf;
+
+  /* See if directory exists */
+  status = stat(p, &buf);
+
+  if (status < 0) {
+    if (errno == ENOENT) {
+      /* Try to create directory */
+      status = mkdir(p, 0755);
+      return status;
+    } else {
+      return status;
+    }
+  }
+
+  if (!S_ISDIR(buf.st_mode)) {
+    return -1;
+  }
+
+  return 0;
+}
+
+/* ================================================== */
+/* Return 0 if the directory couldn't be created, 1 if it could (or
+   already existed) */
+int
+UTI_CreateDirAndParents(const char *path)
+{
+  char *p;
+  int i, j, k, last;
+
+  p = (char *)Malloc(1 + strlen(path));
+
+  i = k = 0;
+  while (1) {
+    p[i++] = path[k++];
+
+    if (path[k] == '/' || !path[k]) {
+      p[i] = 0;
+
+      if (create_dir(p) < 0) {
+        Free(p);
+        return 0;
+      }
+
+      if (!path[k]) {
+        /* End of the string */
+        break;
+      }
+
+      /* Check whether its a trailing / or group of / */
+      last = 1;
+      j = k + 1;
+      while (path[j]) {
+        if (path[j] != '/') {
+          k = j - 1; /* Pick up a / into p[] thru the assignment at the top of the loop */
+          last = 0;
+          break;
+        }
+        j++;
+      }
+
+      if (last)
+        break;
+    }
+
+    if (!path[k])
+      break;
+  }
+
+  Free(p);
+  return 1;
+}
diff --git a/util.h b/util.h
index 11ffb16c12e2ab0ca74d9cb4f8667ee87ec5bc29..a01b7aa8a0aa408a151a48d65f91031088f65d5e 100644 (file)
--- a/util.h
+++ b/util.h
@@ -130,4 +130,7 @@ extern int UTI_DecodePasswordFromText(char *key);
 
 extern int UTI_SetQuitSignalsHandler(void (*handler)(int));
 
+/* Create a directory and any parent directories that don't exist */
+extern int UTI_CreateDirAndParents(const char *path);
+
 #endif /* GOT_UTIL_H */