-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathextra.c
60 lines (51 loc) · 1.23 KB
/
extra.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <stdlib.h>
#include <string.h>
#ifndef _MAX_PATH
#ifdef _POSIX_PATH_MAX
#define MAX_PATH _POSIX_PATH_MAX
#else
#define _MAX_PATH 260
#endif
#endif
static char libdir[_MAX_PATH];
static char *fpath;
#ifdef _WIN32
#define DIRSEP "\\/:"
#define DIRSEPCH "\\"
#else
#define DIRSEP "/"
#define DIRSEPCH "/"
#endif
#define LIB80 "lib80" DIRSEPCH
static char *fname(char *s) { /* get to the file name */
char *t;
while ((t = strpbrk(s, DIRSEP)))
s = t + 1;
return s;
}
static void initLibdir() {
char *env = getenv("LIBDIR80");
char *s;
if (env) {
strcpy(libdir, env);
s = fname(libdir);
if (*s)
strcat(s, DIRSEPCH);
} else if ((env = getenv("CPMDIR80"))) {
strcpy(libdir, env);
s = fname(libdir);
if (*s)
strcat(s, DIRSEPCH);
strcat(s, LIB80);
} else
strcpy(libdir, "." DIRSEPCH);
fpath = strchr(libdir, '\0'); // append point for filenames
}
char const *mkLibPath(char const *s) {
if (strpbrk(s, DIRSEP)) // only apply lib to simple files
return s;
if (!fpath)
initLibdir();
strcpy(fpath, s);
return libdir;
}