Code

remove call_getopt and asprintf
authorKarl DeBisschop <kdebisschop@users.sourceforge.net>
Wed, 13 Nov 2002 11:50:54 +0000 (11:50 +0000)
committerKarl DeBisschop <kdebisschop@users.sourceforge.net>
Wed, 13 Nov 2002 11:50:54 +0000 (11:50 +0000)
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@190 f882894a-f735-0410-b71e-b25c423dba1c

plugins/check_disk.c
plugins/check_dns.c
plugins/check_fping.c
plugins/check_hpjd.c
plugins/check_mrtg.c
plugins/check_nwstat.c
plugins/check_ping.c
plugins/check_vsz.c
plugins/urlize.c
plugins/utils.c

index 9ce4a3248ee72329d78cc4ae5d181d41dc218f47..bde9563197bed419041a8f126a4dfe0c03450e9f 100644 (file)
 #include <stdarg.h>
 
 #define PROGNAME "check_disk"
+#define REVISION "$Revision$"
+#define COPYRIGHT "2000-2002"
 
 int process_arguments (int, char **);
-int call_getopt (int, char **);
 int validate_arguments (void);
 int check_disk (int usp, int free_disk);
 void print_help (void);
@@ -49,7 +50,7 @@ int w_df = -1;
 int c_df = -1;
 float w_dfp = -1.0;
 float c_dfp = -1.0;
-char *path = NULL;
+char *path = "";
 int verbose = FALSE;
 int display_mntp = FALSE;
 
@@ -73,7 +74,7 @@ main (int argc, char **argv)
        if (process_arguments (argc, argv) != OK)
                usage ("Could not parse arguments\n");
 
-       command_line = ssprintf (command_line, "%s %s", DF_COMMAND, path);
+       asprintf (&command_line, "%s %s", DF_COMMAND, path);
 
        if (verbose)
                printf ("%s ==> ", command_line);
@@ -175,41 +176,6 @@ process_arguments (int argc, char **argv)
 {
        int c;
 
-       if (argc < 2)
-               return ERROR;
-
-       for (c = 1; c < argc; c++) {
-               if (strcmp ("-to", argv[c]) == 0) {
-                       strcpy (argv[c], "-t");
-               }
-       }
-
-       c = 0;
-       while ((c += (call_getopt (argc - c, &argv[c]))) < argc) {
-
-               if (w_dfp == -1 && is_intnonneg (argv[c]))
-                       w_dfp = (100.0 - atof (argv[c]));
-               else if (c_dfp == -1 && is_intnonneg (argv[c]))
-                       c_dfp = (100.0 - atof (argv[c]));
-               else if (path == NULL || path[0] == 0)
-                       path = strscpy (path, argv[c]);
-       }
-
-       if (path == NULL) {
-               path = malloc (1);
-               if (path == NULL)
-                       terminate (STATE_UNKNOWN, "Could not malloc empty path\n");
-               path[0] = 0;
-       }
-
-       return validate_arguments ();
-}
-
-int
-call_getopt (int argc, char **argv)
-{
-       int c, i = 0;
-
 #ifdef HAVE_GETOPT_H
        int option_index = 0;
        static struct option long_options[] = {
@@ -226,27 +192,24 @@ call_getopt (int argc, char **argv)
        };
 #endif
 
+       if (argc < 2)
+               return ERROR;
+
+       for (c = 1; c < argc; c++)
+               if (strcmp ("-to", argv[c]) == 0)
+                       strcpy (argv[c], "-t");
+
        while (1) {
 #ifdef HAVE_GETOPT_H
                c =
-                       getopt_long (argc, argv, "+?Vhvt:c:w:p:m", long_options, &option_index);
+                       getopt_long (argc, argv, "Vhvt:c:w:p:m", long_options, &option_index);
 #else
-               c = getopt (argc, argv, "+?Vhvt:c:w:p:m");
+               c = getopt (argc, argv, "Vhvt:c:w:p:m");
 #endif
 
-               i++;
-
-               if (c == -1 || c == EOF || c == 1)
+               if (c == -1 || c == EOF)
                        break;
 
-               switch (c) {
-               case 't':
-               case 'c':
-               case 'w':
-               case 'p':
-                       i++;
-               }
-
                switch (c) {
                case 'w':                                                                       /* warning time threshold */
                        if (is_intnonneg (optarg)) {
@@ -298,7 +261,7 @@ call_getopt (int argc, char **argv)
                        display_mntp = TRUE;
                        break;
                case 'V':                                                                       /* version */
-                       print_revision (my_basename (argv[0]), "$Revision$");
+                       print_revision (PROGNAME, REVISION);
                        exit (STATE_OK);
                case 'h':                                                                       /* help */
                        print_help ();
@@ -308,7 +271,18 @@ call_getopt (int argc, char **argv)
                        break;
                }
        }
-       return i;
+
+       c = optind;
+       if (w_dfp == -1 && argc > c && is_intnonneg (argv[c]))
+               w_dfp = (100.0 - atof (argv[c++]));
+
+       if (c_dfp == -1 && argc > c && is_intnonneg (argv[c]))
+               c_dfp = (100.0 - atof (argv[c++]));
+
+       if (argc > c && strlen (path) == 0)
+               path = argv[c++];
+
+       return validate_arguments ();
 }
 
 int
@@ -358,7 +332,7 @@ check_disk (usp, free_disk)
 void
 print_help (void)
 {
-       print_revision (PROGNAME, "$Revision$");
+       print_revision (PROGNAME, REVISION);
        printf
                ("Copyright (c) 2000 Ethan Galstad/Karl DeBisschop\n\n"
                 "This plugin will check the percent of used disk space on a mounted\n"
index bc0400f86195562524614d17b51899c53ee7289a..f9cf28890ed2855548cac095371f1438953e2cc4 100644 (file)
 #include "popen.h"
 #include "utils.h"
 
+#define PROGNAME "check_dns"
+#define REVISION "$Revision$"
+#define COPYRIGHT "2000-2002"
+
 int process_arguments (int, char **);
-int call_getopt (int, char **);
 int validate_arguments (void);
-void print_usage (char *);
-void print_help (char *);
+void print_usage (void);
+void print_help (void);
 int error_scan (char *);
 
 #define ADDRESS_LENGTH 256
@@ -80,13 +83,12 @@ main (int argc, char **argv)
        }
 
        if (process_arguments (argc, argv) != OK) {
-               print_usage (my_basename (argv[0]));
+               print_usage ();
                return STATE_UNKNOWN;
        }
 
        /* get the command to run */
-       command_line = ssprintf (command_line, "%s %s %s", NSLOOKUP_COMMAND,
-               query_address, dns_server);
+       sprintf (&command_line, "%s %s %s", NSLOOKUP_COMMAND,   query_address, dns_server);
 
        alarm (timeout_interval);
        time (&start_time);
@@ -171,7 +173,7 @@ main (int argc, char **argv)
        /* compare to expected address */
        if (result == STATE_OK && match_expected_address && strcmp(address, expected_address)) {
                result = STATE_CRITICAL;
-               output = ssprintf(output, "expected %s but got %s", expected_address, address);
+               asprintf(&output, "expected %s but got %s", expected_address, address);
                }
        
        (void) time (&end_time);
@@ -256,46 +258,6 @@ process_arguments (int argc, char **argv)
 {
        int c;
 
-       if (argc < 2)
-               return ERROR;
-
-       for (c = 1; c < argc; c++)
-               if (strcmp ("-to", argv[c]) == 0)
-                       strcpy (argv[c], "-t");
-
-       c = 0;
-       while (c += (call_getopt (argc - c, &argv[c]))) {
-               if (argc <= c)
-                       break;
-               if (query_address[0] == 0) {
-                       if (is_host (argv[c]) == FALSE) {
-                               printf ("Invalid name/address: %s\n\n", argv[c]);
-                               return ERROR;
-                       }
-                       if (strlen (argv[c]) >= ADDRESS_LENGTH)
-                               terminate (STATE_UNKNOWN, "Input buffer overflow\n");
-                       strcpy (query_address, argv[c]);
-               }
-               else if (dns_server[0] == 0) {
-                       if (is_host (argv[c]) == FALSE) {
-                               printf ("Invalid name/address: %s\n\n", argv[c]);
-                               return ERROR;
-                       }
-                       if (strlen (argv[c]) >= ADDRESS_LENGTH)
-                               terminate (STATE_UNKNOWN, "Input buffer overflow\n");
-                       strcpy (dns_server, argv[c]);
-               }
-       }
-
-       return validate_arguments ();
-
-}
-
-int
-call_getopt (int argc, char **argv)
-{
-       int c, i = 1;
-
 #ifdef HAVE_GETOPT_H
        int opt_index = 0;
        static struct option long_opts[] = {
@@ -311,37 +273,33 @@ call_getopt (int argc, char **argv)
        };
 #endif
 
+       if (argc < 2)
+               return ERROR;
+
+       for (c = 1; c < argc; c++)
+               if (strcmp ("-to", argv[c]) == 0)
+                       strcpy (argv[c], "-t");
 
        while (1) {
 #ifdef HAVE_GETOPT_H
-               c = getopt_long (argc, argv, "+?hVvt:H:s:r:a:", long_opts, &opt_index);
+               c = getopt_long (argc, argv, "hVvt:H:s:r:a:", long_opts, &opt_index);
 #else
-               c = getopt (argc, argv, "+?hVvt:H:s:r:a:");
+               c = getopt (argc, argv, "hVvt:H:s:r:a:");
 #endif
 
                if (c == -1 || c == EOF)
                        break;
 
-               i++;
-               switch (c) {
-               case 't':
-               case 'H':
-               case 's':
-               case 'r':
-               case 'a':
-                       i++;
-               }
-
                switch (c) {
                case '?': /* args not parsable */
-                       printf ("%s: Unknown argument: %s\n\n", my_basename (argv[0]), optarg);
-                       print_usage (my_basename (argv[0]));
+                       printf ("%s: Unknown argument: %s\n\n", PROGNAME, optarg);
+                       print_usage ();
                        exit (STATE_UNKNOWN);
                case 'h': /* help */
-                       print_help (my_basename (argv[0]));
+                       print_help ();
                        exit (STATE_OK);
                case 'V': /* version */
-                       print_revision (my_basename (argv[0]), "$Revision$");
+                       print_revision (PROGNAME, REVISION);
                        exit (STATE_OK);
                case 'v': /* version */
                        verbose = TRUE;
@@ -352,7 +310,7 @@ call_getopt (int argc, char **argv)
                case 'H': /* hostname */
                        if (is_host (optarg) == FALSE) {
                                printf ("Invalid host name/address\n\n");
-                               print_usage (my_basename (argv[0]));
+                               print_usage ();
                                exit (STATE_UNKNOWN);
                        }
                        if (strlen (optarg) >= ADDRESS_LENGTH)
@@ -362,7 +320,7 @@ call_getopt (int argc, char **argv)
                case 's': /* server name */
                        if (is_host (optarg) == FALSE) {
                                printf ("Invalid server name/address\n\n");
-                               print_usage (my_basename (argv[0]));
+                               print_usage ();
                                exit (STATE_UNKNOWN);
                        }
                        if (strlen (optarg) >= ADDRESS_LENGTH)
@@ -372,7 +330,7 @@ call_getopt (int argc, char **argv)
                case 'r': /* reverse server name */
                        if (is_host (optarg) == FALSE) {
                                printf ("Invalid host name/address\n\n");
-                               print_usage (my_basename (argv[0]));
+                               print_usage ();
                                exit (STATE_UNKNOWN);
                        }
                        if (strlen (optarg) >= ADDRESS_LENGTH)
@@ -382,7 +340,7 @@ call_getopt (int argc, char **argv)
                case 'a': /* expected address */
                        if (is_dotted_quad (optarg) == FALSE) {
                                printf ("Invalid expected address\n\n");
-                               print_usage (my_basename (argv[0]));
+                               print_usage ();
                                exit (STATE_UNKNOWN);
                        }
                        if (strlen (optarg) >= ADDRESS_LENGTH)
@@ -392,7 +350,29 @@ call_getopt (int argc, char **argv)
                        break;
                }
        }
-       return i;
+
+       c = optind;
+       if (query_address[0] == 0) {
+               if (is_host (argv[c]) == FALSE) {
+                       printf ("Invalid name/address: %s\n\n", argv[c]);
+                       return ERROR;
+               }
+               if (strlen (argv[c]) >= ADDRESS_LENGTH)
+                       terminate (STATE_UNKNOWN, "Input buffer overflow\n");
+               strcpy (query_address, argv[c++]);
+       }
+
+       if (dns_server[0] == 0) {
+               if (is_host (argv[c]) == FALSE) {
+                       printf ("Invalid name/address: %s\n\n", argv[c]);
+                       return ERROR;
+               }
+               if (strlen (argv[c]) >= ADDRESS_LENGTH)
+                       terminate (STATE_UNKNOWN, "Input buffer overflow\n");
+               strcpy (dns_server, argv[c++]);
+       }
+
+       return validate_arguments ();
 }
 
 int
@@ -405,21 +385,21 @@ validate_arguments ()
 }
 
 void
-print_usage (char *cmd)
+print_usage (void)
 {
        printf ("Usage: %s -H host [-s server] [-a expected-address] [-t timeout]\n" "       %s --help\n"
-                                       "       %s --version\n", cmd, cmd, cmd);
+                                       "       %s --version\n", PROGNAME, PROGNAME, PROGNAME);
 }
 
 void
-print_help (char *cmd)
+print_help (void)
 {
-       print_revision (cmd, "$Revision$");
+       print_revision (PROGNAME, REVISION);
        printf ("Copyright (c) 1999 Ethan Galstad (nagios@nagios.org)\n\n");
-       print_usage (cmd);
-       printf ("\n");
+       print_usage ();
        printf
-               ("-H, --hostname=HOST\n"
+               ("\nOptions:\n"
+                "-H, --hostname=HOST\n"
                 "   The name or address you want to query\n"
                 "-s, --server=HOST\n"
                 "   Optional DNS server you want to use for the lookup\n"
index 9a2dd5570ba2b3b73f41fc5ec6ac775c6b341c05..da11e678091d36d319f10bd2ee25bf33d7597f94 100644 (file)
@@ -71,9 +71,8 @@ main (int argc, char **argv)
        server = strscpy (server, server_name);
 
        /* compose the command */
-       command_line = ssprintf
-               (command_line, "%s -b %d -c %d %s",
-                PATH_TO_FPING, packet_size, packet_count, server);
+       asprintf (&command_line, "%s -b %d -c %d %s", PATH_TO_FPING,
+                 packet_size, packet_count, server);
 
        if (verbose)
                printf ("%s\n", command_line);
index 6d42cd3866091f048d6601d9464fd3fb9f7f0ec0..42b4bb544d3e75b05637cc044159af57721c61e2 100644 (file)
@@ -66,6 +66,8 @@
 #include "utils.h"
 
 #define PROGNAME "check_hpjd"
+#define REVISION "$Revision$"
+#define COPYRIGHT "2000-2002"
 
 #define HPJD_LINE_STATUS               ".1.3.6.1.4.1.11.2.3.9.1.1.2.1"
 #define HPJD_PAPER_STATUS              ".1.3.6.1.4.1.11.2.3.9.1.1.2.2"
 #define OFFLINE                1
 
 int process_arguments (int, char **);
-int call_getopt (int, char **);
 int validate_arguments (void);
 void print_help (void);
 void print_usage (void);
 
 char *community = NULL;
-char *address = NULL;
+char *address = "127.0.0.1";
+
 
 int
 main (int argc, char **argv)
@@ -386,55 +388,6 @@ process_arguments (int argc, char **argv)
 {
        int c;
 
-       if (argc < 2)
-               return ERROR;
-
-       for (c = 1; c < argc; c++) {
-               if (strcmp ("-to", argv[c]) == 0)
-                       strcpy (argv[c], "-t");
-               else if (strcmp ("-wt", argv[c]) == 0)
-                       strcpy (argv[c], "-w");
-               else if (strcmp ("-ct", argv[c]) == 0)
-                       strcpy (argv[c], "-c");
-       }
-
-
-
-       c = 0;
-       while ((c += (call_getopt (argc - c, &argv[c]))) < argc) {
-
-               if (is_option (argv[c]))
-                       continue;
-
-               if (address == NULL) {
-                       if (is_host (argv[c])) {
-                               address = argv[c];
-                       }
-                       else {
-                               usage ("Invalid host name");
-                       }
-               }
-               else if (community == NULL) {
-                       community = argv[c];
-               }
-       }
-
-       if (address == NULL)
-               address = strscpy (NULL, "127.0.0.1");
-
-       return validate_arguments ();
-}
-
-
-
-
-
-
-int
-call_getopt (int argc, char **argv)
-{
-       int c, i = 0;
-
 #ifdef HAVE_GETOPT_H
        int option_index = 0;
        static struct option long_options[] = {
@@ -450,6 +403,18 @@ call_getopt (int argc, char **argv)
        };
 #endif
 
+       if (argc < 2)
+               return ERROR;
+
+       for (c = 1; c < argc; c++) {
+               if (strcmp ("-to", argv[c]) == 0)
+                       strcpy (argv[c], "-t");
+               else if (strcmp ("-wt", argv[c]) == 0)
+                       strcpy (argv[c], "-w");
+               else if (strcmp ("-ct", argv[c]) == 0)
+                       strcpy (argv[c], "-c");
+       }
+
        while (1) {
 #ifdef HAVE_GETOPT_H
                c = getopt_long (argc, argv, "+hVH:C:", long_options, &option_index);
@@ -457,17 +422,9 @@ call_getopt (int argc, char **argv)
                c = getopt (argc, argv, "+?hVH:C:");
 #endif
 
-               i++;
-
                if (c == -1 || c == EOF || c == 1)
                        break;
 
-               switch (c) {
-               case 'H':
-               case 'C':
-                       i++;
-               }
-
                switch (c) {
                case 'H':                                                                       /* hostname */
                        if (is_host (optarg)) {
@@ -481,7 +438,7 @@ call_getopt (int argc, char **argv)
                        community = optarg;
                        break;
                case 'V':                                                                       /* version */
-                       print_revision (PROGNAME, "$Revision$");
+                       print_revision (PROGNAME, REVISION);
                        exit (STATE_OK);
                case 'h':                                                                       /* help */
                        print_help ();
@@ -490,7 +447,22 @@ call_getopt (int argc, char **argv)
                        usage ("Invalid argument\n");
                }
        }
-       return i;
+
+       c = optind;
+       if (address == NULL) {
+               if (is_host (argv[c])) {
+                       address = argv[c++];
+               }
+               else {
+                       usage ("Invalid host name");
+               }
+       }
+
+       if (community == NULL) {
+               community = argv[c++];
+       }
+
+       return validate_arguments ();
 }
 
 
@@ -510,7 +482,7 @@ validate_arguments (void)
 void
 print_help (void)
 {
-       print_revision (PROGNAME, "$Revision$");
+       print_revision (PROGNAME, REVISION);
        printf
                ("Copyright (c) 2000 Ethan Galstad/Karl DeBisschop\n\n"
                 "This plugin tests the STATUS of an HP printer with a JetDirect card.\n"
index b86686d728116c4375f89612bac787fa0f7e3af2..4d297aaa1f70f20293c1bff3da26e3b6fd912e65 100644 (file)
@@ -86,7 +86,6 @@ Notes:\n\
 #include "utils.h"
 
 int process_arguments (int, char **);
-int call_getopt (int, char **);
 int validate_arguments (void);
 void print_help (void);
 void print_usage (void);
@@ -97,8 +96,8 @@ int use_average = TRUE;
 int variable_number = -1;
 unsigned long value_warning_threshold = 0L;
 unsigned long value_critical_threshold = 0L;
-char *value_label = NULL;
-char *units_label = NULL;
+char *value_label = "";
+char *units_label = "";
 
 int
 main (int argc, char **argv)
@@ -215,83 +214,6 @@ process_arguments (int argc, char **argv)
 {
        int c;
 
-       if (argc < 2)
-               return ERROR;
-
-       for (c = 1; c < argc; c++) {
-               if (strcmp ("-to", argv[c]) == 0)
-                       strcpy (argv[c], "-t");
-               else if (strcmp ("-wt", argv[c]) == 0)
-                       strcpy (argv[c], "-w");
-               else if (strcmp ("-ct", argv[c]) == 0)
-                       strcpy (argv[c], "-c");
-       }
-
-
-
-       c = 0;
-       while ((c += (call_getopt (argc - c, &argv[c]))) < argc) {
-
-               if (is_option (argv[c]))
-                       continue;
-
-               if (log_file == NULL) {
-                       log_file = argv[c];
-               }
-               else if (expire_minutes <= 0) {
-                       if (is_intpos (argv[c]))
-                               expire_minutes = atoi (argv[c]);
-                       else
-                               terminate (STATE_UNKNOWN,
-                                                                        "%s is not a valid expiration time\nUse '%s -h' for additional help\n",
-                                                                        argv[c], PROGNAME);
-               }
-               else if (strcmp (argv[c], "MAX") == 0) {
-                       use_average = FALSE;
-               }
-               else if (strcmp (argv[c], "AVG") == 0) {
-                       use_average = TRUE;
-               }
-               else if (variable_number == -1) {
-                       variable_number = atoi (argv[c]);
-                       if (variable_number < 1 || variable_number > 2) {
-                               printf ("%s :", argv[c]);
-                               usage ("Invalid variable number\n");
-                       }
-               }
-               else if (value_warning_threshold == 0) {
-                       value_warning_threshold = strtoul (argv[c], NULL, 10);
-               }
-               else if (value_critical_threshold == 0) {
-                       value_critical_threshold = strtoul (argv[c], NULL, 10);
-               }
-               else if (value_label == NULL) {
-                       value_label = argv[c];
-               }
-               else if (units_label == NULL) {
-                       units_label = argv[c];
-               }
-       }
-
-       if (value_label == NULL)
-               value_label = strscpy (NULL, "");
-
-       if (units_label == NULL)
-               units_label = strscpy (NULL, "");
-
-       return validate_arguments ();
-}
-
-
-
-
-
-
-int
-call_getopt (int argc, char **argv)
-{
-       int c, i = 0;
-
 #ifdef HAVE_GETOPT_H
        int option_index = 0;
        static struct option long_options[] = {
@@ -310,32 +232,30 @@ call_getopt (int argc, char **argv)
        };
 #endif
 
+       if (argc < 2)
+               return ERROR;
+
+       for (c = 1; c < argc; c++) {
+               if (strcmp ("-to", argv[c]) == 0)
+                       strcpy (argv[c], "-t");
+               else if (strcmp ("-wt", argv[c]) == 0)
+                       strcpy (argv[c], "-w");
+               else if (strcmp ("-ct", argv[c]) == 0)
+                       strcpy (argv[c], "-c");
+       }
+
        while (1) {
 #ifdef HAVE_GETOPT_H
                c =
-                       getopt_long (argc, argv, "+hVF:e:a:v:c:w:l:u:", long_options,
+                       getopt_long (argc, argv, "hVF:e:a:v:c:w:l:u:", long_options,
                                                                         &option_index);
 #else
-               c = getopt (argc, argv, "+?hVF:e:a:v:c:w:l:u:");
+               c = getopt (argc, argv, "hVF:e:a:v:c:w:l:u:");
 #endif
 
-               i++;
-
-               if (c == -1 || c == EOF || c == 1)
+               if (c == -1 || c == EOF)
                        break;
 
-               switch (c) {
-               case 'F':
-               case 'e':
-               case 'a':
-               case 'v':
-               case 'c':
-               case 'w':
-               case 'l':
-               case 'u':
-                       i++;
-               }
-
                switch (c) {
                case 'F':                                                                       /* input file */
                        log_file = optarg;
@@ -367,7 +287,7 @@ call_getopt (int argc, char **argv)
                        units_label = optarg;
                        break;
                case 'V':                                                                       /* version */
-                       print_revision (PROGNAME, "$Revision$");
+                       print_revision (PROGNAME, REVISION);
                        exit (STATE_OK);
                case 'h':                                                                       /* help */
                        print_help ();
@@ -376,7 +296,55 @@ call_getopt (int argc, char **argv)
                        usage ("Invalid argument\n");
                }
        }
-       return i;
+
+       c = optind;
+       if (log_file == NULL && argc > c) {
+               log_file = argv[c++];
+       }
+
+       if (expire_minutes <= 0 && argc > c) {
+               if (is_intpos (argv[c]))
+                       expire_minutes = atoi (argv[c++]);
+               else
+                       terminate (STATE_UNKNOWN,
+                                  "%s is not a valid expiration time\nUse '%s -h' for additional help\n",
+                                  argv[c], PROGNAME);
+       }
+
+       if (argc > c && strcmp (argv[c], "MAX") == 0) {
+               use_average = FALSE;
+               c++;
+       }
+       else if (argc > c && strcmp (argv[c], "AVG") == 0) {
+               use_average = TRUE;
+               c++;
+       }
+
+       if (argc > c && variable_number == -1) {
+               variable_number = atoi (argv[c++]);
+               if (variable_number < 1 || variable_number > 2) {
+                       printf ("%s :", argv[c]);
+                       usage ("Invalid variable number\n");
+               }
+       }
+
+       if (argc > c && value_warning_threshold == 0) {
+               value_warning_threshold = strtoul (argv[c++], NULL, 10);
+       }
+
+       if (vargc > c && alue_critical_threshold == 0) {
+               value_critical_threshold = strtoul (argv[c++], NULL, 10);
+       }
+
+       if (argc > c && strlen (value_label) == 0) {
+               value_label = argv[c++];
+       }
+
+       if (argc > c && strlen (units_label) == 0) {
+               units_label = argv[c++];
+       }
+
+       return validate_arguments ();
 }
 
 int
index e1426702c5f0a7710d78ddbcef3533519c25b4f7..f8fca736d179207fecc57dacd614773674232ac2 100644 (file)
@@ -180,13 +180,13 @@ int main(int argc, char **argv){
                if(result!=STATE_OK)
                        return result;
                if(!strcmp(recv_buffer,"-1\n"))
-                       netware_version = ssprintf(netware_version,"");
+                       asprintf(&netware_version,"");
                else {
                        recv_buffer[strlen(recv_buffer)-1]=0;
-                       netware_version = ssprintf(netware_version,"NetWare %s: ",recv_buffer);
+                       asprintf(&netware_version,"NetWare %s: ",recv_buffer);
                }
        } else
-               netware_version = ssprintf(netware_version,"");
+               asprintf(&netware_version,"");
 
 
        /* check CPU load */
@@ -204,7 +204,7 @@ int main(int argc, char **argv){
                        break;
                }
 
-               send_buffer = ssprintf(send_buffer,"UTIL%s\r\n",temp_buffer);
+               asprintf(&send_buffer,"UTIL%s\r\n",temp_buffer);
                result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer));
                if(result!=STATE_OK)
                        return result;
@@ -221,7 +221,7 @@ int main(int argc, char **argv){
                else if(check_warning_value==TRUE && utilization >= warning_value)
                        result=STATE_WARNING;
 
-               output_message = ssprintf(output_message,"Load %s - %s %s-min load average = %lu%%",(result==STATE_OK)?"ok":"problem",uptime,temp_buffer,utilization);
+               asprintf(&output_message,"Load %s - %s %s-min load average = %lu%%",(result==STATE_OK)?"ok":"problem",uptime,temp_buffer,utilization);
 
        /* check number of user connections */
        } else if (vars_to_check==CHECK_CONNS) {
@@ -236,7 +236,7 @@ int main(int argc, char **argv){
                        result=STATE_CRITICAL;
                else if(check_warning_value==TRUE && current_connections >= warning_value)
                        result=STATE_WARNING;
-               output_message = ssprintf(output_message,"Conns %s - %lu current connections",(result==STATE_OK)?"ok":"problem",current_connections);
+               asprintf(&output_message,"Conns %s - %lu current connections",(result==STATE_OK)?"ok":"problem",current_connections);
 
        /* check % long term cache hits */
        } else if (vars_to_check==CHECK_LTCH) {
@@ -251,7 +251,7 @@ int main(int argc, char **argv){
                        result=STATE_CRITICAL;
                else if(check_warning_value==TRUE && cache_hits <= warning_value)
                        result=STATE_WARNING;
-               output_message = ssprintf(output_message,"Long term cache hits = %d%%",cache_hits);
+               asprintf(&output_message,"Long term cache hits = %d%%",cache_hits);
 
        /* check cache buffers */
        } else if (vars_to_check==CHECK_CBUFF) {
@@ -266,7 +266,7 @@ int main(int argc, char **argv){
                        result=STATE_CRITICAL;
                else if(check_warning_value==TRUE && cache_buffers <= warning_value)
                        result=STATE_WARNING;
-               output_message = ssprintf(output_message,"Total cache buffers = %lu",cache_buffers);
+               asprintf(&output_message,"Total cache buffers = %lu",cache_buffers);
 
        /* check dirty cache buffers */
        } else if (vars_to_check==CHECK_CDBUFF) {
@@ -281,7 +281,7 @@ int main(int argc, char **argv){
                        result=STATE_CRITICAL;
                else if(check_warning_value==TRUE && cache_buffers >= warning_value)
                        result=STATE_WARNING;
-               output_message = ssprintf(output_message,"Dirty cache buffers = %lu",cache_buffers);
+               asprintf(&output_message,"Dirty cache buffers = %lu",cache_buffers);
 
        /* check LRU sitting time in minutes */
        } else if (vars_to_check==CHECK_LRUM) {
@@ -296,19 +296,19 @@ int main(int argc, char **argv){
                        result=STATE_CRITICAL;
                else if(check_warning_value==TRUE && lru_time <= warning_value)
                        result=STATE_WARNING;
-               output_message = ssprintf(output_message,"LRU sitting time = %lu minutes",lru_time);
+               sprintf(&output_message,"LRU sitting time = %lu minutes",lru_time);
 
 
        /* check KB free space on volume */
        } else if (vars_to_check==CHECK_VKF) {
 
-               send_buffer = ssprintf(send_buffer,"VKF%s\r\n",volume_name);
+               asprintf(&send_buffer,"VKF%s\r\n",volume_name);
                result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer));
                if(result!=STATE_OK)
                        return result;
 
                if (!strcmp(recv_buffer,"-1\n")) {
-                       output_message = ssprintf(output_message,"Error: Volume '%s' does not exist!",volume_name);
+                       asprintf(&output_message,"Error: Volume '%s' does not exist!",volume_name);
                        result=STATE_CRITICAL;
                }       else {
                        free_disk_space=strtoul(recv_buffer,NULL,10);
@@ -316,27 +316,27 @@ int main(int argc, char **argv){
                                result=STATE_CRITICAL;
                        else if(check_warning_value==TRUE && free_disk_space <= warning_value)
                                result=STATE_WARNING;
-                       output_message = ssprintf(output_message,"%s%lu KB free on volume %s",(result==STATE_OK)?"":"Only ",free_disk_space,volume_name);
+                       asprintf(&output_message,"%s%lu KB free on volume %s",(result==STATE_OK)?"":"Only ",free_disk_space,volume_name);
                }
 
        /* check % free space on volume */
        } else if (vars_to_check==CHECK_VPF) {
 
-               send_buffer = ssprintf(send_buffer,"VKF%s\r\n",volume_name);
+               asprintf(&send_buffer,"VKF%s\r\n",volume_name);
                result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer));
                if(result!=STATE_OK)
                        return result;
 
                if(!strcmp(recv_buffer,"-1\n")){
 
-                       output_message = ssprintf(output_message,"Error: Volume '%s' does not exist!",volume_name);
+                       asprintf(&output_message,"Error: Volume '%s' does not exist!",volume_name);
                        result=STATE_CRITICAL;
 
                } else {
 
                        free_disk_space=strtoul(recv_buffer,NULL,10);
 
-                       send_buffer = ssprintf(send_buffer,"VKS%s\r\n",volume_name);
+                       asprintf(&send_buffer,"VKS%s\r\n",volume_name);
                        result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer));
                        if(result!=STATE_OK)
                                return result;
@@ -349,7 +349,7 @@ int main(int argc, char **argv){
                        else if(check_warning_value==TRUE && percent_free_space <= warning_value)
                                result=STATE_WARNING;
                        free_disk_space/=1024;
-                       output_message = ssprintf(output_message,"%lu MB (%d%%) free on volume %s",free_disk_space,percent_free_space,volume_name);
+                       asprintf(&output_message,"%lu MB (%d%%) free on volume %s",free_disk_space,percent_free_space,volume_name);
                }
 
        /* check to see if DS Database is open or closed */
@@ -368,7 +368,7 @@ int main(int argc, char **argv){
                result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer));
                temp_buffer=strtok(recv_buffer,"\r\n");
  
-               output_message = ssprintf(output_message,"Directory Services Database is %s (DS version %s)",(result==STATE_OK)?"open":"closed",temp_buffer);
+               asprintf(&output_message,"Directory Services Database is %s (DS version %s)",(result==STATE_OK)?"open":"closed",temp_buffer);
 
        /* check to see if logins are enabled */
        } else if (vars_to_check==CHECK_LOGINS) {
@@ -382,19 +382,19 @@ int main(int argc, char **argv){
                else
                        result=STATE_WARNING;
  
-               output_message = ssprintf(output_message,"Logins are %s",(result==STATE_OK)?"enabled":"disabled");
+               asprintf(&output_message,"Logins are %s",(result==STATE_OK)?"enabled":"disabled");
 
        /* check packet receive buffers */
        } else if (vars_to_check==CHECK_UPRB || vars_to_check==CHECK_PUPRB) {
  
-               send_buffer = ssprintf(send_buffer,"S15\r\n",volume_name);
+               asprintf(&send_buffer,"S15\r\n",volume_name);
                result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer));
                if(result!=STATE_OK)
                        return result;
 
                used_packet_receive_buffers=atoi(recv_buffer);
 
-               send_buffer = ssprintf(send_buffer,"S16\r\n",volume_name);
+               asprintf(&send_buffer,"S16\r\n",volume_name);
                result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer));
                if(result!=STATE_OK)
                        return result;
@@ -415,15 +415,15 @@ int main(int argc, char **argv){
                                result=STATE_WARNING;
                }
  
-               output_message = ssprintf(output_message,"%d of %d (%lu%%) packet receive buffers used",used_packet_receive_buffers,max_packet_receive_buffers,percent_used_packet_receive_buffers);
+               asprintf(&output_message,"%d of %d (%lu%%) packet receive buffers used",used_packet_receive_buffers,max_packet_receive_buffers,percent_used_packet_receive_buffers);
 
        /* check SAP table entries */
        } else if (vars_to_check==CHECK_SAPENTRIES) {
 
                if(sap_number==-1)
-                       send_buffer = ssprintf(send_buffer,"S9\r\n");
+                       asprintf(&send_buffer,"S9\r\n");
                else
-                       send_buffer = ssprintf(send_buffer,"S9.%d\r\n",sap_number);
+                       asprintf(&send_buffer,"S9.%d\r\n",sap_number);
                result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer));
                if(result!=STATE_OK)
                        return result;
@@ -436,20 +436,20 @@ int main(int argc, char **argv){
                        result=STATE_WARNING;
 
                if(sap_number==-1)
-                       output_message = ssprintf(output_message,"%d entries in SAP table",sap_entries);
+                       asprintf(&output_message,"%d entries in SAP table",sap_entries);
                else
-                       output_message = ssprintf(output_message,"%d entries in SAP table for SAP type %d",sap_entries,sap_number);
+                       asprintf(&output_message,"%d entries in SAP table for SAP type %d",sap_entries,sap_number);
 
        /* check KB purgeable space on volume */
        } else if (vars_to_check==CHECK_VKP) {
 
-               send_buffer = ssprintf(send_buffer,"VKP%s\r\n",volume_name);
+               asprintf(&send_buffer,"VKP%s\r\n",volume_name);
                result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer));
                if(result!=STATE_OK)
                        return result;
 
                if (!strcmp(recv_buffer,"-1\n")) {
-                       output_message = ssprintf(output_message,"Error: Volume '%s' does not exist!",volume_name);
+                       asprintf(&output_message,"Error: Volume '%s' does not exist!",volume_name);
                        result=STATE_CRITICAL;
                } else {
                        purgeable_disk_space=strtoul(recv_buffer,NULL,10);
@@ -457,27 +457,27 @@ int main(int argc, char **argv){
                                result=STATE_CRITICAL;
                        else if(check_warning_value==TRUE && purgeable_disk_space >= warning_value)
                                result=STATE_WARNING;
-                       output_message = ssprintf(output_message,"%s%lu KB purgeable on volume %s",(result==STATE_OK)?"":"Only ",purgeable_disk_space,volume_name);
+                       asprintf(&output_message,"%s%lu KB purgeable on volume %s",(result==STATE_OK)?"":"Only ",purgeable_disk_space,volume_name);
                }
 
        /* check % purgeable space on volume */
        } else if (vars_to_check==CHECK_VPP) {
 
-               send_buffer = ssprintf(send_buffer,"VKP%s\r\n",volume_name);
+               asprintf(&send_buffer,"VKP%s\r\n",volume_name);
                result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer));
                if(result!=STATE_OK)
                        return result;
 
                if(!strcmp(recv_buffer,"-1\n")){
 
-                       output_message = ssprintf(output_message,"Error: Volume '%s' does not exist!",volume_name);
+                       asprintf(&output_message,"Error: Volume '%s' does not exist!",volume_name);
                        result=STATE_CRITICAL;
 
                } else {
 
                        purgeable_disk_space=strtoul(recv_buffer,NULL,10);
 
-                       send_buffer = ssprintf(send_buffer,"VKS%s\r\n",volume_name);
+                       asprintf(&send_buffer,"VKS%s\r\n",volume_name);
                        result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer));
                        if(result!=STATE_OK)
                                return result;
@@ -490,19 +490,19 @@ int main(int argc, char **argv){
                        else if(check_warning_value==TRUE && percent_purgeable_space >= warning_value)
                                result=STATE_WARNING;
                        purgeable_disk_space/=1024;
-                       output_message = ssprintf(output_message,"%lu MB (%d%%) purgeable on volume %s",purgeable_disk_space,percent_purgeable_space,volume_name);
+                       asprintf(&output_message,"%lu MB (%d%%) purgeable on volume %s",purgeable_disk_space,percent_purgeable_space,volume_name);
                }
 
        /* check KB not yet purgeable space on volume */
        } else if (vars_to_check==CHECK_VKNP) {
 
-               send_buffer = ssprintf(send_buffer,"VKNP%s\r\n",volume_name);
+               asprintf(&send_buffer,"VKNP%s\r\n",volume_name);
                result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer));
                if(result!=STATE_OK)
                        return result;
 
                if (!strcmp(recv_buffer,"-1\n")) {
-                       output_message = ssprintf(output_message,"Error: Volume '%s' does not exist!",volume_name);
+                       asprintf(&output_message,"Error: Volume '%s' does not exist!",volume_name);
                        result=STATE_CRITICAL;
                } else {
                        non_purgeable_disk_space=strtoul(recv_buffer,NULL,10);
@@ -510,27 +510,27 @@ int main(int argc, char **argv){
                                result=STATE_CRITICAL;
                        else if(check_warning_value==TRUE && non_purgeable_disk_space >= warning_value)
                                result=STATE_WARNING;
-                       output_message = ssprintf(output_message,"%s%lu KB not yet purgeable on volume %s",(result==STATE_OK)?"":"Only ",non_purgeable_disk_space,volume_name);
+                       asprintf(&output_message,"%s%lu KB not yet purgeable on volume %s",(result==STATE_OK)?"":"Only ",non_purgeable_disk_space,volume_name);
                }
 
        /* check % not yet purgeable space on volume */
        } else if (vars_to_check==CHECK_VPNP) {
 
-               send_buffer = ssprintf(send_buffer,"VKNP%s\r\n",volume_name);
+               asprintf(&send_buffer,"VKNP%s\r\n",volume_name);
                result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer));
                if(result!=STATE_OK)
                        return result;
 
                if(!strcmp(recv_buffer,"-1\n")){
 
-                       output_message = ssprintf(output_message,"Error: Volume '%s' does not exist!",volume_name);
+                       asprintf(&output_message,"Error: Volume '%s' does not exist!",volume_name);
                        result=STATE_CRITICAL;
 
                } else {
 
                        non_purgeable_disk_space=strtoul(recv_buffer,NULL,10);
 
-                       send_buffer = ssprintf(send_buffer,"VKS%s\r\n",volume_name);
+                       asprintf(&send_buffer,"VKS%s\r\n",volume_name);
                        result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer));
                        if(result!=STATE_OK)
                                return result;
@@ -543,13 +543,13 @@ int main(int argc, char **argv){
                        else if(check_warning_value==TRUE && percent_non_purgeable_space >= warning_value)
                                result=STATE_WARNING;
                        purgeable_disk_space/=1024;
-                       output_message = ssprintf(output_message,"%lu MB (%d%%) not yet purgeable on volume %s",non_purgeable_disk_space,percent_non_purgeable_space,volume_name);
+                       asprintf(&output_message,"%lu MB (%d%%) not yet purgeable on volume %s",non_purgeable_disk_space,percent_non_purgeable_space,volume_name);
                }
 
        /* check # of open files */
        } else if (vars_to_check==CHECK_OFILES) {
 
-               send_buffer = ssprintf(send_buffer,"S18\r\n");
+               asprintf(&send_buffer,"S18\r\n");
                result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer));
                if(result!=STATE_OK)
                        return result;
@@ -561,12 +561,12 @@ int main(int argc, char **argv){
                else if(check_warning_value==TRUE && open_files >= warning_value)
                        result=STATE_WARNING;
 
-               output_message = ssprintf(output_message,"%d open files",open_files);
+               asprintf(&output_message,"%d open files",open_files);
 
        /* check # of abended threads (Netware 5.x only) */
        } else if (vars_to_check==CHECK_ABENDS) {
 
-               send_buffer = ssprintf(send_buffer,"S17\r\n");
+               asprintf(&send_buffer,"S17\r\n");
                result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer));
                if(result!=STATE_OK)
                        return result;
@@ -578,19 +578,19 @@ int main(int argc, char **argv){
                else if(check_warning_value==TRUE && abended_threads >= warning_value)
                        result=STATE_WARNING;
 
-               output_message = ssprintf(output_message,"%d abended threads",abended_threads);
+               asprintf(&output_message,"%d abended threads",abended_threads);
 
        /* check # of current service processes (Netware 5.x only) */
        } else if (vars_to_check==CHECK_CSPROCS) {
 
-               send_buffer = ssprintf(send_buffer,"S20\r\n");
+               asprintf(&send_buffer,"S20\r\n");
                result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer));
                if(result!=STATE_OK)
                        return result;
  
                max_service_processes=atoi(recv_buffer);
  
-               send_buffer = ssprintf(send_buffer,"S21\r\n");
+               sprintf(&send_buffer,"S21\r\n");
                result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer));
                if(result!=STATE_OK)
                        return result;
@@ -602,7 +602,7 @@ int main(int argc, char **argv){
                else if(check_warning_value==TRUE && current_service_processes >= warning_value)
                        result=STATE_WARNING;
 
-               output_message = ssprintf(output_message,"%d current service processes (%d max)",current_service_processes,max_service_processes);
+               asprintf(&output_message,"%d current service processes (%d max)",current_service_processes,max_service_processes);
 
        } else {
 
index df1d9eb2025c4ec4750538cafce3add20491bd65..3602122c28abd4a6288e266bc4f5f79b8c21380b 100644 (file)
@@ -88,11 +88,9 @@ main (int argc, char **argv)
 
        /* does the host address of number of packets argument come first? */
 #ifdef PING_PACKETS_FIRST
-       command_line =
-               ssprintf (command_line, PING_COMMAND, max_packets, server_address);
+       asprintf (&command_line, PING_COMMAND, max_packets, server_address);
 #else
-       command_line =
-               ssprintf (command_line, PING_COMMAND, server_address, max_packets);
+       asprintf (&command_line, PING_COMMAND, server_address, max_packets);
 #endif
 
        /* Set signal handling and alarm */
index 2ec8775b574638791ec880fcfac0fbb6e905b430..7eeab22cc9d48af2e2ef50598b3e6ad0811c0088 100644 (file)
@@ -61,7 +61,7 @@ main (int argc, char **argv)
        int proc_size = -1;
        char input_buffer[MAX_INPUT_BUFFER];
        char proc_name[MAX_INPUT_BUFFER];
-       char *message = NULL;
+       char *message = "";
 
        if (!process_arguments (argc, argv)) {
                printf ("%s: failure parsing arguments\n", my_basename (argv[0]));
@@ -80,8 +80,6 @@ main (int argc, char **argv)
        if (child_stderr == NULL)
                printf ("Could not open stderr for %s\n", VSZ_COMMAND);
 
-       message = malloc ((size_t) 1);
-       message[0] = 0;
        while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process)) {
 
                line++;
@@ -93,12 +91,7 @@ main (int argc, char **argv)
                if (sscanf (input_buffer, VSZ_FORMAT, &proc_size, proc_name) == 2) {
                        if (proc == NULL) {
                                if (proc_size > warn) {
-                                       len = strlen (message) + strlen (proc_name) + 23;
-                                       message = realloc (message, len);
-                                       if (message == NULL)
-                                               terminate (STATE_UNKNOWN,
-                                                                                        "check_vsz: could not malloc message (1)");
-                                       sprintf (message, "%s %s(%d)", message, proc_name, proc_size);
+                                       asprintf (&message, "%s %s(%d)", message, proc_name, proc_size);
                                        result = max_state (result, STATE_WARNING);
                                }
                                if (proc_size > crit) {
@@ -106,12 +99,7 @@ main (int argc, char **argv)
                                }
                        }
                        else if (strstr (proc_name, proc)) {
-                               len = strlen (message) + 21;
-                               message = realloc (message, len);
-                               if (message == NULL)
-                                       terminate (STATE_UNKNOWN,
-                                                                                "check_vsz: could not malloc message (2)");
-                               sprintf (message, "%s %d", message, proc_size);
+                               asprintf (&message, "%s %d", message, proc_size);
                                if (proc_size > warn) {
                                        result = max_state (result, STATE_WARNING);
                                }
@@ -206,11 +194,7 @@ process_arguments (int argc, char **argv)
                        warn = atoi (optarg);
                        break;
                case 'C':                                                                       /* command name */
-                       proc = malloc (strlen (optarg) + 1);
-                       if (proc == NULL)
-                               terminate (STATE_UNKNOWN,
-                                                                        "check_vsz: failed malloc of proc in process_arguments");
-                       strcpy (proc, optarg);
+                       proc = optarg;
                        break;
                }
        }
@@ -236,13 +220,8 @@ process_arguments (int argc, char **argv)
                crit = atoi (argv[c++]);
        }
 
-       if (proc == NULL) {
-               proc = malloc (strlen (argv[c]) + 1);
-               if (proc == NULL)
-                       terminate (STATE_UNKNOWN,
-                                                                "check_vsz: failed malloc of proc in process_arguments");
-               strcpy (proc, argv[c]);
-       }
+       if (proc == NULL)
+               proc = argv[c];
 
        return c;
 }
index 9e02cb5d140340527605946dc9c889a937612d11..9835c824d4c1fbf38d2dc0e1f4324b7d9ab20d47 100644 (file)
@@ -71,9 +71,9 @@ main (int argc, char **argv)
                exit (STATE_UNKNOWN);
        }
 
-       cmd = ssprintf (cmd, "%s", argv[2]);
+       asprintf (&cmd, "%s", argv[2]);
        for (i = 3; i < argc; i++) {
-               cmd = ssprintf (cmd, "%s %s", cmd, argv[i]);
+               asprintf (&cmd, "%s %s", cmd, argv[i]);
        }
 
        child_process = spopen (cmd);
index bf1d20479d034c3ee979d5ad386ec2877de11e17..5dc6cfdbc5502dc4a6e8f31bb0e0feea20e4f51b 100644 (file)
@@ -50,7 +50,6 @@ void strip (char *);
 char *strscpy (char *dest, const char *src);
 char *strscat (char *dest, const char *src);
 char *strnl (char *str);
-char *ssprintf (char *str, const char *fmt, ...);
 char *strpcpy (char *dest, const char *src, const char *str);
 char *strpcat (char *dest, const char *src, const char *str);
 
@@ -494,72 +493,6 @@ strnl (char *str)
 
 
 
-/******************************************************************************
- *
- * Does a formatted print to a string variable
- *
- * Given a pointer destination string, which may or may not already
- * hold some text, and a source string with additional text (possibly
- * NULL or empty), returns a pointer to a string that cntains the
- * results of the specified formatted print
- *
- * Example:
- *
- * char *str=NULL;
- * str = ssprintf(str,"%d %s",1,"string");
- *
- *****************************************************************************/
-
-char *
-ssprintf (char *ptr, const char *fmt, ...)
-{
-       va_list ap;
-       int nchars;
-       size_t size;
-       char *str = NULL;
-
-       if (str == NULL) {
-               str = malloc (TXTBLK);
-               if (str == NULL)
-                       terminate (STATE_UNKNOWN, "malloc failed in ssprintf");
-               size = TXTBLK;
-       }
-       else
-               size = max (strlen (str), TXTBLK);
-
-       va_start (ap, fmt);
-
-       while (1) {
-
-               nchars = vsnprintf (str, size, fmt, ap);
-
-               if (nchars > -1)
-                       if (nchars < (int) size) {
-                               va_end (ap);
-                               str[nchars] = '\0';
-                               if (ptr)
-                                       free (ptr);
-                               return str;
-                       }
-                       else {
-                               size = (size_t) (nchars + 1);
-                       }
-
-               else
-                       size *= 2;
-
-               str = realloc (str, size);
-
-               if (str == NULL)
-                       terminate (STATE_UNKNOWN, "realloc failed in ssprintf");
-       }
-
-}
-
-
-
-
-
 /******************************************************************************
  *
  * Like strscpy, except only the portion of the source string up to