Changeset 331 for EcnlProtoTool/trunk/ntshell/ntshell/core/ntlibc.c
- Timestamp:
- Jan 21, 2018, 12:10:09 AM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
EcnlProtoTool/trunk/ntshell/ntshell/core/ntlibc.c
r321 r331 57 57 } 58 58 59 int ntlibc_strlcpy(char *des, const char *src, int n) 60 { 61 char *d = des, *e = &des[n]; 62 const char *s = src; 63 while (*s && d < e) { 64 *d = *s; 65 d++; 66 s++; 67 } 68 *d++ = '\0'; 69 return (int)d - (int)des; 70 } 71 59 72 char *ntlibc_strcat(char *des, const char *src) 60 73 { … … 71 84 *d = '\0'; 72 85 return des; 86 } 87 88 int ntlibc_strlcat(char *des, const char *src, int n) 89 { 90 char *d = des, *e = &des[n]; 91 const char *s = src; 92 while (*d && d < e) { 93 d++; 94 } 95 while (*s && d < e) { 96 *d = *s; 97 d++; 98 s++; 99 } 100 *d++ = '\0'; 101 return (int)d - (int)des; 73 102 } 74 103 … … 223 252 } 224 253 254 unsigned long ntlibc_strtoul(const char *restrict nptr, char **restrict endptr, int base) 255 { 256 int cnt; 257 int num = 0; 258 int ofs = 0; 259 int sign = 0; 260 int scnt = 0; 261 char *p = (char *)nptr; 262 while (*p != '\0') { 263 if (!ntlibc_isdigit(*p)) { 264 if (*p == ' ') { 265 ofs++; 266 } 267 if (*p == '+') { 268 sign = 0; 269 ofs++; 270 if (scnt++ > 0) { 271 *endptr = p; 272 break; 273 } 274 } 275 if (*p == '-') { 276 sign = 1; 277 ofs++; 278 if (scnt++ > 0) { 279 *endptr = p; 280 break; 281 } 282 } 283 *endptr = p; 284 break; 285 } 286 p++; 287 } 288 for (cnt = ofs; (nptr[cnt] >= '0') && (nptr[cnt] <= '9'); cnt++) { 289 num = 10 * num + (nptr[cnt] - '0'); 290 } 291 if (sign) { 292 return -num; 293 } 294 else { 295 return num; 296 } 297 } 298 225 299 char *ntlibc_strchr(const char *s, int c) 226 300 {
Note:
See TracChangeset
for help on using the changeset viewer.