Rev 3425 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 3425 | Rev 4377 | ||
|---|---|---|---|
| Line 1... | Line 1... | ||
| 1 | /* |
1 | /* |
| 2 | * Copyright (c) 2001-2004 Jakub Jermar |
2 | * Copyright (c) 2001-2004 Jakub Jermar |
| - | 3 | * Copyright (c) 2008 Jiri Svoboda |
|
| 3 | * All rights reserved. |
4 | * All rights reserved. |
| 4 | * |
5 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
6 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions |
7 | * modification, are permitted provided that the following conditions |
| 7 | * are met: |
8 | * are met: |
| Line 74... | Line 75... | ||
| 74 | } |
75 | } |
| 75 | 76 | ||
| 76 | return (char *) dst; |
77 | return (char *) dst; |
| 77 | } |
78 | } |
| 78 | 79 | ||
| - | 80 | /** Move memory block with possible overlapping. |
|
| - | 81 | * |
|
| - | 82 | * Copy cnt bytes from src address to dst address. The source and destination |
|
| - | 83 | * memory areas may overlap. |
|
| - | 84 | * |
|
| - | 85 | * @param src Source address to copy from. |
|
| - | 86 | * @param dst Destination address to copy to. |
|
| - | 87 | * @param cnt Number of bytes to copy. |
|
| - | 88 | * |
|
| - | 89 | * @return Destination address. |
|
| - | 90 | */ |
|
| - | 91 | void *memmove(void *dst, const void *src, size_t n) |
|
| - | 92 | { |
|
| - | 93 | const uint8_t *sp; |
|
| - | 94 | uint8_t *dp; |
|
| - | 95 | ||
| - | 96 | /* Nothing to do? */ |
|
| - | 97 | if (src == dst) |
|
| - | 98 | return dst; |
|
| - | 99 | ||
| - | 100 | /* Non-overlapping? */ |
|
| - | 101 | if (dst >= src + n || src >= dst + n) { |
|
| - | 102 | return memcpy(dst, src, n); |
|
| - | 103 | } |
|
| - | 104 | ||
| - | 105 | /* Which direction? */ |
|
| - | 106 | if (src > dst) { |
|
| - | 107 | /* Forwards. */ |
|
| - | 108 | sp = src; |
|
| - | 109 | dp = dst; |
|
| - | 110 | ||
| - | 111 | while (n-- != 0) |
|
| - | 112 | *dp++ = *sp++; |
|
| - | 113 | } else { |
|
| - | 114 | /* Backwards. */ |
|
| - | 115 | sp = src + (n - 1); |
|
| - | 116 | dp = dst + (n - 1); |
|
| - | 117 | ||
| - | 118 | while (n-- != 0) |
|
| - | 119 | *dp-- = *sp--; |
|
| - | 120 | } |
|
| - | 121 | ||
| - | 122 | return dst; |
|
| - | 123 | } |
|
| - | 124 | ||
| 79 | /** Fill block of memory |
125 | /** Fill block of memory |
| 80 | * |
126 | * |
| 81 | * Fill cnt bytes at dst address with the value x. The filling is done |
127 | * Fill cnt bytes at dst address with the value x. The filling is done |
| 82 | * byte-by-byte. |
128 | * byte-by-byte. |
| 83 | * |
129 | * |
| Line 112... | Line 158... | ||
| 112 | 158 | ||
| 113 | for (i = 0; i < cnt; i++) |
159 | for (i = 0; i < cnt; i++) |
| 114 | p[i] = x; |
160 | p[i] = x; |
| 115 | } |
161 | } |
| 116 | 162 | ||
| 117 | /** Copy string. |
- | |
| 118 | * |
- | |
| 119 | * Copy string from src address to dst address. The copying is done |
- | |
| 120 | * char-by-char until the null character. The source and destination memory |
- | |
| 121 | * areas cannot overlap. |
- | |
| 122 | * |
- | |
| 123 | * @param src Source string to copy from. |
- | |
| 124 | * @param dst Destination string to copy to. |
- | |
| 125 | * |
- | |
| 126 | * @return Address of the destination string. |
- | |
| 127 | */ |
- | |
| 128 | char *strcpy(char *dest, const char *src) |
- | |
| 129 | { |
- | |
| 130 | char *orig = dest; |
- | |
| 131 | - | ||
| 132 | while ((*(dest++) = *(src++))) |
- | |
| 133 | ; |
- | |
| 134 | return orig; |
- | |
| 135 | } |
- | |
| 136 | - | ||
| 137 | /** @} |
163 | /** @} |
| 138 | */ |
164 | */ |