Mercurial > projects > ldc
comparison dmd2/inifile.c @ 1452:638d16625da2
LDC 2 compiles again.
author | Robert Clipsham <robert@octarineparrot.com> |
---|---|
date | Sat, 30 May 2009 17:23:32 +0100 |
parents | 2667e3a145be |
children | 54b3c1394d62 |
comparison
equal
deleted
inserted
replaced
1423:42bd767ec5a4 | 1452:638d16625da2 |
---|---|
1 | 1 /* |
2 // Copyright (c) 1999-2006 by Digital Mars | 2 * Some portions copyright (c) 1994-1995 by Symantec |
3 // All Rights Reserved | 3 * Copyright (c) 1999-2009 by Digital Mars |
4 // written by Walter Bright | 4 * All Rights Reserved |
5 // http://www.digitalmars.com | 5 * http://www.digitalmars.com |
6 | 6 * Written by Walter Bright |
7 * | |
8 * This source file is made available for personal use | |
9 * only. The license is in /dmd/src/dmd/backendlicense.txt | |
10 * For any other uses, please contact Digital Mars. | |
11 */ | |
7 | 12 |
8 #include <stdio.h> | 13 #include <stdio.h> |
9 #include <string.h> | 14 #include <string.h> |
10 #include <stdlib.h> | 15 #include <stdlib.h> |
11 #include <ctype.h> | 16 #include <ctype.h> |
12 | 17 |
18 #if __APPLE__ | |
19 #include <sys/syslimits.h> | |
20 #endif | |
21 #if __FreeBSD__ || __sun&&__SVR4 | |
22 // for PATH_MAX | |
23 #include <limits.h> | |
24 #endif | |
25 | |
26 #if __sun&&__SVR4 | |
27 #include <alloca.h> | |
28 #endif | |
29 | |
13 #include "root.h" | 30 #include "root.h" |
14 #include "mem.h" | 31 #include "rmem.h" |
15 | |
16 #ifdef __MINGW32__ | |
17 #include <malloc.h> | |
18 #endif | |
19 | 32 |
20 #define LOG 0 | 33 #define LOG 0 |
21 | 34 |
22 char *skipspace(const char *p); | 35 char *skipspace(const char *p); |
23 | 36 |
41 * Input: | 54 * Input: |
42 * argv0 program name (argv[0]) | 55 * argv0 program name (argv[0]) |
43 * inifile .ini file name | 56 * inifile .ini file name |
44 */ | 57 */ |
45 | 58 |
46 void inifile(char *argv0x, const char *inifilex) | 59 void inifile(const char *argv0x, const char *inifilex) |
47 { | 60 { |
48 char *argv0 = (char *)argv0x; | 61 char *argv0 = (char *)argv0x; |
49 char *inifile = (char *)inifilex; // do const-correct later | 62 char *inifile = (char *)inifilex; // do const-correct later |
50 char *path; // need path for @P macro | 63 char *path; // need path for @P macro |
51 char *filename; | 64 char *filename; |
76 else | 89 else |
77 { | 90 { |
78 filename = FileName::combine(getenv("HOME"), inifile); | 91 filename = FileName::combine(getenv("HOME"), inifile); |
79 if (!FileName::exists(filename)) | 92 if (!FileName::exists(filename)) |
80 { | 93 { |
81 filename = FileName::replaceName(argv0, inifile); | 94 filename = (char *)FileName::replaceName(argv0, inifile); |
82 if (!FileName::exists(filename)) | 95 if (!FileName::exists(filename)) |
83 { | 96 { |
84 #if POSIX | 97 #if linux || __APPLE__ || __FreeBSD__ || __sun&&__SVR4 |
85 | 98 #if __GLIBC__ || __APPLE__ || __FreeBSD__ || __sun&&__SVR4 // This fix by Thomas Kuehne |
86 #if 0 | |
87 #if __GLIBC__ // This fix by Thomas Kuehne | |
88 /* argv0 might be a symbolic link, | 99 /* argv0 might be a symbolic link, |
89 * so try again looking past it to the real path | 100 * so try again looking past it to the real path |
90 */ | 101 */ |
102 #if __APPLE__ || __FreeBSD__ || __sun&&__SVR4 | |
103 char resolved_name[PATH_MAX + 1]; | |
104 char* real_argv0 = realpath(argv0, resolved_name); | |
105 #else | |
91 char* real_argv0 = realpath(argv0, NULL); | 106 char* real_argv0 = realpath(argv0, NULL); |
107 #endif | |
108 //printf("argv0 = %s, real_argv0 = %p\n", argv0, real_argv0); | |
92 if (real_argv0) | 109 if (real_argv0) |
93 { | 110 { |
94 filename = FileName::replaceName(real_argv0, inifile); | 111 filename = (char *)FileName::replaceName(real_argv0, inifile); |
112 #if !(__APPLE__ || __FreeBSD__ || __sun&&__SVR4) | |
95 free(real_argv0); | 113 free(real_argv0); |
114 #endif | |
96 if (FileName::exists(filename)) | 115 if (FileName::exists(filename)) |
97 goto Ldone; | 116 goto Ldone; |
98 } | 117 } |
99 #else | 118 #else |
100 #error use of glibc non-standard extension realpath(char*, NULL) | 119 #error use of glibc non-standard extension realpath(char*, NULL) |
101 #endif | 120 #endif |
102 #endif | 121 if (1){ |
103 | |
104 // old way; problem is that argv0 might not be on the PATH at all | |
105 // and some other instance might be found | |
106 | |
107 // Search PATH for argv0 | 122 // Search PATH for argv0 |
108 const char *p = getenv("PATH"); | 123 const char *p = getenv("PATH"); |
109 Array *paths = FileName::splitPath(p); | 124 Array *paths = FileName::splitPath(p); |
110 filename = FileName::searchPath(paths, argv0, 0); | 125 filename = FileName::searchPath(paths, argv0, 0); |
111 if (!filename) | 126 if (!filename) |
112 goto Letc; // argv0 not found on path | 127 goto Letc; // argv0 not found on path |
113 filename = FileName::replaceName(filename, inifile); | 128 filename = (char *)FileName::replaceName(filename, inifile); |
114 if (FileName::exists(filename)) | 129 if (FileName::exists(filename)) |
115 goto Ldone; | 130 goto Ldone; |
131 } | |
116 #endif | 132 #endif |
117 | 133 |
118 // Search /etc/ for inifile | 134 // Search /etc/ for inifile |
119 Letc: | 135 Letc: |
120 filename = FileName::combine((char *)"/etc/", inifile); | 136 filename = FileName::combine((char *)"/etc/", inifile); |