functional: add mntent test
[libc-test.git] / src / common / path.c
blob6ca99510b7caf2af1f51aa4917c7a6a69b1aa69a
1 #include <string.h>
2 #include <stdio.h>
3 #include "test.h"
5 /* relative path to p */
6 char *t_pathrel(char *buf, size_t n, char *argv0, char *p)
8 char *s = strrchr(argv0, '/');
9 int k;
11 if (s)
12 k = snprintf(buf, n, "%.*s/%s", (int)(s-argv0), argv0, p);
13 else
14 k = snprintf(buf, n, "./%s", p);
15 if ((size_t)k >= n)
16 return 0;
17 return buf;