-
Notifications
You must be signed in to change notification settings - Fork 0
/
file.c
78 lines (60 loc) · 1.59 KB
/
file.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include "gltron.h"
char* getFullPath(char *filename) {
char *path;
FILE *fp = NULL;
char *base;
char *share1 = "/usr/share/games/gltron";
char *share2 = "/usr/local/share/games/gltron";
/* check a few directories for the files and */
/* return the full path. */
/* check: current directory, GLTRON_HOME, and, for UNIX only: */
/* /usr/share/games/gltron and /usr/local/share/games/gltron */
path = malloc(strlen(filename) + 1);
sprintf(path, "%s", filename);
printf("checking '%s'...", path);
fp = fopen(path, "r");
if(fp != 0) {
fclose(fp);
printf("ok\n");
return path;
}
free(path);
printf("unsuccessful\n");
base = getenv("GLTRON_HOME");
if(base != 0) {
path = malloc(strlen(base) + 1 + strlen(filename) + 1);
sprintf(path, "%s%c%s", base, SEPERATOR, filename);
printf("checking '%s'...", path);
fp = fopen(path, "r");
if(fp != 0) {
fclose(fp);
printf("ok\n");
return path;
}
free(path);
printf("unsuccessful\n");
}
path = malloc(strlen(share1) + 1 + strlen(filename) + 1);
sprintf(path, "%s%c%s", share1, SEPERATOR, filename);
printf("checking '%s'", path);
fp = fopen(path, "r");
if(fp != 0) {
printf("ok\n");
fclose(fp);
return path;
}
free(path);
printf("unsuccessful\n");
path = malloc(strlen(share2) + 1 + strlen(filename) + 1);
sprintf(path, "%s%c%s", share2, SEPERATOR, filename);
printf("checking '%s'", path);
fp = fopen(path, "r");
if(fp != 0) {
fclose(fp);
printf("ok\n");
return path;
}
free(path);
printf("unsuccessful\n");
return 0;
}