aboutsummaryrefslogtreecommitdiff
path: root/lib/io/src/dir_entry.c
blob: 15f078f78847b7578f2eae6533a5717280dfa2d1 (plain)
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
/* SPDX-License-Identifier: GPL-3.0-or-later */
/*
 * dir_entry.c
 *
 * Copyright (C) 2023 David Oberhollenzer <goliath@infraroot.at>
 */
#include "io/dir_entry.h"
#include "compat.h"

#include <stdlib.h>
#include <string.h>

dir_entry_t *dir_entry_create(const char *name)
{
	size_t len, name_len;
	dir_entry_t *out;

	name_len = strlen(name);
	if (SZ_ADD_OV(name_len, 1, &name_len))
		return NULL;
	if (SZ_ADD_OV(sizeof(*out), name_len, &len))
		return NULL;

	out = calloc(1, len);
	if (out == NULL)
		return NULL;

	memcpy(out->name, name, name_len);
	return out;
}