Changeset ac02aaa in mainline


Ignore:
Timestamp:
2008-09-14T11:00:31Z (16 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
693f614
Parents:
9f3363e
Message:

Implement memmove() for the use in the boot component.

Location:
boot/generic
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • boot/generic/string.c

    r9f3363e rac02aaa  
    4040/** Return number of characters in a string.
    4141 *
    42  * @param str NULL terminated string.
    43  *
    44  * @return Number of characters in str.
     42 * @param str           NULL terminated string.
     43 *
     44 * @return              Number of characters in str.
    4545 */
    4646size_t strlen(const char *str)
     
    5454}
    5555
    56 /** Compare two NULL terminated strings
     56/** Compare two NULL terminated strings.
    5757 *
    5858 * Do a char-by-char comparison of two NULL terminated strings.
     
    6060 * characters on the minimum of their lengths.
    6161 *
    62  * @param src First string to compare.
    63  * @param dst Second string to compare.
    64  *
    65  * @return 0 if the strings are equal, -1 if first is smaller, 1 if second smaller.
     62 * @param src           First string to compare.
     63 * @param dst           Second string to compare.
     64 *
     65 * @return              0 if the strings are equal, -1 if first is smaller,
     66 *                      1 if second smaller.
    6667 *
    6768 */
     
    8283
    8384
    84 /** Compare two NULL terminated strings
     85/** Compare two NULL terminated strings.
    8586 *
    8687 * Do a char-by-char comparison of two NULL terminated strings.
     
    8990 * length.
    9091 *
    91  * @param src First string to compare.
    92  * @param dst Second string to compare.
    93  * @param len Maximal length for comparison.
    94  *
    95  * @return 0 if the strings are equal, -1 if first is smaller, 1 if second smaller.
     92 * @param src           First string to compare.
     93 * @param dst           Second string to compare.
     94 * @param len           Maximal length for comparison.
     95 *
     96 * @return              0 if the strings are equal, -1 if first is smaller,
     97 *                      1 if second smaller.
    9698 *
    9799 */
     
    119121 * last copied character.
    120122 *
    121  * @param src Source string.
    122  * @param dest Destination buffer.
    123  * @param len Size of destination buffer.
     123 * @param src           Source string.
     124 * @param dest          Destination buffer.
     125 * @param len           Size of destination buffer.
    124126 */
    125127void strncpy(char *dest, const char *src, size_t len)
     
    133135}
    134136
    135 /** Convert ascii representation to unative_t
     137/** Convert ascii representation to unative_t.
    136138 *
    137139 * Supports 0x for hexa & 0 for octal notation.
    138140 * Does not check for overflows, does not support negative numbers
    139141 *
    140  * @param text Textual representation of number
    141  * @return Converted number or 0 if no valid number ofund
     142 * @param text          Textual representation of number.
     143 * @return              Converted number or 0 if no valid number found.
    142144 */
    143145unative_t atoi(const char *text)
     
    153155
    154156        while (*text) {
    155                 if (base != 16 && \
    156                     ((*text >= 'A' && *text <= 'F' )
    157                      || (*text >='a' && *text <='f')))
     157                if (base != 16 &&
     158                    ((*text >= 'A' && *text <= 'F') ||
     159                    (*text >='a' && *text <='f')))
    158160                        break;
    159161                if (base == 8 && *text >='8')
     
    177179}
    178180
     181/** Move piece of memory to another, possibly overlapping, location.
     182 *
     183 * @param dst           Destination address.
     184 * @param src           Source address.
     185 * @param len           Number of bytes to move.
     186 *
     187 * @return              Destination address.
     188 */
     189void *memmove(void *dst, const void *src, size_t len)
     190{
     191        char *d = dst;
     192        const char *s = src;
     193        if (s < d) {
     194                while (len--)
     195                        *(d + len) = *(s + len);
     196        } else {
     197                while (len--)
     198                        *d++ = *s++;
     199        }
     200       
     201        return dst;
     202}
     203
    179204/** @}
    180205 */
  • boot/generic/string.h

    r9f3363e rac02aaa  
    4343extern void strncpy(char *dest, const char *src, size_t len);
    4444extern unative_t atoi(const char *text);
     45extern void *memmove(void *dst, const void *src, size_t len);
    4546
    4647#endif
Note: See TracChangeset for help on using the changeset viewer.