aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Frysinger <vapier@gentoo.org>2008-12-31 07:08:47 -0500
committerMike Frysinger <vapier@gentoo.org>2008-12-31 09:51:44 -0500
commit90e9c762d9b5dbeb8432f4992b6ba570baa732ca (patch)
tree9616340afe1056cfa28d32c8700370804a810917 /libsbutil
parentlibsbutil: drop remove() replacement (diff)
downloadsandbox-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')
-rw-r--r--libsbutil/Makefile.am2
-rw-r--r--libsbutil/include/rcscripts/rctypes.h24
-rw-r--r--libsbutil/include/rcscripts/rcutil.h5
-rw-r--r--libsbutil/include/rcscripts/util/config.h1
-rw-r--r--libsbutil/include/rcscripts/util/file.h13
-rw-r--r--libsbutil/include/rcscripts/util/list.h444
-rw-r--r--libsbutil/include/rcscripts/util/string.h2
-rw-r--r--libsbutil/src/config.c68
-rw-r--r--libsbutil/src/file.c191
-rw-r--r--libsbutil/src/string.c13
10 files changed, 3 insertions, 760 deletions
diff --git a/libsbutil/Makefile.am b/libsbutil/Makefile.am
index ea86462..e4de53f 100644
--- a/libsbutil/Makefile.am
+++ b/libsbutil/Makefile.am
@@ -24,9 +24,7 @@ libsbutil_la_SOURCES = \
sb_write.c \
sb_close.c \
sb_printf.c \
- include/rcscripts/rctypes.h \
include/rcscripts/rcutil.h \
- include/rcscripts/util/list.h \
include/rcscripts/util/str_list.h \
include/rcscripts/util/debug.h \
src/debug.c \
diff --git a/libsbutil/include/rcscripts/rctypes.h b/libsbutil/include/rcscripts/rctypes.h
deleted file mode 100644
index 8a6002e..0000000
--- a/libsbutil/include/rcscripts/rctypes.h
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * rctypes.h
- *
- * Misc types and macro's.
- *
- * Copyright 1999-2008 Gentoo Foundation
- * Copyright 2004-2007 Martin Schlemmer <azarah@nosferatu.za.org>
- * Licensed under the GPL-2
- */
-
-#ifndef __RCTYPES_H__
-#define __RCTYPES_H__
-
-/* Min/Max macro's */
-#ifdef MAX
-# undef MAX
-#endif
-#define MAX(_a, _b) (((_a) > (_b)) ? (_a) : (_b))
-#ifdef MIN
-# undef MIN
-#endif
-#define MIN(_a, _b) ((_a) > (_b) ? (_b) : (_a))
-
-#endif /* __RCTYPES_H__ */
diff --git a/libsbutil/include/rcscripts/rcutil.h b/libsbutil/include/rcscripts/rcutil.h
index 5d2369c..895a141 100644
--- a/libsbutil/include/rcscripts/rcutil.h
+++ b/libsbutil/include/rcscripts/rcutil.h
@@ -10,13 +10,12 @@
#ifndef __RCUTIL_H__
#define __RCUTIL_H__
-#include "rcscripts/rctypes.h"
#include "rcscripts/util/debug.h"
#include "rcscripts/util/string.h"
#include "rcscripts/util/file.h"
#include "rcscripts/util/config.h"
-#include "rcscripts/util/list.h"
-#include "rcscripts/util/str_list.h"
#include "rcscripts/util/dynbuf.h"
+#include "rcscripts/util/str_list.h" /* used by libsandbox/execve wrapper */
+
#endif /* __RCUTIL_H__ */
diff --git a/libsbutil/include/rcscripts/util/config.h b/libsbutil/include/rcscripts/util/config.h
index ad392f4..a38b1a1 100644
--- a/libsbutil/include/rcscripts/util/config.h
+++ b/libsbutil/include/rcscripts/util/config.h
@@ -21,6 +21,5 @@
* together seperated by 'sep'. */
char *rc_get_cnf_entry (const char *pathname, const char *entry,
const char *sep);
-char ** rc_get_list_file (char **list, char *filename);
#endif /* __RC_CONFIG_H__ */
diff --git a/libsbutil/include/rcscripts/util/file.h b/libsbutil/include/rcscripts/util/file.h
index 18697c5..197f211 100644
--- a/libsbutil/include/rcscripts/util/file.h
+++ b/libsbutil/include/rcscripts/util/file.h
@@ -13,30 +13,17 @@
#include <stdio.h>
-/* Return true if filename '_name' ends in '_ext' */
-#define CHECK_FILE_EXTENSION(_name, _ext) \
- ((check_str (_name)) && (check_str (_ext)) \
- && (strlen (_name) > strlen (_ext)) \
- && (0 == strncmp (&(_name[strlen(_name) - strlen(_ext)]), \
- _ext, strlen(_ext))))
-
/* The following functions do not care about errors - they only return
* TRUE if 'pathname' exist, and is the type requested, or else FALSE.
* This is only if pathname is valid ... */
bool rc_file_exists (const char *pathname);
bool rc_is_file (const char *pathname, bool follow_link);
-bool rc_is_link (const char *pathname);
bool rc_is_dir (const char *pathname, bool follow_link);
/* The following functions do not care about errors - it only returns
* the size/mtime of 'pathname' if it exists, and is the type requested,
* or else 0. */
off_t rc_get_size (const char *pathname, bool follow_link);
-time_t rc_get_mtime (const char *pathname, bool follow_link);
-
-/* The following functions return 0 on success, or -1 with errno set on error. */
-int rc_mktree (const char *pathname, mode_t mode);
-int rc_rmtree (const char *pathname);
/* The following return a pointer on success, or NULL with errno set on error.
* If it returned NULL, but errno is not set, then there was no error, but
diff --git a/libsbutil/include/rcscripts/util/list.h b/libsbutil/include/rcscripts/util/list.h
deleted file mode 100644
index a1d988b..0000000
--- a/libsbutil/include/rcscripts/util/list.h
+++ /dev/null
@@ -1,444 +0,0 @@
-/*
- * Copied from the Linux kernel source tree, version 2.6.0-test1.
- *
- * Licensed under the GPL v2 as per the whole kernel source tree.
- *
- * Ripped out the rcu stuff, as it's not needed.
- */
-
-#ifndef __LINUX_LIST_H__
-#define __LINUX_LIST_H__
-
-//#include <linux/stddef.h>
-/**
- * container_of - cast a member of a structure out to the containing structure
- *
- * @ptr: the pointer to the member.
- * @type: the type of the container struct this is embedded in.
- * @member: the name of the member within the struct.
- *
- */
-#define container_of(ptr, type, member) ({ \
- const typeof( ((type *)0)->member ) *__mptr = (ptr); \
- (type *)( (char *)__mptr - offsetof(type,member) );})
-
-//#include <linux/prefetch.h>
-static inline void prefetch(const void *x) {;}
-
-//#include <asm/system.h>
-
-/*
- * These are non-NULL pointers that will result in page faults
- * under normal circumstances, used to verify that nobody uses
- * non-initialized list entries.
- */
-#define LIST_POISON1 ((void *) 0x00100100)
-#define LIST_POISON2 ((void *) 0x00200200)
-
-/*
- * Simple doubly linked list implementation.
- *
- * Some of the internal functions ("__xxx") are useful when
- * manipulating whole lists rather than single entries, as
- * sometimes we already know the next/prev entries and we can
- * generate better code by using them directly rather than
- * using the generic single-entry routines.
- */
-
-struct list_head {
- struct list_head *next, *prev;
-};
-
-#define LIST_HEAD_INIT(name) { &(name), &(name) }
-
-#define LIST_HEAD(name) \
- struct list_head name = LIST_HEAD_INIT(name)
-
-#define INIT_LIST_HEAD(ptr) do { \
- (ptr)->next = (ptr); (ptr)->prev = (ptr); \
-} while (0)
-
-/*
- * Insert a new entry between two known consecutive entries.
- *
- * This is only for internal list manipulation where we know
- * the prev/next entries already!
- */
-static inline void __list_add(struct list_head *new,
- struct list_head *prev,
- struct list_head *next)
-{
- next->prev = new;
- new->next = next;
- new->prev = prev;
- prev->next = new;
-}
-
-/**
- * list_add - add a new entry
- * @new: new entry to be added
- * @head: list head to add it after
- *
- * Insert a new entry after the specified head.
- * This is good for implementing stacks.
- */
-static inline void list_add(struct list_head *new, struct list_head *head)
-{
- __list_add(new, head, head->next);
-}
-
-/**
- * list_add_tail - add a new entry
- * @new: new entry to be added
- * @head: list head to add it before
- *
- * Insert a new entry before the specified head.
- * This is useful for implementing queues.
- */
-static inline void list_add_tail(struct list_head *new, struct list_head *head)
-{
- __list_add(new, head->prev, head);
-}
-
-/*
- * Delete a list entry by making the prev/next entries
- * point to each other.
- *
- * This is only for internal list manipulation where we know
- * the prev/next entries already!
- */
-static inline void __list_del(struct list_head * prev, struct list_head * next)
-{
- next->prev = prev;
- prev->next = next;
-}
-
-/**
- * list_del - deletes entry from list.
- * @entry: the element to delete from the list.
- * Note: list_empty on entry does not return true after this, the entry is
- * in an undefined state.
- */
-static inline void list_del(struct list_head *entry)
-{
- __list_del(entry->prev, entry->next);
- entry->next = LIST_POISON1;
- entry->prev = LIST_POISON2;
-}
-
-/**
- * list_del_init - deletes entry from list and reinitialize it.
- * @entry: the element to delete from the list.
- */
-static inline void list_del_init(struct list_head *entry)
-{
- __list_del(entry->prev, entry->next);
- INIT_LIST_HEAD(entry);
-}
-
-/**
- * list_move - delete from one list and add as another's head
- * @list: the entry to move
- * @head: the head that will precede our entry
- */
-static inline void list_move(struct list_head *list, struct list_head *head)
-{
- __list_del(list->prev, list->next);
- list_add(list, head);
-}
-
-/**
- * list_move_tail - delete from one list and add as another's tail
- * @list: the entry to move
- * @head: the head that will follow our entry
- */
-static inline void list_move_tail(struct list_head *list,
- struct list_head *head)
-{
- __list_del(list->prev, list->next);
- list_add_tail(list, head);
-}
-
-/**
- * list_empty - tests whether a list is empty
- * @head: the list to test.
- */
-static inline int list_empty(struct list_head *head)
-{
- return head->next == head;
-}
-
-static inline void __list_splice(struct list_head *list,
- struct list_head *head)
-{
- struct list_head *first = list->next;
- struct list_head *last = list->prev;
- struct list_head *at = head->next;
-
- first->prev = head;
- head->next = first;
-
- last->next = at;
- at->prev = last;
-}
-
-/**
- * list_splice - join two lists
- * @list: the new list to add.
- * @head: the place to add it in the first list.
- */
-static inline void list_splice(struct list_head *list, struct list_head *head)
-{
- if (!list_empty(list))
- __list_splice(list, head);
-}
-
-/**
- * list_splice_init - join two lists and reinitialise the emptied list.
- * @list: the new list to add.
- * @head: the place to add it in the first list.
- *
- * The list at @list is reinitialised
- */
-static inline void list_splice_init(struct list_head *list,
- struct list_head *head)
-{
- if (!list_empty(list)) {
- __list_splice(list, head);
- INIT_LIST_HEAD(list);
- }
-}
-
-/**
- * list_entry - get the struct for this entry
- * @ptr: the &struct list_head pointer.
- * @type: the type of the struct this is embedded in.
- * @member: the name of the list_struct within the struct.
- */
-#define list_entry(ptr, type, member) \
- container_of(ptr, type, member)
-
-/**
- * list_for_each - iterate over a list
- * @pos: the &struct list_head to use as a loop counter.
- * @head: the head for your list.
- */
-#define list_for_each(pos, head) \
- for (pos = (head)->next, prefetch(pos->next); pos != (head); \
- pos = pos->next, prefetch(pos->next))
-
-/**
- * __list_for_each - iterate over a list
- * @pos: the &struct list_head to use as a loop counter.
- * @head: the head for your list.
- *
- * This variant differs from list_for_each() in that it's the
- * simplest possible list iteration code, no prefetching is done.
- * Use this for code that knows the list to be very short (empty
- * or 1 entry) most of the time.
- */
-#define __list_for_each(pos, head) \
- for (pos = (head)->next; pos != (head); pos = pos->next)
-
-/**
- * list_for_each_prev - iterate over a list backwards
- * @pos: the &struct list_head to use as a loop counter.
- * @head: the head for your list.
- */
-#define list_for_each_prev(pos, head) \
- for (pos = (head)->prev, prefetch(pos->prev); pos != (head); \
- pos = pos->prev, prefetch(pos->prev))
-
-/**
- * list_for_each_safe - iterate over a list safe against removal of list entry
- * @pos: the &struct list_head to use as a loop counter.
- * @n: another &struct list_head to use as temporary storage
- * @head: the head for your list.
- */
-#define list_for_each_safe(pos, n, head) \
- for (pos = (head)->next, n = pos->next; pos != (head); \
- pos = n, n = pos->next)
-
-/**
- * list_for_each_entry - iterate over list of given type
- * @pos: the type * to use as a loop counter.
- * @head: the head for your list.
- * @member: the name of the list_struct within the struct.
- */
-#define list_for_each_entry(pos, head, member) \
- for (pos = list_entry((head)->next, typeof(*pos), member), \
- prefetch(pos->member.next); \
- &pos->member != (head); \
- pos = list_entry(pos->member.next, typeof(*pos), member), \
- prefetch(pos->member.next))
-
-/**
- * list_for_each_entry_reverse - iterate backwards over list of given type.
- * @pos: the type * to use as a loop counter.
- * @head: the head for your list.
- * @member: the name of the list_struct within the struct.
- */
-#define list_for_each_entry_reverse(pos, head, member) \
- for (pos = list_entry((head)->prev, typeof(*pos), member), \
- prefetch(pos->member.prev); \
- &pos->member != (head); \
- pos = list_entry(pos->member.prev, typeof(*pos), member), \
- prefetch(pos->member.prev))
-
-
-/**
- * list_for_each_entry_safe - iterate over list of given type safe against removal of list entry
- * @pos: the type * to use as a loop counter.
- * @n: another type * to use as temporary storage
- * @head: the head for your list.
- * @member: the name of the list_struct within the struct.
- */
-#define list_for_each_entry_safe(pos, n, head, member) \
- for (pos = list_entry((head)->next, typeof(*pos), member), \
- n = list_entry(pos->member.next, typeof(*pos), member); \
- &pos->member != (head); \
- pos = n, n = list_entry(n->member.next, typeof(*n), member))
-
-/*
- * Double linked lists with a single pointer list head.
- * Mostly useful for hash tables where the two pointer list head is
- * too wasteful.
- * You lose the ability to access the tail in O(1).
- */
-
-struct hlist_head {
- struct hlist_node *first;
-};
-
-struct hlist_node {
- struct hlist_node *next, **pprev;
-};
-
-#define HLIST_HEAD_INIT { .first = NULL }
-#define HLIST_HEAD(name) struct hlist_head name = { .first = NULL }
-#define INIT_HLIST_HEAD(ptr) ((ptr)->first = NULL)
-#define INIT_HLIST_NODE(ptr) ((ptr)->next = NULL, (ptr)->pprev = NULL)
-
-static __inline__ int hlist_unhashed(struct hlist_node *h)
-{
- return !h->pprev;
-}
-
-static __inline__ int hlist_empty(struct hlist_head *h)
-{
- return !h->first;
-}
-
-static __inline__ void __hlist_del(struct hlist_node *n)
-{
- struct hlist_node *next = n->next;
- struct hlist_node **pprev = n->pprev;
- *pprev = next;
- if (next)
- next->pprev = pprev;
-}
-
-static __inline__ void hlist_del(struct hlist_node *n)
-{
- __hlist_del(n);
- n->next = LIST_POISON1;
- n->pprev = LIST_POISON2;
-}
-
-static __inline__ void hlist_del_init(struct hlist_node *n)
-{
- if (n->pprev) {
- __hlist_del(n);
- INIT_HLIST_NODE(n);
- }
-}
-
-static __inline__ void hlist_add_head(struct hlist_node *n, struct hlist_head *h)
-{
- struct hlist_node *first = h->first;
- n->next = first;
- if (first)
- first->pprev = &n->next;
- h->first = n;
- n->pprev = &h->first;
-}
-
-/* next must be != NULL */
-static __inline__ void hlist_add_before(struct hlist_node *n, struct hlist_node *next)
-{
- n->pprev = next->pprev;
- n->next = next;
- next->pprev = &n->next;
- *(n->pprev) = n;
-}
-
-static __inline__ void hlist_add_after(struct hlist_node *n,
- struct hlist_node *next)
-{
- next->next = n->next;
- *(next->pprev) = n;
- n->next = next;
-}
-
-#define hlist_entry(ptr, type, member) container_of(ptr,type,member)
-
-/* Cannot easily do prefetch unfortunately */
-#define hlist_for_each(pos, head) \
- for (pos = (head)->first; pos && ({ prefetch(pos->next); 1; }); \
- pos = pos->next)
-
-#define hlist_for_each_safe(pos, n, head) \
- for (pos = (head)->first; n = pos ? pos->next : 0, pos; \
- pos = n)
-
-/**
- * hlist_for_each_entry - iterate over list of given type
- * @tpos: the type * to use as a loop counter.
- * @pos: the &struct hlist_node to use as a loop counter.
- * @head: the head for your list.
- * @member: the name of the hlist_node within the struct.
- */
-#define hlist_for_each_entry(tpos, pos, head, member) \
- for (pos = (head)->first; \
- pos && ({ prefetch(pos->next); 1;}) && \
- ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
- pos = pos->next)
-
-/**
- * hlist_for_each_entry_continue - iterate over a hlist continuing after existing point
- * @tpos: the type * to use as a loop counter.
- * @pos: the &struct hlist_node to use as a loop counter.
- * @member: the name of the hlist_node within the struct.
- */
-#define hlist_for_each_entry_continue(tpos, pos, member) \
- for (pos = (pos)->next; \
- pos && ({ prefetch(pos->next); 1;}) && \
- ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
- pos = pos->next)
-
-/**
- * hlist_for_each_entry_from - iterate over a hlist continuing from existing point
- * @tpos: the type * to use as a loop counter.
- * @pos: the &struct hlist_node to use as a loop counter.
- * @member: the name of the hlist_node within the struct.
- */
-#define hlist_for_each_entry_from(tpos, pos, member) \
- for (; pos && ({ prefetch(pos->next); 1;}) && \
- ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
- pos = pos->next)
-
-/**
- * hlist_for_each_entry_safe - iterate over list of given type safe against removal of list entry
- * @tpos: the type * to use as a loop counter.
- * @pos: the &struct hlist_node to use as a loop counter.
- * @n: another &struct hlist_node to use as temporary storage
- * @head: the head for your list.
- * @member: the name of the hlist_node within the struct.
- */
-#define hlist_for_each_entry_safe(tpos, pos, n, head, member) \
- for (pos = (head)->first; \
- pos && ({ n = pos->next; 1; }) && \
- ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
- pos = n)
-
-#endif
diff --git a/libsbutil/include/rcscripts/util/string.h b/libsbutil/include/rcscripts/util/string.h
index a5484b4..982d9a7 100644
--- a/libsbutil/include/rcscripts/util/string.h
+++ b/libsbutil/include/rcscripts/util/string.h
@@ -17,7 +17,5 @@ char *rc_strcatpaths (const char *pathname1, const char *pathname2);
/* Compat functions for GNU extensions */
char *rc_strndup (const char *str, size_t size);
-/* Same as basename(3), but do not modify path */
-char *rc_basename (const char *path);
#endif /* __RC_STRING_H__ */
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;
-}