]> andersk Git - moira.git/blame - lib/strs.c
if you get a "not exported" error while manipulating a filesys, let
[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
0fed7e9b 15#include <sys/types.h>
16#include <strings.h>
17#include <ctype.h>
18
19extern char *malloc(), *realloc();
68687902 20
21/*
22 * Random string functions which should be in the C library..
23 */
24
25/*
26 * Make a copy of a string.
27 */
28char *
29strsave(s)
30 char *s;
31{
0fed7e9b 32 register int len;
33 register char *p;
34 /* Kludge for sloppy string semantics */
35 if (!s) {
36 printf("NULL != \"\" !!!!\r\n");
37 p = malloc(1);
070955b9 38 *p = '\0';
0fed7e9b 39 return p;
40 }
41 len = strlen(s) + 1;
42 p = malloc((u_int)len);
68687902 43 if (p) bcopy(s, p, len);
44 return p;
45}
46/*
47 * Trim whitespace off both ends of a string.
48 */
9ca8ff13 49char *strtrim(save)
50 register char *save;
68687902 51{
9ca8ff13 52 register char *t, *s;
53
54 s = save;
68687902 55 while (isspace(*s)) s++;
56 /* skip to end of string */
9ca8ff13 57 if (*s == '\0') {
58 *save = '\0';
59 return(save);
60 }
68687902 61
62 for (t = s; *t; t++) continue;
63 while (t > s) {
64 --t;
65 if (!isspace(*t)) {
66 t++;
67 break;
68 }
69 }
70 *t = '\0';
71 return s;
72}
73
74/*
75 * Case insensitive string compare.
76 */
77
78int cistrcmp(cp1, cp2)
79 char *cp1, *cp2;
80{
81 register int c1, c2;
82
83 do {
84 if (isupper(c1 = (*cp1++))) c1 = tolower(c1);
85 if (isupper(c2 = (*cp2++))) c2 = tolower(c2);
86 if (c1 != c2) return c1-c2;
87 } while (c1 && c2);
88 return 0;
89}
90
This page took 0.058706 seconds and 5 git commands to generate.