mirror of
https://github.com/kenshineto/kern.git
synced 2025-04-21 20:57:25 +00:00
volatile string fns
This commit is contained in:
parent
af90a91457
commit
86d2e07768
4 changed files with 73 additions and 0 deletions
|
@ -51,6 +51,38 @@ extern void *memmove(void *restrict dest, const void *restrict src, size_t n);
|
|||
*/
|
||||
extern void *memset(void *restrict dest, int c, size_t n);
|
||||
|
||||
/**
|
||||
* Copy the first n bytes from memory area src to memory area dest. The memory
|
||||
* areas must not overlap.
|
||||
* @param dest - the destination
|
||||
* @param src - the source
|
||||
* @param n - the byte count
|
||||
* @returns a pointer to dest
|
||||
*/
|
||||
extern void *memcpyv(volatile void *restrict dest,
|
||||
const volatile void *restrict src, size_t n);
|
||||
|
||||
/**
|
||||
* Copy the first n bytes from memory area src to memory area dest. The memory
|
||||
* areas may overlap; memmove behaves as though the bytes are first copied to a
|
||||
* temporary array.
|
||||
* @param dest - the destination
|
||||
* @param src - the source
|
||||
* @param n - the byte count
|
||||
* @returns a pointer to dest
|
||||
*/
|
||||
extern void *memmovev(volatile void *restrict dest,
|
||||
const volatile void *restrict src, size_t n);
|
||||
|
||||
/**
|
||||
* Fill the first n bytes of the memory region dest with the constant byte c.
|
||||
* @param dest - the destination
|
||||
* @param c - the byte to write
|
||||
* @param n - the byte count
|
||||
* @returns a pointer to dest
|
||||
*/
|
||||
extern void *memsetv(volatile void *restrict dest, int c, size_t n);
|
||||
|
||||
/**
|
||||
* Calculates the length of the string pointed to by str, excluding
|
||||
* the terminating null byte
|
||||
|
|
11
lib/memcpyv.c
Normal file
11
lib/memcpyv.c
Normal file
|
@ -0,0 +1,11 @@
|
|||
#include <string.h>
|
||||
|
||||
void *memcpyv(volatile void *restrict dest, const volatile void *restrict src,
|
||||
size_t n)
|
||||
{
|
||||
char *d = dest;
|
||||
const char *s = src;
|
||||
for (; n; n--)
|
||||
*d++ = *s++;
|
||||
return dest;
|
||||
}
|
20
lib/memmovev.c
Normal file
20
lib/memmovev.c
Normal file
|
@ -0,0 +1,20 @@
|
|||
#include <string.h>
|
||||
|
||||
void *memmovev(volatile void *dest, const volatile void *src, size_t n)
|
||||
{
|
||||
char *d = dest;
|
||||
const char *s = src;
|
||||
|
||||
if (d == s)
|
||||
return d;
|
||||
|
||||
if (d < s) {
|
||||
for (; n; n--)
|
||||
*d++ = *s++;
|
||||
} else {
|
||||
while (n)
|
||||
n--, d[n] = s[n];
|
||||
}
|
||||
|
||||
return dest;
|
||||
}
|
10
lib/memsetv.c
Normal file
10
lib/memsetv.c
Normal file
|
@ -0,0 +1,10 @@
|
|||
#include <string.h>
|
||||
|
||||
void *memsetv(volatile void *dest, int c, size_t n)
|
||||
{
|
||||
unsigned char *d = dest;
|
||||
for (; n; n--) {
|
||||
*d++ = c;
|
||||
};
|
||||
return dest;
|
||||
}
|
Loading…
Add table
Reference in a new issue