diff options
author | Mike Frysinger <vapier@gentoo.org> | 2008-12-31 07:08:47 -0500 |
---|---|---|
committer | Mike Frysinger <vapier@gentoo.org> | 2008-12-31 09:51:44 -0500 |
commit | 90e9c762d9b5dbeb8432f4992b6ba570baa732ca (patch) | |
tree | 9616340afe1056cfa28d32c8700370804a810917 /libsbutil/src | |
parent | libsbutil: drop remove() replacement (diff) | |
download | sandbox-90e9c762d9b5dbeb8432f4992b6ba570baa732ca.tar.gz sandbox-90e9c762d9b5dbeb8432f4992b6ba570baa732ca.tar.bz2 sandbox-90e9c762d9b5dbeb8432f4992b6ba570baa732ca.zip |
libsbutil: delete more unused code imported from rcscripts
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Diffstat (limited to 'libsbutil/src')
-rw-r--r-- | libsbutil/src/config.c | 68 | ||||
-rw-r--r-- | libsbutil/src/file.c | 191 | ||||
-rw-r--r-- | libsbutil/src/string.c | 13 |
3 files changed, 1 insertions, 271 deletions
diff --git a/libsbutil/src/config.c b/libsbutil/src/config.c index 7a2251a..b0284bf 100644 --- a/libsbutil/src/config.c +++ b/libsbutil/src/config.c @@ -156,71 +156,3 @@ _continue: return value; } - -char ** -rc_get_list_file (char **list, char *filename) -{ - rc_dynbuf_t *dynbuf = NULL; - char *buf = NULL; - char *tmp_p = NULL; - char *token = NULL; - - rc_errno_save (); - - if (!check_arg_str (filename)) - return NULL; - - dynbuf = rc_dynbuf_new_mmap_file (filename); - if (NULL == dynbuf) - return NULL; - - /* Make sure we do not get false positives below */ - rc_errno_clear (); - while (NULL != (buf = rc_dynbuf_read_line (dynbuf))) - { - tmp_p = buf; - - /* Strip leading spaces/tabs */ - while ((tmp_p[0] == ' ') || (tmp_p[0] == '\t')) - tmp_p++; - - /* Get entry - we do not want comments, and only the first word - * on a line is valid */ - token = strsep (&tmp_p, "# \t"); - if (check_str (token)) - { - tmp_p = xstrndup (token, strlen (token)); - if (NULL == tmp_p) - { - if (NULL != list) - str_list_free (list); - rc_dynbuf_free (dynbuf); - free (buf); - - return NULL; - } - - str_list_add_item (list, tmp_p, error); - } - - free (buf); - } - - /* rc_dynbuf_read_line() returned NULL with errno set */ - if ((NULL == buf) && (rc_errno_is_set ())) - { - DBG_MSG ("Failed to read line from dynamic buffer!\n"); -error: - if (NULL != list) - str_list_free (list); - rc_dynbuf_free (dynbuf); - - return NULL; - } - - rc_dynbuf_free (dynbuf); - - rc_errno_restore (); - - return list; -} diff --git a/libsbutil/src/file.c b/libsbutil/src/file.c index b9e87cc..4542ae5 100644 --- a/libsbutil/src/file.c +++ b/libsbutil/src/file.c @@ -10,6 +10,7 @@ #include "headers.h" #include "rcscripts/rcutil.h" +#include "rcscripts/util/str_list.h" bool rc_file_exists (const char *pathname) @@ -48,24 +49,6 @@ rc_is_file (const char *pathname, bool follow_link) } bool -rc_is_link (const char *pathname) -{ - struct stat buf; - int retval; - - if (!check_str (pathname)) - return false; - - retval = lstat (pathname, &buf); - if ((-1 != retval) && (S_ISLNK (buf.st_mode))) - retval = true; - else - retval = false; - - return retval; -} - -bool rc_is_dir (const char *pathname, bool follow_link) { struct stat buf; @@ -101,178 +84,6 @@ rc_get_size (const char *pathname, bool follow_link) return retval; } -time_t -rc_get_mtime (const char *pathname, bool follow_link) -{ - struct stat buf; - int retval; - - if (!check_str (pathname)) - return 0; - - retval = follow_link ? stat (pathname, &buf) : lstat (pathname, &buf); - if (-1 != retval) - retval = buf.st_mtime; - else - retval = 0; - - return retval; -} - -int -rc_mktree (const char *pathname, mode_t mode) -{ - char *temp_name = NULL; - char *temp_token = NULL; - char *token_p; - char *token; - int retval; - int lenght; - - if (!check_arg_str (pathname)) - return -1; - - /* Lenght of 'pathname' + extra for "./" if needed */ - lenght = strlen (pathname) + 2; - /* lenght + '\0' */ - temp_name = xmalloc (lenght + 1); - if (NULL == temp_name) - return -1; - - temp_token = xstrndup (pathname, strlen (pathname)); - if (NULL == temp_token) - goto error; - - token_p = temp_token; - - if (pathname[0] == '/') - temp_name[0] = '\0'; - else - /* If not an absolute path, make it local */ - strncpy (temp_name, ".", lenght); - - token = strsep (&token_p, "/"); - /* First token might be "", but that is OK as it will be when the - * pathname starts with '/' */ - while (NULL != token) - { - strncat (temp_name, "/", lenght - strlen (temp_name)); - strncat (temp_name, token, lenght - strlen (temp_name)); - - /* If it does not exist, create the dir. If it does exit, - * but is not a directory, we will catch it below. */ - if (!rc_file_exists (temp_name)) - { - retval = mkdir (temp_name, mode); - if (-1 == retval) - { - rc_errno_set (errno); - DBG_MSG ("Failed to create directory '%s'!\n", temp_name); - goto error; - } - /* Not a directory or symlink pointing to a directory */ - } - else if (!rc_is_dir (temp_name, true)) - { - rc_errno_set (ENOTDIR); - DBG_MSG ("Component in '%s' is not a directory!\n", temp_name); - goto error; - } - - do - { - token = strsep (&token_p, "/"); - /* The first "" was Ok, but rather skip double '/' after that */ - } - while ((NULL != token) && (0 == strlen (token))); - } - - free (temp_name); - free (temp_token); - - return 0; - -error: - free (temp_name); - free (temp_token); - - return -1; -} - -int -rc_rmtree (const char *pathname) -{ - char **dirlist = NULL; - int i = 0; - - if (!check_arg_str (pathname)) - return -1; - - if (!rc_file_exists (pathname)) - { - rc_errno_set (ENOENT); - DBG_MSG ("'%s' does not exist!\n", pathname); - return -1; - } - - if (!rc_is_dir (pathname, false)) - { - rc_errno_set (ENOTDIR); - DBG_MSG ("'%s' is not a directory!\n", pathname); - return -1; - } - - - dirlist = rc_ls_dir (pathname, true, false); - if ((NULL == dirlist) && (rc_errno_is_set ())) - { - /* Do not error out - caller should decide itself if it - * it is an issue */ - DBG_MSG ("Failed to ls_dir() directory '%s'!\n", pathname); - return -1; - } - - while ((NULL != dirlist) && (NULL != dirlist[i])) - { - /* If it is a directory, call rc_rmtree() again with - * it as argument */ - if (rc_is_dir (dirlist[i], false)) - { - if (-1 == rc_rmtree (dirlist[i])) - { - DBG_MSG ("Failed to rm_tree() directory '%s'!\n", dirlist[i]); - goto error; - } - } - - /* Now actually remove it. Note that if it was a directory, - * it should already be removed by above rc_rmtree() call */ - if ((rc_file_exists (dirlist[i]) && (-1 == remove (dirlist[i])))) - { - rc_errno_set (errno); - DBG_MSG ("Failed to remove() '%s'!\n", dirlist[i]); - goto error; - } - i++; - } - - str_list_free (dirlist); - - /* Now remove the parent */ - if (-1 == remove (pathname)) - { - rc_errno_set (errno); - DBG_MSG ("Failed to remove '%s'!\n", pathname); - goto error; - } - - return 0; -error: - str_list_free (dirlist); - - return -1; -} - char ** rc_ls_dir (const char *pathname, bool hidden, bool sort) { diff --git a/libsbutil/src/string.c b/libsbutil/src/string.c index e9db24b..71e7213 100644 --- a/libsbutil/src/string.c +++ b/libsbutil/src/string.c @@ -57,16 +57,3 @@ rc_strndup (const char *str, size_t size) return (char *) memcpy (new_str, str, len); } - -char * -rc_basename (const char *path) -{ - char *new_path = NULL; - - if (!check_arg_str (path)) - return NULL; - - /* Copied from glibc */ - new_path = strrchr (path, '/'); - return new_path ? new_path + 1 : (char *) path; -} |