forked from dresden-elektronik/deconz-lib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathu_memory.c
78 lines (63 loc) · 1.33 KB
/
u_memory.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*
* Copyright (c) 2024 dresden elektronik ingenieurtechnik gmbh.
* All rights reserved.
*
* The software in this package is published under the terms of the BSD
* style license a copy of which has been included with this distribution in
* the LICENSE.txt file.
*
*/
#include <stdint.h>
#include <string.h>
#include <stdlib.h>
#include "u_assert.h"
#include "u_memory.h"
void *U_memalign(void *p, unsigned align)
{
uintptr_t num;
uintptr_t algn;
void *p1;
U_ASSERT(align == 1 || align == 4 || align == 8 || align == 16 || align == 32 || align == 64);
num = (uintptr_t)p;
algn = align;
p1 = (void*)((num + (algn - 1)) & ~(algn - 1));
U_ASSERT(p <= p1);
U_ASSERT((((uintptr_t)p1) & (align - 1)) == 0);
return p1;
}
void *U_memset(void *p, int c, unsigned long n)
{
return memset(p, c, n);
}
int U_memcmp(const void *a, const void *b, unsigned long n)
{
return memcmp(a, b, n);
}
unsigned U_strlen(const char *str)
{
return strlen(str);
}
void *U_memcpy(void *dst, const void *src, unsigned long n)
{
return memcpy(dst, src, n);
}
void *U_Alloc(unsigned long size)
{
void *p;
p = malloc(size);
if (p)
{
U_memset(p, 0, size);
}
return p;
}
int U_Free(void *p)
{
U_ASSERT(p != 0);
if (p)
{
free(p);
return 1;
}
return 0;
}