blob: 166aa225f025667309d5eab887acbec198ae3235 (
plain) (
blame)
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
|
/* apk_pathbuilder.h - Alpine Package Keeper (APK)
*
* Copyright (C) 2021 Timo Teräs <timo.teras@iki.fi>
* All rights reserved.
*
* SPDX-License-Identifier: GPL-2.0-only
*/
#include <errno.h>
#include "apk_pathbuilder.h"
int apk_pathbuilder_pushb(struct apk_pathbuilder *pb, apk_blob_t b)
{
size_t i = pb->namelen;
if (i + b.len + 2 >= ARRAY_SIZE(pb->name)) return -ENAMETOOLONG;
if (i) pb->name[i++] = '/';
memcpy(&pb->name[i], b.ptr, b.len);
pb->namelen = i + b.len;
pb->name[pb->namelen] = 0;
return 0;
}
void apk_pathbuilder_pop(struct apk_pathbuilder *pb)
{
char *slash = memrchr(pb->name, '/', pb->namelen);
if (slash) pb->namelen = slash - pb->name;
else pb->namelen = 0;
pb->name[pb->namelen] = 0;
}
|