]> andersk Git - moira.git/blame - lib/strs.c
Avoid buffer overruns and check return value of malloc()
[moira.git] / lib / strs.c
CommitLineData
fa59b86f 1/* $Id$
68687902 2 *
7ac48069 3 * Miscellaneous string functions.
68687902 4 *
7ac48069 5 * Copyright (C) 1987-1998 by the Massachusetts Institute of Technology
6 * For copying and distribution information, please see the file
7 * <mit-copyright.h>.
68687902 8 */
9
babbc197 10#include <mit-copyright.h>
7ac48069 11#include <moira.h>
0fed7e9b 12
7ac48069 13#include <ctype.h>
68687902 14
7ac48069 15RCSID("$Header$");
5eaef520 16
68687902 17/*
18 * Trim whitespace off both ends of a string.
19 */
44d12d58 20char *strtrim(char *save)
68687902 21{
44d12d58 22 char *t, *s;
5eaef520 23
24 s = save;
25 while (isspace(*s))
26 s++;
27 /* skip to end of string */
28 if (*s == '\0')
29 {
30 *save = '\0';
31 return save;
9ca8ff13 32 }
68687902 33
5eaef520 34 for (t = s; *t; t++)
35 continue;
36 while (t > s)
37 {
38 --t;
39 if (!isspace(*t))
40 {
41 t++;
42 break;
68687902 43 }
44 }
5eaef520 45 if (*t)
46 *t = '\0';
47 return s;
68687902 48}
77f073b6 49
50
51/* Modify a string for all of the letters to be uppercase. */
52
5eaef520 53char *uppercase(char *s)
77f073b6 54{
44d12d58 55 char *p;
77f073b6 56
5eaef520 57 for (p = s; *p; p++)
58 {
77f073b6 59 if (islower(*p))
60 *p = toupper(*p);
5eaef520 61 }
62 return s;
77f073b6 63}
bc5b5d78 64
65
5eaef520 66char *lowercase(char *s)
bc5b5d78 67{
44d12d58 68 char *p;
bc5b5d78 69
5eaef520 70 for (p = s; *p; p++)
71 {
bc5b5d78 72 if (isupper(*p))
73 *p = tolower(*p);
501a4b9d 74 }
5eaef520 75 return s;
501a4b9d 76}
This page took 0.092171 seconds and 5 git commands to generate.