-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmem.h
More file actions
43 lines (35 loc) · 1.22 KB
/
mem.h
File metadata and controls
43 lines (35 loc) · 1.22 KB
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
#ifndef MEM_H
#define MEM_H
#include <stddef.h>
#include <stdint.h>
#if __SIZEOF_POINTER__ == 8
// `uint<CPU-architecture>_t`
typedef uint64_t op_t;
#else
// `uint<CPU-architecture>_t`
typedef uint32_t op_t;
#endif
#define OPTSIZ sizeof(op_t)
// Returns a pointer to the first occurence of `needle` in the first `n_bytes` of `haystack`.
// If nothing is found, returns a NULL pointer.
void *ft_memsrch(const void *haystack, int needle, uint64_t n_bytes);
// Compares the first `n_bytes` bytes `a` to `b`. Returns `0` if they are equal,
// or a non-zero u8 if not.
//
// Safety:
// If `a` and `b` are equal and both point to allocated regions shorter than `n_bytes`,
// this function will access invalid memory.
short ft_memcmp(const void *a, const void *b, uint64_t n_bytes);
// Copies the first `n_bytes` of `src` into `dest`.
//
// Safety:
// If `n_bytes` is bigger than `src` or `dest`, this might result in invalid
// memory access.
void *ft_memcpy(void *dest, const void *src, uint64_t n_bytes);
// Sets the first `n_bytes` of `src` to `c`.
//
// Safety:
// If `n_bytes` is bigger than the allocated region `src` is pointing to, this will
// result in invalid memory access.
void *ft_memset(void *src, int c, uint64_t n_bytes);
#endif