>From c88f47fa91b9b77e14882b8083c1e730de16709c Mon Sep 17 00:00:00 2001 From: illusionoflife Date: Wed, 8 Aug 2012 10:38:45 +0400 Subject: [PATCH] Moved list reversion into static function. --- src/netrc.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/netrc.c b/src/netrc.c index 193d4f3..233c72d 100644 --- a/src/netrc.c +++ b/src/netrc.c @@ -47,7 +47,7 @@ as that of the covered work. */ acc_t *netrc_list; static acc_t *parse_netrc (const char *); - +static void reverse_list(acc_t **list); /* Return the correct user and password, given the host, user (as given in the URL), and password (as given in the URL). May return NULL. @@ -433,23 +433,30 @@ parse_netrc (const char *path) maybe_add_to_list (¤t, &retval); xfree (current); - /* Reverse the order of the list so that it appears in file order. */ - current = retval; - retval = NULL; - while (current) + reverse_list(&retval); + return retval; +} + +static void +reverse_list(acc_t **list) +{ + acc_t *current = *list; + acc_t *reversed = NULL; + + while (current) { acc_t *saved_reference; /* Change the direction of the pointers. */ saved_reference = current->next; - current->next = retval; + current->next = reversed; /* Advance to the next node. */ - retval = current; + reversed = current; current = saved_reference; } - - return retval; + + *list = reversed; } -- 1.7.11.4