2021-06-07 16:49:15 +00:00
|
|
|
/* 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)
|
|
|
|
{
|
2021-11-11 09:24:49 +00:00
|
|
|
size_t oldlen = pb->namelen, i = pb->namelen;
|
2021-06-07 16:49:15 +00:00
|
|
|
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;
|
2021-11-11 09:24:49 +00:00
|
|
|
return oldlen;
|
2021-06-07 16:49:15 +00:00
|
|
|
}
|
|
|
|
|
2021-11-09 19:28:55 +00:00
|
|
|
void apk_pathbuilder_pop(struct apk_pathbuilder *pb, int pos)
|
2021-06-07 16:49:15 +00:00
|
|
|
{
|
2021-11-09 19:28:55 +00:00
|
|
|
if (pos < 0) return;
|
|
|
|
pb->namelen = pos;
|
2021-06-07 16:49:15 +00:00
|
|
|
pb->name[pb->namelen] = 0;
|
|
|
|
}
|