/* * $Source$ * $Author$ * $Header$ * * Copyright (C) 1987 by the Massachusetts Institute of Technology * For copying and distribution information, please see the file * . * * Miscellaneous string functions. */ #ifndef lint static char *rcsid_strs_c = "$Header$"; #endif lint #include #include #include #include extern char *malloc(), *realloc(); /* * Random string functions which should be in the C library.. */ /* * Make a copy of a string. */ char * strsave(s) char *s; { register int len; register char *p; /* Kludge for sloppy string semantics */ if (!s) { printf("NULL != \"\" !!!!\r\n"); p = malloc(1); *p = '\0'; return p; } len = strlen(s) + 1; p = malloc((u_int)len); if (p) bcopy(s, p, len); return p; } /* * Trim whitespace off both ends of a string. */ char *strtrim(save) register char *save; { register char *t, *s; s = save; while (isspace(*s)) s++; /* skip to end of string */ if (*s == '\0') { *save = '\0'; return(save); } for (t = s; *t; t++) continue; while (t > s) { --t; if (!isspace(*t)) { t++; break; } } *t = '\0'; return s; }