string: Replace the for_each_line_modes enum by a bitmap.
authorAndre Noll <maan@systemlinux.org>
Mon, 25 Mar 2013 15:36:10 +0000 (15:36 +0000)
committerAndre Noll <maan@systemlinux.org>
Thu, 2 May 2013 17:56:09 +0000 (19:56 +0200)
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.

string.c

index c001b15d7dc8eca43d50af650a3dadf1693ed7ab..d7e74d9dda16915d4bbe865d1f268dfa7d311963 100644 (file)
--- 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);
 }