Clubcos  0.0.0
Clubcos - Clubc Operating System
 모두 데이타 구조 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 매크로 페이지들
string.h
이 파일의 문서화 페이지로 가기
1 // Copyright (c) 2014, 임경현 (dlarudgus20)
2 // All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are met:
6 //
7 // * Redistributions of source code must retain the above copyright notice, this
8 // list of conditions and the following disclaimer.
9 //
10 // * Redistributions in binary form must reproduce the above copyright notice,
11 // this list of conditions and the following disclaimer in the documentation
12 // and/or other materials provided with the distribution.
13 //
14 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17 // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
18 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
20 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
21 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
22 // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 
33 #ifndef STRING_H_
34 #define STRING_H_
35 
36 #include <stddef.h>
37 #include <stdint.h>
38 #include <stdarg.h>
39 
40 size_t strlen(const char* str);
41 size_t strnlen(const char *str, size_t size);
42 char *strcpy(char * restrict dest, const char * restrict src);
43 char *strncpy(char * restrict dest, const char * restrict src, size_t count);
44 char *strcat(char * restrict dest, const char * restrict src);
45 
46 int strcmp(const char *lhs, const char *rhs);
47 char *strchr(const char *str, int ch);
48 char *_strchr_not(const char *str, int ch);
49 
50 void *_memcpy_forward(void *dest, const void *src, size_t count); /* asmfunc */
51 void *_memcpy_reverse(void *dest, const void *src, size_t count); /* asmfunc */
52 static inline void *memcpy(void * restrict dest, const void * restrict src, size_t count)
53 {
54  return _memcpy_forward((void *)dest, (const void *)src, count);
55 }
56 static inline void *memmove(void *dest, const void *src, size_t count)
57 {
58  char *d = (char *)dest;
59  const char *s = (const char *)src;
60  if (s < d && d < s + count)
61  return _memcpy_reverse(dest, src, count);
62  else
63  return _memcpy_forward(dest, src, count);
64 }
65 
66 void *memset(void *dest, int ch, size_t count); /* asmfunc */
67 void *_memset_2(void *dest, int ch, size_t count); /* asmfunc */
68 void *memchr(const void *ptr, int ch, size_t count); /* asmfunc */
69 void *_memchr_4(const void *ptr, int ch, size_t count); /* asmfunc */
70 
71 int atoi(const char *str);
72 
73 int snprintf(char *buf, size_t size, const char *format, ...);
74 int vsnprintf(char *buf, size_t size, const char *format, va_list va);
75 
76 void srand(unsigned int seed);
77 int rand(void);
78 
79 static inline int isalpha(int c) { return (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z'); }
80 static inline int isdigit(int c) { return c >= '0' && c <= '9'; }
81 static inline int iscntrl(int c) { return (c <= 0x1f && c == 0x7f); }
82 static inline int isspace(int c) { return strchr(" \t\n\v\f\r", c) != NULL; }
83 
84 #define max(a, b) (((a) > (b)) ? (a) : (b))
85 #define min(a, b) (((a) < (b)) ? (a) : (b))
86 #define range(a, x, b) (((x) < (a)) ? (a) : (min(x, b)))
87 
88 #endif /* STRING_H_ */
void * _memcpy_forward(void *dest, const void *src, size_t count)
void * memset(void *dest, int ch, size_t count)
char * _strchr_not(const char *str, int ch)
Definition: string.c:106
void * memchr(const void *ptr, int ch, size_t count)
char * strncpy(char *restrict dest, const char *restrict src, size_t count)
Definition: string.c:57
void * _memcpy_reverse(void *dest, const void *src, size_t count)
void * _memset_2(void *dest, int ch, size_t count)
int snprintf(char *buf, size_t size, const char *format,...)
Definition: snprintf.c:455
size_t strlen(const char *str)
Definition: string.c:36
int atoi(const char *str)
Definition: string.c:117
int rand(void)
Definition: string.c:168
char * strcpy(char *restrict dest, const char *restrict src)
Definition: string.c:49
char * strchr(const char *str, int ch)
Definition: string.c:95
void * _memchr_4(const void *ptr, int ch, size_t count)
void srand(unsigned int seed)
Definition: string.c:164
int strcmp(const char *lhs, const char *rhs)
Definition: string.c:80
size_t strnlen(const char *str, size_t size)
Definition: string.c:42
int vsnprintf(char *buf, size_t size, const char *format, va_list va)
Definition: snprintf.c:67
char * strcat(char *restrict dest, const char *restrict src)
Definition: string.c:68