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