-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathalloc.h
More file actions
25 lines (18 loc) · 883 Bytes
/
alloc.h
File metadata and controls
25 lines (18 loc) · 883 Bytes
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
#ifndef ALLOC_H
#define ALLOC_H
#include "stddef.h"
#include <stdint.h>
// Allocates a buffer of size `bytes_new` and copies `old_buf` into it.
// Returns NULL on malloc failure, or if `bytes_old` is larger than
// `bytes_new`.
void *ft_realloc(void *old_buf, uint64_t bytes_new, uint64_t bytes_old) __attribute__((warn_unused_result));
// Allocates a buffer of size `nmemb * size`, 0-initialized bytes.
// Returns NULL on malloc failure, or if `nmemb * size` would
// result in a `uint64_t` overflow.
void *ft_calloc(uint64_t nmemb, uint64_t size) __attribute__((warn_unused_result));
void *ft_calloc_aligned(uint64_t nmemb, uint64_t size, uint8_t alignment);
void ft_free_aligned(void *ptr);
// Returns a heap-allocated duplicate of `src`.
// Returns NULL on malloc failure.
void *ft_memdup(const void *src, const uint64_t bytes) __attribute__((warn_unused_result));
#endif