summaryrefslogtreecommitdiffstats
path: root/isys/str.c
blob: 87f9d3c47c601062869c2fee687617b81218e182 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*
 * str.c - String helper functions that don't need string.h or ctype.h
 *
 * Copyright 2006 Red Hat, Inc.
 *
 * David Cantrell <dcantrell@redhat.com>
 *
 * This software may be freely redistributed under the terms of the GNU
 * general public license.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#include <stdio.h>
#include <stdlib.h>

#include "str.h"

/**
 * Convert given string to uppercase. Modifies the argument in the caller's
 * stack. If you must ask simply "why?" for this function, it's so we don't
 * need toupper() and the same for loop all over the place.
 *
 * LIMITATIONS: Only deals with ASCII character set.
 *
 * @param str String to convert to uppercase.
 * @return Pointer to str.
 */
char *str2upper(char *str) {
    char *tmp;

    if (str == NULL)
        return NULL;

    /* man ascii(7) */
    tmp = str;
    while (*tmp != '\0') {
        if (*tmp >= 'a' && *tmp <= 'z')
            *tmp -= 32;

        tmp++;
    }

    return str;
}

/* vim:set shiftwidth=4 softtabstop=4: */