summaryrefslogtreecommitdiffabout
authorSergey Poznyakoff <gray@gnu.org>2018-08-16 06:32:59 (GMT)
committer Sergey Poznyakoff <gray@gnu.org>2018-08-16 06:32:59 (GMT)
commit5f13fe76ab44b0476f6634a3368e0115f46eaf52 (patch) (side-by-side diff)
tree55e0f67470e3929fca34a40b93dc1bfb674b0697
parentcd169165d8193ad430ae27c50ee213ffa75fdca3 (diff)
downloadpam-modules-5f13fe76ab44b0476f6634a3368e0115f46eaf52.tar.gz
pam-modules-5f13fe76ab44b0476f6634a3368e0115f46eaf52.tar.bz2
Minor changes
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--lib/slist.c18
1 files changed, 16 insertions, 2 deletions
diff --git a/lib/slist.c b/lib/slist.c
index 46e516e..eea81e6 100644
--- a/lib/slist.c
+++ b/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)
{

Return to:

Send suggestions and report system problems to the System administrator.