[augeas-devel] Make a file-scoped static array "const"

Jim Meyering jim at meyering.net
Tue May 20 19:23:25 UTC 2008


changeset:   480:2212572bc990
tag:         tip
user:        Jim Meyering <meyering at redhat.com>
date:        Sun May 18 11:22:05 2008 +0200
files:       src/augtool.c
description:
Make a file-scoped static array "const".

* src/augtool.c [commands]: Make this variable "const".
(cmd_help, run_command): Make index pointers const, too.


diff --git a/src/augtool.c b/src/augtool.c
--- a/src/augtool.c
+++ b/src/augtool.c
@@ -37,7 +37,7 @@
     const char *help;
 };

-static struct command commands[];
+static const struct command const commands[];

 static augeas *aug = NULL;
 static const char *const progname = "augtool";
@@ -46,8 +46,6 @@
 char *loadpath = NULL;

 static char *cleanpath(char *path) {
-    if (strlen(path) == 0)
-        return path;
     char *e = path + strlen(path) - 1;
     while (e != path && (*e == SEP || isspace(*e)))
         *e-- = '\0';
@@ -231,7 +229,7 @@
 }

 static void cmd_help(ATTRIBUTE_UNUSED char *args[]) {
-    struct command *c;
+    const struct command *c;

     printf("Commands:\n\n");
     printf("    exit, quit\n        Exit the program\n\n");
@@ -299,7 +297,7 @@
     return cmd;
 }

-static struct command commands[] = {
+static const struct command const commands[] = {
     { "ls",  1, 1, cmd_ls, "ls <PATH>",
       "List the direct children of PATH"
     },
@@ -343,7 +341,7 @@

 static int run_command(char *cmd, int maxargs, char **args) {
     int r = 0;
-    struct command *c;
+    const struct command *c;

     if (STREQ("exit", cmd) || STREQ("quit", cmd)) {
         exit(EXIT_SUCCESS);




More information about the augeas-devel mailing list