"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/sets.c" between
proftpd-1.3.6b.tar.gz and proftpd-1.3.6c.tar.gz

About: ProFTPD is a highly configurable FTP server software (with FTPS and SFTP support).

sets.c  (proftpd-1.3.6b):sets.c  (proftpd-1.3.6c)
/* /*
* ProFTPD - FTP server daemon * ProFTPD - FTP server daemon
* Copyright (c) 1997, 1998 Public Flood Software * Copyright (c) 1997, 1998 Public Flood Software
* Copyright (c) 2001-2016 The ProFTPD Project team * Copyright (c) 2001-2019 The ProFTPD Project team
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or * the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
skipping to change at line 47 skipping to change at line 47
if (p == NULL && if (p == NULL &&
permanent_pool == NULL) { permanent_pool == NULL) {
errno = EPERM; errno = EPERM;
return NULL; return NULL;
} }
p = p ? p : permanent_pool; p = p ? p : permanent_pool;
new_set = palloc(p, sizeof(xaset_t)); new_set = palloc(p, sizeof(xaset_t));
if (new_set == NULL) {
if (!new_set)
return NULL; return NULL;
}
new_set->xas_list = NULL; new_set->xas_list = NULL;
new_set->pool = p; new_set->pool = p;
new_set->xas_compare = cmpfunc; new_set->xas_compare = cmpfunc;
return new_set; return new_set;
} }
/* Inserts a new member into an existing set. The member is inserted /* Inserts a new member into an existing set. The member is inserted
* at the beginning of the set. Returns 0 if successful, -1 otherwise (with * at the beginning of the set. Returns 0 if successful, -1 otherwise (with
* errno set appropriately). * errno set appropriately).
*/ */
int xaset_insert(xaset_t *set, xasetmember_t *member) { int xaset_insert(xaset_t *set, xasetmember_t *member) {
if (set == NULL || if (set == NULL ||
member == NULL) { member == NULL) {
errno = EINVAL; errno = EINVAL;
return -1; return -1;
} }
member->next = set->xas_list; member->next = set->xas_list;
if (set->xas_list) if (set->xas_list != NULL) {
set->xas_list->prev = member; set->xas_list->prev = member;
}
set->xas_list = member; set->xas_list = member;
return 0; return 0;
} }
/* Inserts a new member into an existing set at the end of the list. /* Inserts a new member into an existing set at the end of the list.
*/ */
int xaset_insert_end(xaset_t *set, xasetmember_t *member) { int xaset_insert_end(xaset_t *set, xasetmember_t *member) {
xasetmember_t **tmp, *prev = NULL; xasetmember_t **tmp, *prev = NULL;
skipping to change at line 97 skipping to change at line 97
return -1; return -1;
} }
for (tmp = &set->xas_list; *tmp; prev = *tmp, tmp = &(*tmp)->next) for (tmp = &set->xas_list; *tmp; prev = *tmp, tmp = &(*tmp)->next)
; ;
*tmp = member; *tmp = member;
member->prev = prev; member->prev = prev;
member->next = NULL; member->next = NULL;
if (prev) if (prev != NULL) {
prev->next = member; prev->next = member;
}
return 0; return 0;
} }
/* Inserts a new member into an existing set, sorted using the set's compare /* Inserts a new member into an existing set, sorted using the set's compare
* callback. If dups_allowed is non-0, returns 0 and the member is not added * callback. If dups_allowed is non-0, returns 0 and the member is not added
* to the set. Otherwise, it is added immediately before the first duplicate. * to the set. Otherwise, it is added immediately before the first duplicate.
* If the set is not empty and not pre-sorted, results are undefined. * If the set is not empty and not pre-sorted, results are undefined.
* Returns 0 if successful, -1 otherwise (with errno set appropriately). * Returns 0 if successful, -1 otherwise (with errno set appropriately).
*/ */
int xaset_insert_sort(xaset_t *set, xasetmember_t *member, int dups_allowed) { int xaset_insert_sort(xaset_t *set, xasetmember_t *member, int dups_allowed) {
xasetmember_t **setp = NULL, *mprev = NULL; xasetmember_t **setp = NULL, *mprev = NULL;
if (!set || !member || !set->xas_compare) { if (set == NULL ||
member == NULL ||
set->xas_compare == NULL) {
errno = EINVAL; errno = EINVAL;
return -1; return -1;
} }
for (setp = &set->xas_list; *setp; setp = &(*setp)->next) { for (setp = &set->xas_list; *setp; setp = &(*setp)->next) {
int res; int res;
res = set->xas_compare(member, *setp); res = set->xas_compare(member, *setp);
if (res <= 0) { if (res <= 0) {
if (res == 0 && if (res == 0 &&
!dups_allowed) !dups_allowed) {
return 0; return 0;
}
break; break;
} }
mprev = *setp; mprev = *setp;
} }
if (*setp) if (*setp) {
(*setp)->prev = member; (*setp)->prev = member;
}
member->prev = mprev; member->prev = mprev;
member->next = *setp; member->next = *setp;
*setp = member; *setp = member;
return 0; return 0;
} }
/* Remove a member from a set. The set need not be sorted. Note that this /* Remove a member from a set. The set need not be sorted. Note that this
* does NOT free the memory used by the member. Returns 0 if successful, * does NOT free the memory used by the member. Returns 0 if successful,
skipping to change at line 156 skipping to change at line 162
xasetmember_t *m = NULL; xasetmember_t *m = NULL;
if (set == NULL || if (set == NULL ||
member == NULL) { member == NULL) {
errno = EINVAL; errno = EINVAL;
return -1; return -1;
} }
/* Check if member is actually a member of set. */ /* Check if member is actually a member of set. */
for (m = set->xas_list; m; m = m->next) { for (m = set->xas_list; m; m = m->next) {
if (m == member) if (m == member) {
break; break;
}
} }
if (m == NULL) { if (m == NULL) {
errno = ENOENT; errno = ENOENT;
return -1; return -1;
} }
if (member->prev) if (member->prev != NULL) {
member->prev->next = member->next; member->prev->next = member->next;
else /* assume that member is first in the list */ } else { /* assume that member is first in the list */
set->xas_list = member->next; set->xas_list = member->next;
}
if (member->next) if (member->next != NULL) {
member->next->prev = member->prev; member->next->prev = member->prev;
}
member->next = member->prev = NULL; member->next = member->prev = NULL;
return 0; return 0;
} }
/* Perform an exact copy of the entire set, returning the new set. msize /* Perform an exact copy of the entire set, returning the new set. msize
* specifies the size of each member. If copyfunc is non-NULL, it is called * specifies the size of each member. If copyfunc is non-NULL, it is called
* instead to copy each member. Returns NULL if out of memory condition * instead to copy each member. Returns NULL if out of memory condition
* occurs. * occurs.
*/ */
xaset_t *xaset_copy(pool *p, xaset_t *set, size_t msize, XASET_MCOPY copyfunc) { xaset_t *xaset_copy(pool *p, xaset_t *set, size_t msize, XASET_MCOPY copyfunc) {
xaset_t *new_set; xaset_t *new_set;
xasetmember_t *n, *m, **pos; xasetmember_t *n, *m, **pos;
if (set == NULL) { if (set == NULL) {
errno = EINVAL; errno = EINVAL;
return NULL; return NULL;
} }
if (!copyfunc && !msize) { if (copyfunc == NULL &&
msize == 0) {
errno = EINVAL; errno = EINVAL;
return NULL; return NULL;
} }
p = (p ? p : set->pool); p = (p ? p : set->pool);
new_set = xaset_create(p, set->xas_compare); new_set = xaset_create(p, set->xas_compare);
if (new_set == NULL) if (new_set == NULL) {
return NULL; return NULL;
}
pos = &new_set->xas_list; pos = &new_set->xas_list;
/* NOTE: xaset_insert_sort is not used here for performance reasons. */ /* NOTE: xaset_insert_sort is not used here for performance reasons. */
for (m = set->xas_list; m; m = m->next) { for (m = set->xas_list; m; m = m->next) {
n = copyfunc ? copyfunc(m) : (xasetmember_t *) palloc(p, msize); n = copyfunc ? copyfunc(m) : (xasetmember_t *) palloc(p, msize);
if (!n) if (n == NULL) {
return NULL; /* Could clean up here */ /* Note that we could clean up here. */
return NULL;
}
if (!copyfunc) if (copyfunc == NULL) {
memcpy(n, m, msize); memcpy(n, m, msize);
}
/* Create links */ /* Create links */
n->prev = *pos; n->prev = *pos;
n->next = NULL; n->next = NULL;
if (*pos) if (*pos) {
pos = &(*pos)->next; pos = &(*pos)->next;
}
*pos = n; *pos = n;
} }
return new_set; return new_set;
} }
 End of changes. 28 change blocks. 
19 lines changed or deleted 35 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)