]> granicus.if.org Git - zfs/commitdiff
Change functions which return literals to return `const char*`
authorTomohiro Kusumi <kusumi.tomohiro@gmail.com>
Fri, 9 Mar 2018 21:47:32 +0000 (06:47 +0900)
committerBrian Behlendorf <behlendorf1@llnl.gov>
Fri, 9 Mar 2018 21:47:32 +0000 (13:47 -0800)
get_format_prompt_string() and zpool_state_to_name() return
a string literal which is read-only, thus they should return
`const char*`.

zpool_get_prop_string() returns a non-const string after
successful nv-lookup, and returns a string literal otherwise.
Since this function is designed to be used for read-only purpose,
the return type should also be `const char*`.

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Tomohiro Kusumi <kusumi.tomohiro@osnexus.com>
Closes #7285

cmd/zpool/zpool_main.c
include/libzfs.h
lib/libzfs/libzfs_crypto.c
lib/libzfs/libzfs_pool.c

index ae35cbf4b31e4eeca657cb8f0d1f3c99c31941b9..1d31fde469a53b30a2af225d2bfc4af33313355c 100644 (file)
@@ -1654,7 +1654,7 @@ print_status_config(zpool_handle_t *zhp, status_cbdata_t *cb, const char *name,
        char *vname;
        uint64_t notpresent;
        spare_cbdata_t spare_cb;
-       char *state;
+       const char *state;
        char *path = NULL;
 
        if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_CHILDREN,
index 71a588325f14b5cd9fc5eacf26acc91f27db8bc9..5288ff7f8c86695e9705567e1bbc46bcb1668ca9 100644 (file)
@@ -233,7 +233,7 @@ extern zpool_handle_t *zpool_open_canfail(libzfs_handle_t *, const char *);
 extern void zpool_close(zpool_handle_t *);
 extern const char *zpool_get_name(zpool_handle_t *);
 extern int zpool_get_state(zpool_handle_t *);
-extern char *zpool_state_to_name(vdev_state_t, vdev_aux_t);
+extern const char *zpool_state_to_name(vdev_state_t, vdev_aux_t);
 extern const char *zpool_pool_state_to_name(pool_state_t);
 extern void zpool_free_handles(libzfs_handle_t *);
 
index 6ccee740f6e88b537f8a3023bae9036e359352ce..9ad0fae7d2f36bfb79220a63e820dbfd9068377a 100644 (file)
@@ -130,7 +130,7 @@ catch_signal(int sig)
        caught_interrupt = sig;
 }
 
-static char *
+static const char *
 get_format_prompt_string(zfs_keyformat_t format)
 {
        switch (format) {
index 5f1414271dbb856b9db65fe2ad89eae56013edd8..cd14f2836262c11e8e2afc0d5ffe2266bda65852 100644 (file)
@@ -113,7 +113,7 @@ zpool_props_refresh(zpool_handle_t *zhp)
        return (0);
 }
 
-static char *
+static const char *
 zpool_get_prop_string(zpool_handle_t *zhp, zpool_prop_t prop,
     zprop_source_t *src)
 {
@@ -181,7 +181,7 @@ zpool_get_prop_int(zpool_handle_t *zhp, zpool_prop_t prop, zprop_source_t *src)
 /*
  * Map VDEV STATE to printed strings.
  */
-char *
+const char *
 zpool_state_to_name(vdev_state_t state, vdev_aux_t aux)
 {
        switch (state) {