]> git.decadent.org.uk Git - nfs-utils.git/commitdiff
text-based mount.nfs: Fix po_rightmost() enum return values
authorChuck Lever <chuck.lever@oracle.com>
Thu, 11 Oct 2007 17:55:02 +0000 (13:55 -0400)
committerNeil Brown <neilb@suse.de>
Thu, 11 Oct 2007 23:08:21 +0000 (09:08 +1000)
Neil observed that po_rightmost() now returns enum values from both

enum {
PO_NOT_FOUND = 0,
PO_FOUND = 1,
}

and

enum {
PO_KEY2_RIGHTMOST = 1,
PO_KEY1_RIGHTMOST = -1,
}

It would be cleaner to use a single enum for po_rightmost()'s return value.

We take the next logical step and create specific types for the return
values in order to ensure we don't mix the enum values, and to document
explicitly what return values callers can expect.

This could have been a simpler patch, but I think the end result is a
cleaner overall parser API.

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
Signed-off-by: Neil Brown <neilb@suse.de>
utils/mount/parse_opt.c
utils/mount/parse_opt.h

index f2531422172844b9d1127671035f58fc482795ab..cb398bd2d4d714fd5aa1ab798f3763ed0e9a80f4 100644 (file)
@@ -255,13 +255,12 @@ void po_replace(struct mount_options *target, struct mount_options *source)
  * Convert our mount options object back into a string that the
  * rest of the world can use.
  *
  * Convert our mount options object back into a string that the
  * rest of the world can use.
  *
- * Returns 1 if the string was successfully created; otherwise
- * zero.  Upon return, @string contains the address of a
- * replacement C string containing a comma-delimited list of
- * mount options and values; or the passed-in string is freed
- * and NULL is returned if some failure occurred.
+ * Upon return, @string contains the address of a replacement
+ * C string containing a comma-delimited list of mount options
+ * and values; or the passed-in string is freed and NULL is
+ * returned if some failure occurred.
  */
  */
-int po_join(struct mount_options *options, char **str)
+po_return_t po_join(struct mount_options *options, char **str)
 {
        size_t len = 0;
        struct mount_option *option;
 {
        size_t len = 0;
        struct mount_option *option;
@@ -310,10 +309,8 @@ int po_join(struct mount_options *options, char **str)
  * @options: pointer to mount options
  * @option: pointer to a C string containing the option to add
  *
  * @options: pointer to mount options
  * @option: pointer to a C string containing the option to add
  *
- * Returns 1 if the list was successfully concatenated; otherwise
- * zero.
  */
  */
-int po_append(struct mount_options *options, char *str)
+po_return_t po_append(struct mount_options *options, char *str)
 {
        struct mount_option *option = option_create(str);
 
 {
        struct mount_option *option = option_create(str);
 
@@ -329,9 +326,8 @@ int po_append(struct mount_options *options, char *str)
  * @options: pointer to mount options
  * @keyword: pointer to a C string containing option keyword for which to search
  *
  * @options: pointer to mount options
  * @keyword: pointer to a C string containing option keyword for which to search
  *
- * Returns 1 if the option is present in the list; otherwise zero.
  */
  */
-int po_contains(struct mount_options *options, char *keyword)
+po_found_t po_contains(struct mount_options *options, char *keyword)
 {
        struct mount_option *option;
 
 {
        struct mount_option *option;
 
@@ -382,12 +378,9 @@ char *po_get(struct mount_options *options, char *keyword)
  *
  * This function can be used to determine which of two similar
  * options will be the one to take effect.
  *
  * This function can be used to determine which of two similar
  * options will be the one to take effect.
- *
- * Returns 1 if key2 is rightmost or key1 is not present.
- * Returns -1 if key1 is rightmost or key2 is not present.
- * Returns 0 if neither key is present.
  */
  */
-int po_rightmost(struct mount_options *options, char *key1, char *key2)
+po_rightmost_t po_rightmost(struct mount_options *options,
+                           char *key1, char *key2)
 {
        struct mount_option *option;
 
 {
        struct mount_option *option;
 
@@ -400,7 +393,7 @@ int po_rightmost(struct mount_options *options, char *key1, char *key2)
                }
        }
 
                }
        }
 
-       return PO_NOT_FOUND;
+       return PO_NEITHER_FOUND;
 }
 
 /**
 }
 
 /**
@@ -408,10 +401,9 @@ int po_rightmost(struct mount_options *options, char *key1, char *key2)
  * @options: pointer to mount options
  * @keyword: pointer to a C string containing an option keyword to remove
  *
  * @options: pointer to mount options
  * @keyword: pointer to a C string containing an option keyword to remove
  *
- * Returns 1 if the option was found and removed; passed-in list is
- * truncated upon return; otherwise zero.
+ * Side-effect: the passed-in list is truncated on success.
  */
  */
-int po_remove_all(struct mount_options *options, char *keyword)
+po_found_t po_remove_all(struct mount_options *options, char *keyword)
 {
        struct mount_option *option, *next;
        int found = PO_NOT_FOUND;
 {
        struct mount_option *option, *next;
        int found = PO_NOT_FOUND;
index 6b9fb5eb914abbae0203ebf04268a1f70d5f31cb..e7924ddf078ade1c0c337c00f96d66f468b89973 100644 (file)
  *
  */
 
  *
  */
 
-enum {
+typedef enum {
        PO_FAILED = 0,
        PO_SUCCEEDED = 1,
        PO_FAILED = 0,
        PO_SUCCEEDED = 1,
-};
+} po_return_t;
 
 
-enum {
+typedef enum {
        PO_NOT_FOUND = 0,
        PO_FOUND = 1,
        PO_NOT_FOUND = 0,
        PO_FOUND = 1,
-};
+} po_found_t;
 
 
-enum {
-       PO_KEY2_RIGHTMOST = 1,
+typedef enum {
        PO_KEY1_RIGHTMOST = -1,
        PO_KEY1_RIGHTMOST = -1,
-};
+       PO_NEITHER_FOUND = 0,
+       PO_KEY2_RIGHTMOST = 1,
+} po_rightmost_t;
 
 struct mount_options;
 
 struct mount_options * po_split(char *);
 void                   po_replace(struct mount_options *,
                                   struct mount_options *);
 
 struct mount_options;
 
 struct mount_options * po_split(char *);
 void                   po_replace(struct mount_options *,
                                   struct mount_options *);
-int                    po_join(struct mount_options *, char **);
+po_return_t            po_join(struct mount_options *, char **);
 
 
-int                    po_append(struct mount_options *, char *);
-int                    po_contains(struct mount_options *, char *);
+po_return_t            po_append(struct mount_options *, char *);
+po_found_t             po_contains(struct mount_options *, char *);
 char *                 po_get(struct mount_options *, char *);
 char *                 po_get(struct mount_options *, char *);
-int                    po_rightmost(struct mount_options *, char *, char *);
-int                    po_remove_all(struct mount_options *, char *);
+po_rightmost_t         po_rightmost(struct mount_options *, char *, char *);
+po_found_t             po_remove_all(struct mount_options *, char *);
 void                   po_destroy(struct mount_options *);
 void                   po_destroy(struct mount_options *);