summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
14e6890)
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.
- * 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().
*/
*
* \sa for_each_line(), for_each_line_ro().
*/
-enum for_each_line_modes{
+enum for_each_line_flags {
/** Activate read-only mode. */
/** 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;
size_t size, line_handler_t *line_handler, void *private_data)
{
char *start = buf, *end;
start = ++end;
continue;
}
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);
size_t s = end - start;
char *b = para_malloc(s + 1);
memcpy(b, start, s);
return ret;
start = ++end;
}
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)
return num_lines;
i = buf + size - start;
if (i && i != size)
int for_each_line(char *buf, size_t size, line_handler_t *line_handler,
void *private_data)
{
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);
int for_each_line_ro(char *buf, size_t size, line_handler_t *line_handler,
void *private_data)
{
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,