3 * @author Shinichiro Nakamura
4 * @brief 小規模組み込みシステム向けのlibcライクライブラリの実装。
8 * ===============================================================
9 * Natural Tiny Shell (NT-Shell)
10 * ===============================================================
11 * Copyright (c) 2010-2012 Shinichiro Nakamura
13 * Permission is hereby granted, free of charge, to any person
14 * obtaining a copy of this software and associated documentation
15 * files (the "Software"), to deal in the Software without
16 * restriction, including without limitation the rights to use,
17 * copy, modify, merge, publish, distribute, sublicense, and/or
18 * sell copies of the Software, and to permit persons to whom the
19 * Software is furnished to do so, subject to the following
22 * The above copyright notice and this permission notice shall be
23 * included in all copies or substantial portions of the Software.
25 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
27 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
29 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
30 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
31 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
32 * OTHER DEALINGS IN THE SOFTWARE.
33 * ===============================================================
38 int ntlibc_strlen(const char *s)
49 char *ntlibc_strcpy(char *des, const char *src)
62 char *ntlibc_strcat(char *des, const char *src)
78 int ntlibc_strcmp(const char *s1, const char *s2)
80 char *p1 = (char *)s1;
81 char *p2 = (char *)s2;
84 return (*p1 < *p2) ? -1 : 1;
92 return (*p1 < *p2) ? -1 : 1;
96 int ntlibc_strncmp(const char *s1, const char *s2, int n)
98 char *p1 = (char *)s1;
99 char *p2 = (char *)s2;
106 return (*p1 < *p2) ? -1 : 1;
115 int ntlibc_isdigit(int c)
117 if (('0' <= c) && (c <= '9')) {
123 int ntlibc_isalpha(int c)
125 if (('A' <= c) && (c <= 'Z')) {
128 if (('a' <= c) && (c <= 'z')) {
134 int ntlibc_iscntrl(int c)
136 if (c == 0x07) { return 0; }
137 if (c == 0x08) { return 0; }
138 if (c == 0x09) { return 0; }
139 if (c == 0x0a) { return 0; }
140 if (c == 0x0b) { return 0; }
141 if (c == 0x0c) { return 0; }
142 if (c == 0x0d) { return 0; }
143 if ((0x00 <= c) && (c <= 0x1f)) {
149 int ntlibc_toupper(int c)
151 if (('a' <= c) && (c <= 'z')) {
152 int diff = 'a' - 'A';
158 int ntlibc_tolower(int c)
160 if (('A' <= c) && (c <= 'Z')) {
161 int diff = 'a' - 'A';
167 int ntlibc_atoi(const char *nptr)
174 char *p = (char *)nptr;
176 if (!ntlibc_isdigit(*p)) {
197 for (cnt = ofs; (nptr[cnt] >= '0') && (nptr[cnt] <= '9'); cnt++) {
198 num = 10 * num + (nptr[cnt] - '0');
207 char *ntlibc_strchr(const char *s, int c)
219 char *ntlibc_utoa(unsigned int value, char *s, int radix)
225 *s2++ = "0123456789abcdefghijklmnopqrstuvwxyz"[value % radix];