xref: /third_party/musl/libc-test/src/common/path.c
  • Home
  • History
  • Annotate Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
  • only in /third_party/musl/libc-test/src/common/
1570af302Sopenharmony_ci#include <string.h>
2570af302Sopenharmony_ci#include <stdio.h>
3570af302Sopenharmony_ci#include "test.h"
4570af302Sopenharmony_ci
5570af302Sopenharmony_ci/* relative path to p */
6570af302Sopenharmony_cichar *t_pathrel(char *buf, size_t n, char *argv0, char *p)
7570af302Sopenharmony_ci{
8570af302Sopenharmony_ci	char *s = strrchr(argv0, '/');
9570af302Sopenharmony_ci	int k;
10570af302Sopenharmony_ci
11570af302Sopenharmony_ci	if (s)
12570af302Sopenharmony_ci		k = snprintf(buf, n, "%.*s/%s", (int)(s-argv0), argv0, p);
13570af302Sopenharmony_ci	else
14570af302Sopenharmony_ci		k = snprintf(buf, n, "./%s", p);
15570af302Sopenharmony_ci	if ((size_t)k >= n)
16570af302Sopenharmony_ci		return 0;
17570af302Sopenharmony_ci	return buf;
18570af302Sopenharmony_ci}
19

Indexes created Thu Nov 07 10:32:03 CST 2024