File: abspath.c

package info (click to toggle)
ndctl 81-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 3,436 kB
  • sloc: ansic: 41,432; sh: 3,931; makefile: 28
file content (26 lines) | stat: -rw-r--r-- 606 bytes parent folder | download | duplicates (4)
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
// SPDX-License-Identifier: GPL-2.0

/* originally copied from git/abspath.c */

#include <util/util.h>
#include <util/strbuf.h>

char *prefix_filename(const char *pfx, const char *arg)
{
	struct strbuf path = STRBUF_INIT;
	size_t pfx_len = pfx ? strlen(pfx) : 0;

	if (pfx_len && !is_absolute_path(arg))
		strbuf_add(&path, pfx, pfx_len);

	strbuf_addstr(&path, arg);
	return strbuf_detach(&path, NULL);
}

void fix_filename(const char *prefix, const char **file)
{
	if (!file || !*file || !prefix || is_absolute_path(*file)
			|| !strcmp("-", *file))
		return;
	*file = prefix_filename(prefix, *file);
}