diff options
author | Daniel Stenberg <daniel@haxx.se> | 2001-03-02 07:42:11 +0000 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2001-03-02 07:42:11 +0000 |
commit | b6fa2f882c3b15169ac3830eed7a9a5d8cacb520 (patch) | |
tree | 25bbed5d4cabf5a242de1ff2594be441732fb269 | |
parent | b6c5da337aa6648bf9f39cd15f97123e64b4a91f (diff) |
moved the slist-functions here from FTP since they're more generic than simply
for FTP-stuff
-rw-r--r-- | lib/sendf.c | 75 |
1 files changed, 74 insertions, 1 deletions
diff --git a/lib/sendf.c b/lib/sendf.c index c296af2fc..ccae9928a 100644 --- a/lib/sendf.c +++ b/lib/sendf.c @@ -50,6 +50,76 @@ #include "memdebug.h" #endif +/* returns last node in linked list */ +static struct curl_slist *slist_get_last(struct curl_slist *list) +{ + struct curl_slist *item; + + /* if caller passed us a NULL, return now */ + if (!list) + return NULL; + + /* loop through to find the last item */ + item = list; + while (item->next) { + item = item->next; + } + return item; +} + +/* append a struct to the linked list. It always retunrs the address of the + * first record, so that you can sure this function as an initialization + * function as well as an append function. If you find this bothersome, + * then simply create a separate _init function and call it appropriately from + * within the proram. */ +struct curl_slist *curl_slist_append(struct curl_slist *list, + const char *data) +{ + struct curl_slist *last; + struct curl_slist *new_item; + + new_item = (struct curl_slist *) malloc(sizeof(struct curl_slist)); + if (new_item) { + new_item->next = NULL; + new_item->data = strdup(data); + } + else { + fprintf(stderr, "Cannot allocate memory for QUOTE list.\n"); + return NULL; + } + + if (list) { + last = slist_get_last(list); + last->next = new_item; + return list; + } + + /* if this is the first item, then new_item *is* the list */ + return new_item; +} + +/* be nice and clean up resources */ +void curl_slist_free_all(struct curl_slist *list) +{ + struct curl_slist *next; + struct curl_slist *item; + + if (!list) + return; + + item = list; + do { + next = item->next; + + if (item->data) { + free(item->data); + } + free(item); + item = next; + } while (next); +} + + /* infof() is for info message along the way */ void Curl_infof(struct UrlData *data, char *fmt, ...) @@ -72,8 +142,11 @@ void Curl_failf(struct UrlData *data, char *fmt, ...) va_start(ap, fmt); if(data->errorbuffer) vsnprintf(data->errorbuffer, CURL_ERROR_SIZE, fmt, ap); - else /* no errorbuffer receives this, write to data->err instead */ + else { + /* no errorbuffer receives this, write to data->err instead */ vfprintf(data->err, fmt, ap); + fprintf(data->err, "\n"); + } va_end(ap); } |