]> andersk Git - moira.git/blob - lib/strs.c
88b0178687fbe314621e552480b63676fd0493a6
[moira.git] / lib / strs.c
1 /*
2  *      $Source$
3  *      $Author$
4  *      $Header$
5  *
6  *      Copyright (C) 1987 by the Massachusetts Institute of Technology
7  *      For copying and distribution information, please see the file
8  *      <mit-copyright.h>.
9  *
10  *      Miscellaneous string functions.
11  */
12
13 #ifndef lint
14 static char *rcsid_strs_c = "$Header$";
15 #endif lint
16
17 #include <mit-copyright.h>
18 #include <sys/types.h>
19 #include <strings.h>
20 #include <ctype.h>
21
22 extern char *malloc(), *realloc();
23
24 /*
25  * Random string functions which should be in the C library..
26  */
27
28 /*
29  * Make a copy of a string.
30  */
31 char *
32 strsave(s)
33     char *s;
34 {
35     register int len;
36     register char *p;
37     /* Kludge for sloppy string semantics */
38     if (!s) {
39             printf("NULL != \"\" !!!!\r\n");
40             p = malloc(1);
41             *p = '\0';
42             return p;
43     }
44     len = strlen(s) + 1;
45     p = malloc((u_int)len);
46     if (p) bcopy(s, p, len);
47     return p;
48 }
49 /*
50  * Trim whitespace off both ends of a string.
51  */
52 char *strtrim(save)
53     register char *save;
54 {
55     register char *t, *s;
56
57     s = save;
58     while (isspace(*s)) s++;
59     /* skip to end of string */
60     if (*s == '\0') {
61         *save = '\0';
62         return(save);
63     }
64
65     for (t = s; *t; t++) continue; 
66     while (t > s) {
67         --t;
68         if (!isspace(*t)) {
69             t++;
70             break;
71         }
72     }
73     *t = '\0';
74     return s;
75 }
This page took 0.028131 seconds and 3 git commands to generate.