aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2012-03-12 00:25:40 -0500
committerRob Landley <rob@landley.net>2012-03-12 00:25:40 -0500
commit2c48247a01a19c709f693d649d8158bccb5fbf70 (patch)
tree53297abe89d56a745d1d9a9ddec161fc1adbae24 /lib
parent9f4c1fd2de1b525b7638a79a8294f8d5b865bcc5 (diff)
downloadtoybox-2c48247a01a19c709f693d649d8158bccb5fbf70.tar.gz
Redo tail to use optargs and optionally support lseek. Add support to optargs and llist.c, plus add a test suite entry. Still no -f support though.
Diffstat (limited to 'lib')
-rw-r--r--lib/args.c4
-rw-r--r--lib/lib.h1
-rw-r--r--lib/llist.c24
3 files changed, 18 insertions, 11 deletions
diff --git a/lib/args.c b/lib/args.c
index 918119c6..f4ceba1e 100644
--- a/lib/args.c
+++ b/lib/args.c
@@ -36,7 +36,7 @@
// [yz] needs at least one of y or z. TODO
// at the beginning:
// ^ stop at first nonoption argument
-// <0 die if less than leftover arguments (default 0)
+// <0 die if less than # leftover arguments (default 0)
// >9 die if > # leftover arguments (default MAX_INT)
// ? Allow unknown arguments (pass them through to command).
// & first argument has imaginary dash (ala tar/ps)
@@ -241,7 +241,7 @@ void parse_optflaglist(struct getoptflagstate *gof)
// If this is the start of a new option that wasn't a longopt,
- } else if (strchr(":*#@.", *options)) {
+ } else if (strchr(":*#@.-", *options)) {
if (CFG_TOYBOX_DEBUG && new->type)
error_exit("multiple types %c:%c%c", new->c, new->type, *options);
new->type = *options;
diff --git a/lib/lib.h b/lib/lib.h
index ab10eb73..c2190393 100644
--- a/lib/lib.h
+++ b/lib/lib.h
@@ -35,6 +35,7 @@ struct double_list {
void llist_free(void *list, void (*freeit)(void *data));
void *llist_pop(void *list); // actually void **list, but the compiler's dumb
+void dlist_add_nomalloc(struct double_list **list, struct double_list *new);
struct double_list *dlist_add(struct double_list **list, char *data);
// args.c
diff --git a/lib/llist.c b/lib/llist.c
index c6e7da33..8588721b 100644
--- a/lib/llist.c
+++ b/lib/llist.c
@@ -35,18 +35,24 @@ void *llist_pop(void *list)
return (void *)next;
}
+void dlist_add_nomalloc(struct double_list **list, struct double_list *new)
+{
+ if (*list) {
+ new->next = *list;
+ new->prev = (*list)->prev;
+ (*list)->prev->next = new;
+ (*list)->prev = new;
+ } else *list = new->next = new->prev = new;
+}
+
+
// Add an entry to the end of a doubly linked list
struct double_list *dlist_add(struct double_list **list, char *data)
{
- struct double_list *line = xmalloc(sizeof(struct double_list));
+ struct double_list *new = xmalloc(sizeof(struct double_list));
- line->data = data;
- if (*list) {
- line->next = *list;
- line->prev = (*list)->prev;
- (*list)->prev->next = line;
- (*list)->prev = line;
- } else *list = line->next = line->prev = line;
+ new->data = data;
+ dlist_add_nomalloc(list, new);
- return line;
+ return new;
}