Changeset 16895 for gsdl/trunk/common-src/src/lib/gsdltools.cpp
- Timestamp:
- 2008-08-19T14:13:44+12:00 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
gsdl/trunk/common-src/src/lib/gsdltools.cpp
r9593 r16895 25 25 26 26 #include "gsdltools.h" 27 #include "fileutil.h" 27 28 28 29 #if defined(__WIN32__) … … 30 31 #include <process.h> 31 32 #endif 33 34 #if !defined (__WIN32__) 35 #include <sys/utsname.h> 36 #include <unistd.h> 37 #endif 38 32 39 33 40 bool littleEndian() { … … 160 167 } 161 168 169 170 static bool gsdl_setenv_done = false; 171 172 bool set_gsdl_env_vars (const text_t& gsdlhome) 173 { 174 if (gsdl_setenv_done) { return true; } 175 176 // set up GSDLOS, GSDLHOME and PATH environment variables 177 178 text_t gsdlos, path; 179 unsigned int path_separator = ':'; 180 181 #if defined (__WIN32__) 182 gsdlos = "windows"; 183 path_separator = ';'; 184 185 path = filename_cat (gsdlhome, "bin", "windows", "perl", "bin;"); 186 187 #else 188 struct utsname *buf = new struct utsname(); 189 int i = uname (buf); 190 if (i == -1) gsdlos = "linux"; // uname failed, default to linux 191 else gsdlos.setcstr (buf->sysname); 192 delete buf; 193 lc (gsdlos); 194 #endif 195 196 // according to getenv documentation (after a bit of digging), *getenv* 197 // is responsible for the char* pointer returned, so no need for us 198 // to free it (in fact that would be a mistake!) 199 200 char* orig_pathc = getenv ("PATH"); 201 path += filename_cat (gsdlhome, "bin", gsdlos); 202 path.push_back (path_separator); 203 path += filename_cat (gsdlhome, "bin", "script"); 204 if (orig_pathc != NULL) { 205 path.push_back (path_separator); 206 path += orig_pathc; 207 } 208 209 // these will be cleaned up in the destructor 210 char* gsdlosc = gsdlos.getcstr(); 211 char* gsdlhomec = gsdlhome.getcstr(); 212 char* pathc = path.getcstr(); 213 214 if ((setenv("GSDLOS",gsdlosc,1)!=0) 215 || (setenv("GSDLHOME",gsdlhomec,1)!=0) 216 || (setenv("PATH",pathc,1)!=0)) 217 { 218 perror("Setting Greenstone environment variables"); 219 return false; 220 } 221 222 delete [] gsdlosc; 223 delete [] gsdlhomec; 224 delete [] pathc; 225 226 gsdl_setenv_done = true; 227 228 return true; 229 } 230 231 232 162 233 // attempts to work out if perl is functional 163 234 bool perl_ok (ostream &logout) {
Note:
See TracChangeset
for help on using the changeset viewer.