Whamcloud - gitweb
Align function prototypes for libss's request handler function
[tools/e2fsprogs.git] / lib / ss / list_rqs.c
index 770f5f0..408d3ac 100644 (file)
  * this software for any purpose.  It is provided "as is" without
  * express or implied warranty.
  */
+#include "config.h"
 #include "ss_internal.h"
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
 #include <signal.h>
 #include <setjmp.h>
 #include <sys/wait.h>
 
 typedef void sigret_t;
 
-static char const twentyfive_spaces[26] =
-    "                         ";
-static char const NL[2] = "\n";
-
 void ss_list_requests(int argc __SS_ATTR((unused)),
-                     const char * const *argv __SS_ATTR((unused)),
+                     ss_argv_t argv __SS_ATTR((unused)),
                      int sci_idx, void *infop __SS_ATTR((unused)))
 {
     ss_request_entry *entry;
     char const * const *name;
-    int spacing;
+    int i, spacing;
     ss_request_table **table;
 
-    char buffer[BUFSIZ];
     FILE *output;
     int fd;
     sigset_t omask, igmask;
@@ -44,7 +43,18 @@ void ss_list_requests(int argc __SS_ATTR((unused)),
     sigprocmask(SIG_BLOCK, &igmask, &omask);
     func = signal(SIGINT, SIG_IGN);
     fd = ss_pager_create();
+    if (fd < 0) {
+        perror("ss_pager_create");
+        (void) signal(SIGINT, func);
+        return;
+    }
     output = fdopen(fd, "w");
+    if (!output) {
+        perror("fdopen");
+        close(fd);
+        (void) signal(SIGINT, func);
+        return;
+    }
     sigprocmask(SIG_SETMASK, &omask, (sigset_t *) 0);
 
     fprintf (output, "Available %s requests:\n\n",
@@ -54,27 +64,24 @@ void ss_list_requests(int argc __SS_ATTR((unused)),
         entry = (*table)->requests;
         for (; entry->command_names; entry++) {
             spacing = -2;
-            buffer[0] = '\0';
             if (entry->flags & SS_OPT_DONT_LIST)
                 continue;
             for (name = entry->command_names; *name; name++) {
                 int len = strlen(*name);
-                strncat(buffer, *name, len);
+                fputs(*name, output);
                 spacing += len + 2;
                 if (name[1]) {
-                    strcat(buffer, ", ");
+                    fputs(", ", output);
                 }
             }
             if (spacing > 23) {
-                strcat(buffer, NL);
-                fputs(buffer, output);
+                fputc('\n', output);
                 spacing = 0;
-                buffer[0] = '\0';
             }
-            strncat(buffer, twentyfive_spaces, 25-spacing);
-            strcat(buffer, entry->info_string);
-            strcat(buffer, NL);
-            fputs(buffer, output);
+            for (i = 0; i < 25 - spacing; i++)
+                fputc(' ', output);
+            fputs(entry->info_string, output);
+            fputc('\n', output);
         }
     }
     fclose(output);