lib: Separate out xx_path() & callers
authorVolker Lendecke <vl@samba.org>
Sun, 13 Dec 2015 15:32:52 +0000 (16:32 +0100)
committerJeremy Allison <jra@samba.org>
Mon, 14 Dec 2015 19:23:13 +0000 (20:23 +0100)
We should not have to #include proto.h just for cache_path() or so

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/include/proto.h
source3/lib/util.c
source3/lib/util_path.c [new file with mode: 0644]
source3/lib/util_path.h [new file with mode: 0644]
source3/wscript_build

index eeee40250c6a8adf5ad9d0fd3453fa55d33f2de5..1470b6d09fef7d3c4bc2542d2e76cea1a9488673 100644 (file)
@@ -400,9 +400,7 @@ int smb_mkstemp(char *name_template);
 void *smb_xmalloc_array(size_t size, unsigned int count);
 char *myhostname(void);
 char *myhostname_upper(void);
-char *lock_path(const char *name);
-char *state_path(const char *name);
-char *cache_path(const char *name);
+#include "lib/util_path.h"
 bool parent_dirname(TALLOC_CTX *mem_ctx, const char *dir, char **parent,
                    const char **name);
 bool ms_has_wild(const char *s);
index 320fdc2e0e49b2916564fae315edaea760b41ea0..303fa8b4bc64910439cda631762d9f3d85bdc372 100644 (file)
@@ -1496,71 +1496,6 @@ char *myhostname_upper(void)
        return ret;
 }
 
-/**
- * @brief Returns an absolute path to a file concatenating the provided
- * @a rootpath and @a basename
- *
- * @param name Filename, relative to @a rootpath
- *
- * @retval Pointer to a string containing the full path.
- **/
-
-static char *xx_path(const char *name, const char *rootpath)
-{
-       char *fname = NULL;
-
-       fname = talloc_strdup(talloc_tos(), rootpath);
-       if (!fname) {
-               return NULL;
-       }
-       trim_string(fname,"","/");
-
-       if (!directory_create_or_exist(fname, 0755)) {
-               return NULL;
-       }
-
-       return talloc_asprintf_append(fname, "/%s", name);
-}
-
-/**
- * @brief Returns an absolute path to a file in the Samba lock directory.
- *
- * @param name File to find, relative to LOCKDIR.
- *
- * @retval Pointer to a talloc'ed string containing the full path.
- **/
-
-char *lock_path(const char *name)
-{
-       return xx_path(name, lp_lock_directory());
-}
-
-/**
- * @brief Returns an absolute path to a file in the Samba state directory.
- *
- * @param name File to find, relative to STATEDIR.
- *
- * @retval Pointer to a talloc'ed string containing the full path.
- **/
-
-char *state_path(const char *name)
-{
-       return xx_path(name, lp_state_directory());
-}
-
-/**
- * @brief Returns an absolute path to a file in the Samba cache directory.
- *
- * @param name File to find, relative to CACHEDIR.
- *
- * @retval Pointer to a talloc'ed string containing the full path.
- **/
-
-char *cache_path(const char *name)
-{
-       return xx_path(name, lp_cache_directory());
-}
-
 /*******************************************************************
  Given a filename - get its directory name
 ********************************************************************/
diff --git a/source3/lib/util_path.c b/source3/lib/util_path.c
new file mode 100644 (file)
index 0000000..509ba5f
--- /dev/null
@@ -0,0 +1,95 @@
+/*
+ * Unix SMB/CIFS implementation.
+ * Samba utility functions
+ * Copyright (C) Andrew Tridgell 1992-1998
+ * Copyright (C) Jeremy Allison 2001-2007
+ * Copyright (C) Simo Sorce 2001
+ * Copyright (C) Jim McDonough <jmcd@us.ibm.com> 2003
+ * Copyright (C) James Peach 2006
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "replace.h"
+#include <talloc.h>
+#include "lib/util/samba_util.h"
+#include "lib/util_path.h"
+
+struct share_params;
+#include "source3/param/param_proto.h"
+
+/**
+ * @brief Returns an absolute path to a file concatenating the provided
+ * @a rootpath and @a basename
+ *
+ * @param name Filename, relative to @a rootpath
+ *
+ * @retval Pointer to a string containing the full path.
+ **/
+
+static char *xx_path(const char *name, const char *rootpath)
+{
+       char *fname = NULL;
+
+       fname = talloc_strdup(talloc_tos(), rootpath);
+       if (!fname) {
+               return NULL;
+       }
+       trim_string(fname,"","/");
+
+       if (!directory_create_or_exist(fname, 0755)) {
+               return NULL;
+       }
+
+       return talloc_asprintf_append(fname, "/%s", name);
+}
+
+/**
+ * @brief Returns an absolute path to a file in the Samba lock directory.
+ *
+ * @param name File to find, relative to LOCKDIR.
+ *
+ * @retval Pointer to a talloc'ed string containing the full path.
+ **/
+
+char *lock_path(const char *name)
+{
+       return xx_path(name, lp_lock_directory());
+}
+
+/**
+ * @brief Returns an absolute path to a file in the Samba state directory.
+ *
+ * @param name File to find, relative to STATEDIR.
+ *
+ * @retval Pointer to a talloc'ed string containing the full path.
+ **/
+
+char *state_path(const char *name)
+{
+       return xx_path(name, lp_state_directory());
+}
+
+/**
+ * @brief Returns an absolute path to a file in the Samba cache directory.
+ *
+ * @param name File to find, relative to CACHEDIR.
+ *
+ * @retval Pointer to a talloc'ed string containing the full path.
+ **/
+
+char *cache_path(const char *name)
+{
+       return xx_path(name, lp_cache_directory());
+}
diff --git a/source3/lib/util_path.h b/source3/lib/util_path.h
new file mode 100644 (file)
index 0000000..118a4be
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * Unix SMB/CIFS implementation.
+ * Samba utility functions
+ * Copyright (C) Andrew Tridgell 1992-1998
+ * Copyright (C) Jeremy Allison 2001-2007
+ * Copyright (C) Simo Sorce 2001
+ * Copyright (C) Jim McDonough <jmcd@us.ibm.com> 2003
+ * Copyright (C) James Peach 2006
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __LIB_UTIL_PATH_H__
+#define __LIB_UTIL_PATH_H__
+
+char *lock_path(const char *name);
+char *state_path(const char *name);
+char *cache_path(const char *name);
+
+#endif
index e66e89fa79837755e4c52f6b288cb794b462e24c..d40dd7edd3f9e450b2e84cc130fba053a040c4ef 100755 (executable)
@@ -255,6 +255,7 @@ bld.SAMBA3_SUBSYSTEM('samba3util',
                    lib/util_sid.c
                    lib/util_file.c
                    lib/util.c
+                   lib/util_path.c
                    lib/util_procid.c
                    lib/util_sock.c
                    lib/util_tsock.c