]> git.saurik.com Git - apple/boot.git/blame - gen/libsa/string1.c
boot-80.1.tar.gz
[apple/boot.git] / gen / libsa / string1.c
CommitLineData
14c7c974
A
1/*
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7 * Reserved. This file contains Original Code and/or Modifications of
8 * Original Code as defined in and that are subject to the Apple Public
9 * Source License Version 1.1 (the "License"). You may not use this file
10 * except in compliance with the License. Please obtain a copy of the
11 * License at http://www.apple.com/publicsource and read it before using
12 * this file.
13 *
14 * The Original Code and all software distributed under the License are
15 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT. Please see the
19 * License for the specific language governing rights and limitations
20 * under the License.
21 *
22 * @APPLE_LICENSE_HEADER_END@
23 */
24/* string operations */
25#import "libsa.h"
26
27/*#if DONT_USE_GCC_BUILT_IN_STRLEN*/
28
29#define tolower(c) ((int)((c) & ~0x20))
30#define toupper(c) ((int)((c) | 0x20))
31
32int strlen(const char *s)
33{
34 int n;
35
36 n = 0;
37 while (*s++) n++;
38 return(n);
39}
40
41/*#endif*/
42
43int
44strcmp(const char *s1, const char *s2)
45{
46 while (*s1 && (*s1 == *s2)) {
47 s1++;
48 s2++;
49 }
50 return (*s1 - *s2);
51}
52
53int strncmp(const char *s1, const char *s2, size_t len)
54{
55 register int n = len;
56 while (--n >= 0 && *s1 == *s2++)
57 if (*s1++ == '\0')
58 return(0);
59 return(n<0 ? 0 : *s1 - *--s2);
60}
61
62char *
63strcpy(char *s1, const char *s2)
64{
65 register char *ret = s1;
66 while (*s1++ = *s2++)
67 continue;
68 return ret;
69}
70
71char *
72strncpy(char *s1, const char *s2, size_t n)
73{
74 register char *ret = s1;
75 while (n && (*s1++ = *s2++))
76 n--;
77 if (!n) *s1=0;
78 return ret;
79}
80
81int
82ptol(char *str)
83{
84 register int c = *str;
85
86 if (c <= '7' && c >= '0')
87 c -= '0';
88 else if (c <= 'h' && c >= 'a')
89 c -= 'a';
90 else c = 0;
91 return c;
92}
93
94int
95atoi(const char *str)
96{
97 register int sum = 0;
98 while (*str == ' ' || *str == '\t')
99 str++;
100 while (*str >= '0' && *str <= '9') {
101 sum *= 10;
102 sum += *str++ - '0';
103 }
104 return sum;
105}
106
107
108char *strncat(char *s1, const char *s2, size_t n)
109{
110 register char *ret = s1;
111 while (*s1)
112 s1++;
113 while (n-- && *s2)
114 *s1++ = *s2++;
115 *s1 = '\0';
116 return ret;
117}
118
119char *strcat(char *s1, const char *s2)
120{
121 return(strncat(s1, s2, strlen(s2)));
122}
123
124#if STRNCASECMP
125int strncasecmp(const char *s1, const char *s2, size_t len)
126{
127 register int n = len;
128 while (--n >= 0 && tolower(*s1) == tolower(*s2++))
129 if (*s1++ == '\0')
130 return(0);
131 return(n<0 ? 0 : tolower(*s1) - tolower(*--s2));
132}
133#endif
134