mirror of
git://git.gnu.org.ua/pam-modules.git
synced 2025-04-26 00:19:52 +03:00
Minor changes
This commit is contained in:
parent
cd169165d8
commit
5f13fe76ab
1 changed files with 16 additions and 2 deletions
18
lib/slist.c
18
lib/slist.c
|
@ -77,6 +77,7 @@ copy_chars(gray_slist_t slist, const char *str, size_t n)
|
|||
return n;
|
||||
}
|
||||
|
||||
/* Create new string list. */
|
||||
gray_slist_t
|
||||
gray_slist_create(void)
|
||||
{
|
||||
|
@ -88,18 +89,21 @@ gray_slist_create(void)
|
|||
return slist;
|
||||
}
|
||||
|
||||
/* Return error code associated with the string list */
|
||||
int
|
||||
gray_slist_err(gray_slist_t slist)
|
||||
{
|
||||
return slist->ec;
|
||||
}
|
||||
|
||||
/* Clear error code associated with the string list */
|
||||
void
|
||||
gray_slist_clerr(gray_slist_t slist)
|
||||
{
|
||||
slist->ec = 0;
|
||||
}
|
||||
|
||||
/* Clear content of the string list */
|
||||
void
|
||||
gray_slist_clear(gray_slist_t slist)
|
||||
{
|
||||
|
@ -111,7 +115,7 @@ gray_slist_clear(gray_slist_t slist)
|
|||
gray_slist_clerr(slist);
|
||||
}
|
||||
|
||||
|
||||
/* Deallocate memory used by the string list. Store NULL in *SLIST */
|
||||
void
|
||||
gray_slist_free(gray_slist_t *slist)
|
||||
{
|
||||
|
@ -128,6 +132,8 @@ gray_slist_free(gray_slist_t *slist)
|
|||
*slist = NULL;
|
||||
}
|
||||
|
||||
/* Append N bytes from the string STR to the list. Return the number of
|
||||
bytes actually stored. */
|
||||
ssize_t
|
||||
gray_slist_append(gray_slist_t slist, const char *str, size_t n)
|
||||
{
|
||||
|
@ -139,18 +145,20 @@ gray_slist_append(gray_slist_t slist, const char *str, size_t n)
|
|||
while (total < n) {
|
||||
ssize_t s = copy_chars(slist, str + total, n - total);
|
||||
if (s == -1)
|
||||
return -1;
|
||||
break;
|
||||
total += s;
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
/* Append one character to the list. Return 1 on success. */
|
||||
ssize_t
|
||||
gray_slist_append_char(gray_slist_t slist, char c)
|
||||
{
|
||||
return gray_slist_append(slist, &c, 1);
|
||||
}
|
||||
|
||||
/* Return the total size of strings stored in the list. */
|
||||
size_t
|
||||
gray_slist_size(gray_slist_t slist)
|
||||
{
|
||||
|
@ -161,6 +169,8 @@ gray_slist_size(gray_slist_t slist)
|
|||
return size;
|
||||
}
|
||||
|
||||
/* Coalesce all segments in the list into a single contiguous string.
|
||||
Return its length. */
|
||||
ssize_t
|
||||
gray_slist_coalesce(gray_slist_t slist)
|
||||
{
|
||||
|
@ -190,6 +200,7 @@ gray_slist_coalesce(gray_slist_t slist)
|
|||
return size;
|
||||
}
|
||||
|
||||
/* Return the pointer to the head of the list. */
|
||||
void *
|
||||
gray_slist_head(gray_slist_t slist, size_t *psize)
|
||||
{
|
||||
|
@ -198,6 +209,9 @@ gray_slist_head(gray_slist_t slist, size_t *psize)
|
|||
return slist->head ? slist->head->buf : NULL;
|
||||
}
|
||||
|
||||
/* Finish building the string list. Coalesce all segments, and clear the
|
||||
unused memory. On success, return the pointer to the newly-built string.
|
||||
On error (out of memory), return NULL and set error status in the SLIST. */
|
||||
void *
|
||||
gray_slist_finish(gray_slist_t slist)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue