summaryrefslogtreecommitdiff
path: root/string.c
diff options
context:
space:
mode:
authorAndre Noll <maan@systemlinux.org>2013-03-25 15:36:10 +0000
committerAndre Noll <maan@systemlinux.org>2013-05-02 19:56:09 +0200
commit6256ed835dc5ced1fb4c75ed91fb4e68fbf436fd (patch)
tree389c1de683656e0ee34f6299680e4df4405f6076 /string.c
parent14e6890c756529c73a95cf1fb3648a6a7c3344d7 (diff)
string: Replace the for_each_line_modes enum by a bitmap.
Currently we pass an "enum for_each_line_modes" as the first argument to for_each_complete_line(). The parameter is effectively a boolean since the enumeration defines only two possible values. For the upcoming discard feature of for_each_line_modes() we'll need to pass another bit of information, so this patch changes the type of the first argument to for_each_complete_line() to unsigned and treats it as a bit array. The only bit defined so far is LINE_MODE_RO, with unchanged semantics. The two callers are updated to reflect this change.
Diffstat (limited to 'string.c')
-rw-r--r--string.c19
1 files changed, 8 insertions, 11 deletions
diff --git a/string.c b/string.c
index c001b15d..d7e74d9d 100644
--- a/string.c
+++ b/string.c
@@ -350,18 +350,16 @@ __malloc char *para_hostname(void)
}
/**
- * Used to distinguish between read-only and read-write mode.
+ * Controls behavior of for_each_complete_line().
*
* \sa for_each_line(), for_each_line_ro().
*/
-enum for_each_line_modes{
+enum for_each_line_flags {
/** Activate read-only mode. */
- LINE_MODE_RO,
- /** Activate read-write mode. */
- LINE_MODE_RW
+ FELF_READ_ONLY = 1 << 0,
};
-static int for_each_complete_line(enum for_each_line_modes mode, char *buf,
+static int for_each_complete_line(unsigned flags, char *buf,
size_t size, line_handler_t *line_handler, void *private_data)
{
char *start = buf, *end;
@@ -387,7 +385,7 @@ static int for_each_complete_line(enum for_each_line_modes mode, char *buf,
start = ++end;
continue;
}
- if (mode == LINE_MODE_RO) {
+ if (flags & FELF_READ_ONLY) {
size_t s = end - start;
char *b = para_malloc(s + 1);
memcpy(b, start, s);
@@ -403,7 +401,7 @@ static int for_each_complete_line(enum for_each_line_modes mode, char *buf,
return ret;
start = ++end;
}
- if (!line_handler || mode == LINE_MODE_RO)
+ if (!line_handler || (flags & FELF_READ_ONLY))
return num_lines;
i = buf + size - start;
if (i && i != size)
@@ -436,8 +434,7 @@ static int for_each_complete_line(enum for_each_line_modes mode, char *buf,
int for_each_line(char *buf, size_t size, line_handler_t *line_handler,
void *private_data)
{
- return for_each_complete_line(LINE_MODE_RW, buf, size, line_handler,
- private_data);
+ return for_each_complete_line(0, buf, size, line_handler, private_data);
}
/**
@@ -458,7 +455,7 @@ int for_each_line(char *buf, size_t size, line_handler_t *line_handler,
int for_each_line_ro(char *buf, size_t size, line_handler_t *line_handler,
void *private_data)
{
- return for_each_complete_line(LINE_MODE_RO, buf, size, line_handler,
+ return for_each_complete_line(FELF_READ_ONLY, buf, size, line_handler,
private_data);
}