mirror of
https://github.com/Zeal-Operating-System/ZealOS.git
synced 2024-12-25 15:10:28 +00:00
Add zealbooter library files for memset, memmove, memcmp.
This commit is contained in:
parent
cd849bbd1f
commit
b0626d623b
7 changed files with 100 additions and 0 deletions
|
@ -3,6 +3,9 @@
|
|||
|
||||
#include <stdint.h>
|
||||
#include <memcpy.h>
|
||||
#include <memset.h>
|
||||
#include <memmove.h>
|
||||
#include <memcmp.h>
|
||||
#include <print.h>
|
||||
|
||||
uint64_t div_roundup_u64(uint64_t a, uint64_t b);
|
||||
|
|
26
zealbooter/lib/memcmp.c
Normal file
26
zealbooter/lib/memcmp.c
Normal file
|
@ -0,0 +1,26 @@
|
|||
/* memcmp( const void *, const void *, size_t )
|
||||
This file is part of the Public Domain C Library (PDCLib).
|
||||
Permission is granted to use, modify, and / or redistribute at will.
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
int memcmp(const void *s1, const void *s2, size_t n)
|
||||
{
|
||||
const unsigned char *p1 = (const unsigned char *)s1;
|
||||
const unsigned char *p2 = (const unsigned char *)s2;
|
||||
|
||||
while (n--)
|
||||
{
|
||||
if (*p1 != *p2)
|
||||
{
|
||||
return *p1 - *p2;
|
||||
}
|
||||
|
||||
++p1;
|
||||
++p2;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
6
zealbooter/lib/memcmp.h
Normal file
6
zealbooter/lib/memcmp.h
Normal file
|
@ -0,0 +1,6 @@
|
|||
#ifndef __MEMCMP_H__
|
||||
#define __MEMCMP_H__
|
||||
|
||||
int memcmp(const void *s1, const void *s2, size_t n);
|
||||
|
||||
#endif // __MEMCMP_H__
|
33
zealbooter/lib/memmove.c
Normal file
33
zealbooter/lib/memmove.c
Normal file
|
@ -0,0 +1,33 @@
|
|||
/* memmove( void *, const void *, size_t )
|
||||
This file is part of the Public Domain C Library (PDCLib).
|
||||
Permission is granted to use, modify, and / or redistribute at will.
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
void *memmove(void *s1, const void *s2, size_t n)
|
||||
{
|
||||
char *dest = (char *)s1;
|
||||
const char *src = (const char *)s2;
|
||||
|
||||
if (dest <= src)
|
||||
{
|
||||
while (n--)
|
||||
{
|
||||
*dest++ = *src++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
src += n;
|
||||
dest += n;
|
||||
|
||||
while (n--)
|
||||
{
|
||||
*--dest = *--src;
|
||||
}
|
||||
}
|
||||
|
||||
return s1;
|
||||
}
|
||||
|
6
zealbooter/lib/memmove.h
Normal file
6
zealbooter/lib/memmove.h
Normal file
|
@ -0,0 +1,6 @@
|
|||
#ifndef __MEMMOVE_H__
|
||||
#define __MEMMOVE_H__
|
||||
|
||||
void *memmove(void *s1, const void *s2, size_t n);
|
||||
|
||||
#endif // __MEMMOVE_H__
|
20
zealbooter/lib/memset.c
Normal file
20
zealbooter/lib/memset.c
Normal file
|
@ -0,0 +1,20 @@
|
|||
/* memset( void *, int, size_t )
|
||||
This file is part of the Public Domain C Library (PDCLib).
|
||||
Permission is granted to use, modify, and / or redistribute at will.
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
void *memset(void *s, int c, size_t n)
|
||||
{
|
||||
unsigned char *p = (unsigned char *)s;
|
||||
|
||||
while (n--)
|
||||
{
|
||||
*p++ = (unsigned char)c;
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
|
6
zealbooter/lib/memset.h
Normal file
6
zealbooter/lib/memset.h
Normal file
|
@ -0,0 +1,6 @@
|
|||
#ifndef __MEMSET_H__
|
||||
#define __MEMSET_H__
|
||||
|
||||
void *memset(void *s, int c, size_t n);
|
||||
|
||||
#endif // __MEMSET_H__
|
Loading…
Reference in a new issue