2 static const char rcsid[] =
7 * FreeBSD install - a package for the installation and maintainance
8 * of non-core utilities.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
22 * Miscellaneous string utilities.
29 strconcat(char *s1, char *s2)
31 static char tmp[FILENAME_MAX];
34 strncpy(tmp, s1 ? s1 : s2, FILENAME_MAX); /* XXX: what if both are NULL? */
36 strncat(tmp, s2, FILENAME_MAX - strlen(tmp));
40 /* Get a string parameter as a file spec or as a "contents follow -" spec */
42 get_dash_string(char **str)
47 *str = copy_string(s + 1);
49 *str = fileGetContents(s);
55 copy_string(char *str)
57 return (str ? strdup(str) : NULL);
60 /* Return TRUE if 'str' ends in suffix 'suff' */
62 suffix(char *str, char *suff)
67 idx = strrchr(str, '.');
68 if (idx && !strcmp(idx + 1, suff))
73 /* Assuming str has a suffix, brutally murder it! */
75 nuke_suffix(char *str)
79 idx = strrchr(str, '.');
81 *idx = '\0'; /* Yow! Don't try this on a const! */
84 /* Lowercase a whole string */
86 str_lowercase(char *str)
95 get_string(char *str, int max, FILE *fp)
102 while (fgets(str, max, fp)) {
104 while (len && isspace(str[len - 1]))