}
/**
- * 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;
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);
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)
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)
{
- 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);
}