• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * COPYRIGHT AND PERMISSION NOTICE
3  *
4  * Copyright (c) 2003 Embedded Unit Project
5  *
6  * All rights reserved.
7  *
8  * Permission is hereby granted, free of charge, to any person obtaining
9  * a copy of this software and associated documentation files (the
10  * "Software"), to deal in the Software without restriction, including
11  * without limitation the rights to use, copy, modify, merge, publish,
12  * distribute, and/or sell copies of the Software, and to permit persons
13  * to whom the Software is furnished to do so, provided that the above
14  * copyright notice(s) and this permission notice appear in all copies
15  * of the Software and that both the above copyright notice(s) and this
16  * permission notice appear in supporting documentation.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
21  * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
22  * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY
23  * SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER
24  * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
25  * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
26  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
27  *
28  * Except as contained in this notice, the name of a copyright holder
29  * shall not be used in advertising or otherwise to promote the sale,
30  * use or other dealings in this Software without prior written
31  * authorization of the copyright holder.
32  *
33  * $Id: stdImpl.c,v 1.3 2004/02/10 16:15:25 arms22 Exp $
34  */
35 #include "stdImpl.h"
36 
stdimpl_strcpy(char * dst,const char * src)37 char* stdimpl_strcpy(char *dst, const char *src)
38 {
39 	char *start = dst;
40 	char c;
41 	do {
42 		c = *src;
43 		*dst = c;
44 		src++;
45 		dst++;
46 	} while (c);
47 	return start;
48 }
49 
stdimpl_strcat(char * dst,const char * src)50 char* stdimpl_strcat(char *dst, const char *src)
51 {
52 	char *start = dst;
53 	char c;
54 	do {
55 		c = *dst;
56 		dst++;
57 	} while (c);
58 	dst--;
59 	do {
60 		c = *src;
61 		*dst = c;
62 		src++;
63 		dst++;
64 	} while (c);
65 	return start;
66 }
67 
stdimpl_strncat(char * dst,const char * src,unsigned int count)68 char* stdimpl_strncat(char *dst, const char *src,unsigned int count)
69 {
70 	char *start = dst;
71 	char c;
72 	do {
73 		c = *dst;
74 		dst++;
75 	} while (c);
76 	dst--;
77 	if (count) {
78 		do {
79 			c = *src;
80 			*dst = c;
81 			src++;
82 			dst++;
83 			count--;
84 		} while (c && count);
85 		*dst = '\0';
86 	}
87 	return start;
88 }
89 
stdimpl_strlen(const char * str)90 int stdimpl_strlen(const char *str)
91 {
92     const char *estr = str;
93 	char c;
94 	do {
95 		c = *estr;
96 		estr++;
97 	} while (c);
98     return ((int)(estr - str - 1));
99 }
100 
stdimpl_strcmp(const char * s1,const char * s2)101 int stdimpl_strcmp(const char *s1, const char *s2)
102 {
103 	char c1,c2;
104 	do {
105 		c1 = *s1++;
106 		c2 = *s2++;
107 	} while ((c1) && (c2) && (c1==c2));
108 	return c1 - c2;
109 }
110 
_xtoa(unsigned long v,char * string,int r,int is_neg)111 static char* _xtoa(unsigned long v,char *string, int r, int is_neg)
112 {
113 	char *start = string;
114 	char buf[33],*p;
115 
116 	p = buf;
117 
118 	do {
119 		*p++ = "0123456789abcdef"[(v % r) & 0xf];
120 	} while (v /= r);
121 
122 	if (is_neg) {
123 		*p++ = '-';
124 	}
125 
126 	do {
127 		*string++ = *--p;
128 	} while (buf != p);
129 
130 	*string = '\0';
131 
132 	return start;
133 }
134 
stdimpl_itoa(int v,char * string,int r)135 char* stdimpl_itoa(int v,char *string,int r)
136 {
137     if ((r == 10) && (v < 0)) {
138 		return _xtoa((unsigned long)(-v), string, r, 1);
139 	}
140 	return _xtoa((unsigned long)(v), string, r, 0);
141 }
142