+/*********************************************************************
+ *
+ * Function : chomp
+ *
+ * Description : In-situ-eliminate all leading and trailing whitespace
+ * from a string.
+ *
+ * Parameters :
+ * 1 : s : string to be chomped.
+ *
+ * Returns : chomped string
+ *
+ *********************************************************************/
+char *chomp(char *string)
+{
+ char *p, *q, *r;
+
+ /*
+ * strip trailing whitespace
+ */
+ p = string + strlen(string);
+ while (p > string && ijb_isspace(*(p-1)))
+ {
+ p--;
+ }
+ *p = '\0';
+
+ /*
+ * find end of leading whitespace
+ */
+ q = r = string;
+ while (*q && ijb_isspace(*q))
+ {
+ q++;
+ }
+
+ /*
+ * if there was any, move the rest forwards
+ */
+ if (q != string)
+ {
+ while (q <= p)
+ {
+ *r++ = *q++;
+ }
+ }
+
+ return(string);
+
+}
+
+/*********************************************************************
+ *
+ * Function : strsav
+ *
+ * Description : Reallocate "old" and append text to it. This makes
+ * it easier to append to malloc'd strings.
+ *
+ * Parameters :
+ * 1 : old = Old text that is to be extended. Will be
+ * free()d by this routine.
+ * 2 : text_to_append = Text to be appended to old.
+ *
+ * Returns : Pointer to newly malloc'ed appended string.
+ * If there is no text to append, return old. Caller
+ * must free().
+ *
+ *********************************************************************/
+char *strsav(char *old, const char *text_to_append)
+{
+ int old_len, new_len;
+ char *p;
+
+ if (( text_to_append == NULL) || (*text_to_append == '\0'))
+ {
+ return(old);
+ }
+
+ if (NULL != old)
+ {
+ old_len = strlen(old);
+ }
+ else
+ {
+ old_len = 0;
+ }
+
+ new_len = old_len + strlen(text_to_append) + 1;
+
+ if (old)
+ {
+ if ((p = realloc(old, new_len)) == NULL)
+ {
+ log_error(LOG_LEVEL_FATAL, "realloc(%d) bytes failed!", new_len);
+ /* Never get here - LOG_LEVEL_FATAL causes program exit */
+ }
+ }
+ else
+ {
+ if ((p = (char *)malloc(new_len)) == NULL)
+ {
+ log_error(LOG_LEVEL_FATAL, "malloc(%d) bytes failed!", new_len);
+ /* Never get here - LOG_LEVEL_FATAL causes program exit */
+ }
+ }
+
+ strcpy(p + old_len, text_to_append);
+ return(p);
+
+}
+