~ubuntu-branches/ubuntu/lucid/silo/lucid

« back to all changes in this revision

Viewing changes to common/stringops2.c

  • Committer: Bazaar Package Importer
  • Author(s): Fabio M. Di Nitto
  • Date: 2007-10-25 09:28:08 UTC
  • mfrom: (15.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20071025092808-1yhj12t7s4zqsfu5
Tags: 1.4.13a+git20070930-1ubuntu1
* Merge from debian unstable, remaining changes:
  - Build with -fno-stack-protector.
  - Change silo.postinst to automatically update the boot block without
    invoking siloconfig and keep asking questions on upgrades.
  - Convert silo.conf to use /dev/disk/by-uuid.
  - Ubuntu maintainer foobar.
  - Fix debian/rules call to dh_installdocs.
  - Drop the requirement of gcc-4.1 and start using default gcc.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Slooow, but small string operations, so that we don't have
 
2
   to link libc5/glibc in.
 
3
   Originally from linux/lib/string.c, which is 
 
4
        Copyright (C) 1991, 1992  Linus Torvalds
 
5
 */
 
6
 
 
7
#include <stringops.h>
 
8
 
 
9
char * strncpy(char *dest, const char *src, size_t count)
 
10
{
 
11
        char *tmp = dest;
 
12
 
 
13
        while (count-- && (*dest++ = *src++) != '\0')
 
14
                /* nothing */;
 
15
 
 
16
        return tmp;
 
17
}
 
18
 
 
19
char *strcat(char *dest, const char *src)
 
20
{
 
21
        char *tmp = dest;
 
22
        while (*dest) dest++;
 
23
        while ((*dest++ = *src++) != '\0');
 
24
        return tmp;
 
25
}
 
26
 
 
27
char *strncat(char *dest, const char *src, size_t n)
 
28
{
 
29
        char *tmp = dest;
 
30
        while (*dest) dest++;
 
31
        while (n && (*dest++ = *src++) != '\0') n--;
 
32
        if (!n) *dest = 0;
 
33
        return tmp;
 
34
}
 
35
 
 
36
char * strrchr(const char * s, int c)
 
37
{
 
38
        const char *p = s + strlen(s);
 
39
        do {
 
40
                if (*p == (char)c)
 
41
                        return (char *)p;
 
42
        } while (--p >= s);
 
43
        return 0;
 
44
}
 
45
 
 
46
char *strdup(const char *str)
 
47
{
 
48
        extern void *malloc(int);
 
49
        char *ret;
 
50
        ret = malloc(strlen(str) + 1);
 
51
        strcpy(ret, str);
 
52
        return ret;
 
53
}
 
54
 
 
55
__inline__ int tolower(int c)
 
56
{
 
57
        if (c >= 'A' && c <= 'Z') return c - 'A' + 'a';
 
58
        return c;
 
59
}
 
60
 
 
61
int strcasecmp(const char *cs,const char *ct)
 
62
{
 
63
        register signed char __res;
 
64
        while (1)
 
65
                if ((__res = tolower(*cs) - tolower(*ct++)) != 0 || !*cs++)
 
66
                        break;
 
67
        return __res;
 
68
}
 
69
 
 
70
int strncasecmp(const char *cs,const char *ct,size_t n)
 
71
{
 
72
        register signed char __res = 0;
 
73
        while (n--)
 
74
                if ((__res = tolower(*cs) - tolower(*ct++)) != 0 || !*cs++)
 
75
                        break;
 
76
        return __res;
 
77
}
 
78
 
 
79
char * strstr(const char * s1,const char * s2)
 
80
{
 
81
        int l1, l2;
 
82
 
 
83
        l2 = strlen(s2);
 
84
        if (!l2)
 
85
                return (char *) s1;
 
86
        l1 = strlen(s1);
 
87
        while (l1 >= l2) {
 
88
                l1--;
 
89
                if (!memcmp(s1,s2,l2))
 
90
                        return (char *) s1;
 
91
                s1++;
 
92
        }
 
93
        return 0;
 
94
}