1 #include <string.h> 2 #include <stdio.h> 3 #include "test.h" 4 5 /* relative path to p */ t_pathrel(char * buf,size_t n,char * argv0,char * p)6char *t_pathrel(char *buf, size_t n, char *argv0, char *p) 7 { 8 char *s = strrchr(argv0, '/'); 9 int k; 10 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; 18 } 19