blob: 95a3f8bc0d046db5bda26992e7d57276ce1a613b (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
#ifdef CHAD_ROOT_H
#define CHAD_ROOT_H
#include <limits.h>
#include "macros.h"
/* check errno -- chdir */
always_inline void Root(char * filename) {
extern char * realpath(const char * restrict path, char * restrict resolved_path);
extern int chdir(const char * path);
attribute(noreturn) void abort(void);
char path[PATH_MAX], * terminator;
if (!realpath(filename, path)) { return; }
if ((terminator = strrchr(path, '/'))) {
*terminator = '\0';
chdir(path);
}
}
#endif /* CHAD_ROOT_H */
|