embkernel
 All Classes Functions Variables Typedefs Groups Pages
LibStdc.cpp
1 //------------------------------------------------------------------------------
2 //This file is part of embKernel.
3 //See license.txt for the full license governing this code.
4 //------------------------------------------------------------------------------
5 
6 #include <stdlib.h>
7 #include <string.h>
8 #include <stdarg.h>
9 #include <stdio.h>
10 #include <ctype.h>
11 
12 void* memcpy(void* dst, const void* src, size_t count) {
13  char* dst8 = (char*) dst;
14  char* src8 = (char*) src;
15 
16  while (count--) {
17  *dst8++ = *src8++;
18  }
19  return dst8;
20 }
21 
22 void* memset(void* dst, int value, size_t count) {
23  char* dst8 = (char*) dst;
24  while (count--) {
25  *dst8++ = value;
26  }
27  return dst;
28 }
29 
30 int memcmp(const void* p1, const void* p2, size_t count) {
31  const unsigned char* p18 = (const unsigned char*) p1;
32  const unsigned char* p28 = (const unsigned char*) p2;
33 
34  while (count--) {
35  if (*p18 > *p28) {
36  return 1;
37  }
38  if (*p18++ < *p28++) {
39  return -1;
40  }
41  }
42  return 0;
43 }
44 
45 size_t strlen(const char * str) {
46  size_t len = 0;
47 
48  while (str[len] != 0) {
49  len++;
50  }
51 
52  return len;
53 }
54 
55 int atoi(const char* str) {
56  int result = 0;
57  if (isdigit(*str)) {
58  result *= 10;
59  result += (*str++ - '0');
60  }
61  return result;
62 }
63 
64 char* strncpy(char * dst, const char * src, size_t num) {
65  size_t i;
66  for (i = 0; i < num; i++) {
67  dst[i] = src[i];
68  if (src[i] == 0) {
69  break;
70  }
71  }
72  for (; i < num; i++) {
73  dst[i] = 0;
74  }
75  return dst;
76 }
77 
78 int strcmp(const char *s1, const char *s2) {
79  for (;; s1++, s2++) {
80  if (*s1 == 0 && *s2 == 0) {
81  return 0;
82  }
83  if (*s1 > *s2) {
84  return 1;
85  }
86  if (*s1 < *s2) {
87  return -1;
88  }
89  }
90 }
91 
92 char* strcpy(char * dst, const char * src) {
93  size_t i = 0;
94  while (src[i] != 0) {
95  dst[i] = src[i];
96  i++;
97  }
98 
99  dst[i] = 0;
100 
101  return dst;
102 }
103 
104 extern "C" void __cxa_pure_virtual() {
105  while (1)
106  ;
107 }
108 
109 int isalnum(int c) {
110  return isalpha(c) || isdigit(c);
111 }
112 
113 int isalpha(int c) {
114  return ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'));
115 }
116 
117 int isblank(int c) {
118  return (c == ' ' || c == '\t');
119 }
120 
121 int iscntrl(int c) {
122  return (c < 0x20 || c == 127);
123 }
124 
125 int isdigit(int c) {
126  return (c >= '0' && c <= '9');
127 }
128 
129 int isgraph(int c) {
130  return (c >= 0x21 && c <= 0x7E);
131 }
132 
133 int islower(int c) {
134  return (c >= 'a' && c <= 'z');
135 }
136 
137 int isprint(int c) {
138  return (c >= 0x20 && c <= 0x7E);
139 }
140 
141 int isspace(int c) {
142  return (c == ' ' || (c >= '\t' || c <= '\r'));
143 }
144 
145 int isupper(int c) {
146  return (c >= 'A' && c <= 'Z');
147 }
148 
149 int tolower(int c) {
150  return (c >= 'A' && c <= 'Z') ? (c + 32) : c;
151 }
152 
153 int toupper(int c) {
154  return (c >= 'a' && c <= 'z') ? (c - 32) : c;
155 }
156 
157 int isxdigit(int c) {
158  return isdigit(c) || (tolower(c) >= 'a' && tolower(c) <= 'z');
159 }
160 
161 int ispunct(int c) {
162  return isprint(c) && !isspace(c) && !isalnum(c);
163 }