]> andersk Git - moira.git/blame - lib/strs.c
Initial revision
[moira.git] / lib / strs.c
CommitLineData
68687902 1/*
2 * $Source$
3 * $Author$
4 * $Header$
5 *
6 * Copyright (C) 1987 by the Massachusetts Institute of Technology
7 *
8 * Miscellaneous string functions.
9 */
10
11#ifndef lint
12static char *rcsid_strs_c = "$Header$";
13#endif lint
14
15
16/*
17 * Random string functions which should be in the C library..
18 */
19
20/*
21 * Make a copy of a string.
22 */
23char *
24strsave(s)
25 char *s;
26{
27 register int len = strlen(s) + 1;
28 register char *p = malloc((u_int)len);
29 if (p) bcopy(s, p, len);
30 return p;
31}
32/*
33 * Trim whitespace off both ends of a string.
34 */
35char *strtrim(s)
36 register char *s;
37{
38 register char *t;
39
40 while (isspace(*s)) s++;
41 /* skip to end of string */
42
43 for (t = s; *t; t++) continue;
44 while (t > s) {
45 --t;
46 if (!isspace(*t)) {
47 t++;
48 break;
49 }
50 }
51 *t = '\0';
52 return s;
53}
54
55/*
56 * Case insensitive string compare.
57 */
58
59int cistrcmp(cp1, cp2)
60 char *cp1, *cp2;
61{
62 register int c1, c2;
63
64 do {
65 if (isupper(c1 = (*cp1++))) c1 = tolower(c1);
66 if (isupper(c2 = (*cp2++))) c2 = tolower(c2);
67 if (c1 != c2) return c1-c2;
68 } while (c1 && c2);
69 return 0;
70}
71
This page took 0.054735 seconds and 5 git commands to generate.