6 char *path_dir(const char *path, char *buf)
10 if(!buf) buf = (char*)path;
15 if((sep = strrchr(buf, '/')) && sep > buf) {
21 char *path_file(const char *path, char *buf)
26 if(!buf) buf = (char*)path;
31 if((sep = strrchr(buf, '/'))) {
32 len = strlen(sep + 1);
33 memmove(buf, sep + 1, len + 1);
38 char *combine_path(const char *dirname, const char *fname, char *buf)
44 if(!dirname || !*dirname) {
50 while(*dirname) *dest++ = *dirname++;
52 if(dest[-1] != '/') *dest++ = '/';
58 FILE *fopenat(const char *dirname, const char *fname, const char *attr)
62 if(!dirname || !*dirname) {
63 return fopen(fname, attr);
66 buf = alloca(strlen(dirname) + strlen(fname) + 2);
67 combine_path(dirname, fname, buf);
68 return fopen(buf, attr);