Subversion Repositories HelenOS

Rev

Rev 3409 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3409 Rev 4338
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
 *