ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Urlader/urlader.c
(Generate patch)

Comparing Urlader/urlader.c (file contents):
Revision 1.3 by root, Thu Dec 29 10:39:34 2011 UTC vs.
Revision 1.7 by root, Fri Dec 30 14:51:45 2011 UTC

1#ifndef URLADER 1#ifndef URLADER
2# define URLADER "urlader" 2# define URLADER "urlader"
3#endif 3#endif
4#define URLADER_VERSION "1.0" 4#define URLADER_VERSION "1.0" // a decimal number, not a version string
5
6#define MAX_ARGC 32
7#define MAX_ARGS 256
5 8
6#include <stdio.h> 9#include <stdio.h>
7#include <stdlib.h> 10#include <stdlib.h>
8#include <unistd.h> 11#include <unistd.h>
9#include <errno.h> 12#include <errno.h>
15 18
16#define TAIL_MAGIC "SCHMORPPACK0" 19#define TAIL_MAGIC "SCHMORPPACK0"
17 20
18#ifdef _WIN32 21#ifdef _WIN32
19 22
20 #include <windows.h> 23 #include <windows.h>
21 //#include <winbase.h> 24 //#include <winbase.h>
22 #include <shlobj.h> 25 #include <shlobj.h>
23 #include <shlwapi.h> 26 #include <shlwapi.h>
24 #include <wininet.h> 27 #include <wininet.h>
25 28
26 static DWORD dword; 29 static DWORD dword;
27 30
28 #define u_handle HANDLE 31 #define u_handle HANDLE
32 #define u_invalid_handle 0
33 #define u_valid(handle) (!!handle)
34
29 #define u_setenv(name,value) SetEnvironmentVariable (name, value) 35 #define u_setenv(name,value) SetEnvironmentVariable (name, value)
30 #define u_mkdir(path) !CreateDirectory (path, NULL) 36 #define u_mkdir(path) !CreateDirectory (path, NULL)
31 #define u_chdir(path) !SetCurrentDirectory (path) 37 #define u_chdir(path) !SetCurrentDirectory (path)
32 #define u_rename(fr,to) !MoveFile (fr, to) 38 #define u_rename(fr,to) !MoveFile (fr, to)
33 #define u_open(path) CreateFile (path, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, NULL) 39 #define u_open(path) CreateFile (path, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, NULL)
34 #define u_creat(path,exec) CreateFile (path, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, NULL) 40 #define u_creat(path,exec) CreateFile (path, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, NULL)
41 #define u_creat(path,exec) CreateFile (path, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, NULL)
35 #define u_close(handle) CloseHandle (handle) 42 #define u_close(handle) CloseHandle (handle)
36 #define u_append(path,add) PathAppend (path, add) 43 #define u_append(path,add) PathAppend (path, add)
37 #define u_write(handle,data,len) (WriteFile (handle, data, len, &dword, 0) ? dword : -1) 44 #define u_write(handle,data,len) (WriteFile (handle, data, len, &dword, 0) ? dword : -1)
38 #define u_sync() // use transacted I/O?
39 45
40#else 46 #define u_fsync(handle) FlushFileBuffers (handle)
47 #define u_sync()
41 48
49 #define u_lockfile(path) CreateFile (path, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL)
50 #define u_cloexec(handle)
51
52#else
53
54 #define _GNU_SOURCE 1
55 #define _BSD_SOURCE 1
56 // the above increases our chances of getting MAP_ANONYMOUS
57
42 #include <sys/mman.h> 58 #include <sys/mman.h>
43 #include <sys/types.h> 59 #include <sys/types.h>
60 #include <sys/stat.h>
61 #include <unistd.h>
44 #include <pwd.h> 62 #include <pwd.h>
45 63
64 #if defined (MAP_ANON) && !defined (MAP_ANONYMOUS)
65 #define MAP_ANONYMOUS MAP_ANON
66 #endif
67
46 #ifdef PATH_MAX 68 #ifdef PATH_MAX
47 #define MAX_PATH (PATH_MAX < 4096 ? 4096 : PATH_MAX) 69 #define MAX_PATH (PATH_MAX < 4096 ? 4096 : PATH_MAX)
48 #else 70 #else
49 #define MAX_PATH 4096 71 #define MAX_PATH 4096
50 #endif 72 #endif
51 73
52 #define u_handle int 74 #define u_handle int
75 #define u_invalid_handle -1
76 #define u_valid(fd) ((fd) >= 0)
77
53 #define u_setenv(name,value) setenv (name, value, 1) 78 #define u_setenv(name,value) setenv (name, value, 1)
54 #define u_mkdir(path) mkdir (path, 0777) 79 #define u_mkdir(path) mkdir (path, 0777)
55 #define u_chdir(path) chdir (path) 80 #define u_chdir(path) chdir (path)
56 #define u_rename(fr,to) rename (fr, to) 81 #define u_rename(fr,to) rename (fr, to)
57 #define u_open(path) open (path, O_RDONLY) + 1 82 #define u_open(path) open (path, O_RDONLY)
58 #define u_creat(path,exec) open (path, O_WRONLY | O_CREAT | O_TRUNC, (exec) ? 0777 : 0666) + 1 83 #define u_creat(path,exec) open (path, O_WRONLY | O_CREAT | O_TRUNC, (exec) ? 0777 : 0666)
59 #define u_close(handle) close (handle - 1) 84 #define u_close(handle) close (handle)
60 #define u_append(path,add) strcat (strcat (path, "/"), add) 85 #define u_append(path,add) strcat (strcat (path, "/"), add)
61 #define u_write(handle,data,len) write ((handle) - 1, data, len) 86 #define u_write(handle,data,len) write (handle, data, len)
87
88 // on a mostly idle system, a sync at the end is certainly faster, hope for the best
89 #define u_fsync(handle)
62 #define u_sync() sync () 90 #define u_sync() sync ()
91
92 #define u_lockfile(path) open (path, O_RDWR | O_CREAT, 0666)
93 #define u_cloexec(handle) fcntl (handle, F_SETFD, FD_CLOEXEC)
63 94
64#endif 95#endif
65 96
66#define u_16(ptr) (((ptr)[0] << 8) | (ptr)[1]) 97#define u_16(ptr) (((ptr)[0] << 8) | (ptr)[1])
67#define u_32(ptr) (((ptr)[0] << 24) | ((ptr)[1] << 16) | ((ptr)[2] << 8) | (ptr)[3]) 98#define u_32(ptr) (((ptr)[0] << 24) | ((ptr)[1] << 16) | ((ptr)[2] << 8) | (ptr)[3])
68 99
100/* some simple? dynamic memory management for paths might save ltos of ram */
69static u_handle pack_handle; 101static u_handle pack_handle;
102static u_handle lock_handle;
70static char tmppath[MAX_PATH]; 103static char tmppath[MAX_PATH];
71static char currdir[MAX_PATH]; 104static char currdir[MAX_PATH];
72static char datadir[MAX_PATH]; // %AppData%/urlader 105static char datadir[MAX_PATH]; // %AppData%/urlader
73static char exe_dir[MAX_PATH]; // %AppData%/urlader/EXE_ID 106static char exe_dir[MAX_PATH]; // %AppData%/urlader/EXE_ID
74static char execdir[MAX_PATH]; // %AppData%/urlader/EXE_ID/EXE_VER 107static char execdir[MAX_PATH]; // %AppData%/urlader/EXE_ID/EXE_VER
75static char exe_id[MAX_PATH]; 108static char exe_id[MAX_PATH];
76static char exe_ver[MAX_PATH]; 109static char exe_ver[MAX_PATH];
77 110
78static int exe_argc; 111static int exe_argc;
79static const char *exe_argv[32]; 112static const char *exe_argv[MAX_ARGC];
113static char exe_args[MAX_ARGS]; /* actual arguments strings copied here */
114static unsigned int exe_argo;
80 115
81static void 116static void
82fatal (const char *msg) 117fatal (const char *msg)
83{ 118{
84#ifdef _WIN32 119#ifdef _WIN32
85 MessageBox (0, msg, URLADER, 0); 120 MessageBox (0, msg, URLADER, 0);
86#else 121#else
87 fprintf (stderr, "%s: %s\n", URLADER, msg); 122 write (2, URLADER ": ", sizeof (URLADER ": ") - 1);
123 write (2, msg, strlen (msg));
124 write (2, "\n", 1);
88#endif 125#endif
89 126
90 _exit (1); 127 _exit (1);
128}
129
130static void *
131u_malloc (unsigned int size)
132{
133 void *addr;
134
135#ifdef _WIN32
136 HANDLE handle = CreateFileMapping (0, 0, PAGE_READWRITE, 0, size, NULL);
137
138 if (!handle)
139 return 0;
140
141 addr = MapViewOfFile (handle, FILE_MAP_WRITE, 0, 0, size);
142
143 CloseHandle (handle);
144#elif defined (MAP_ANONYMOUS)
145 addr = mmap (0, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0);
146
147 if (addr == (void *)-1)
148 addr = 0;
149#else
150 addr = malloc (size);
151#endif
152
153 return addr;
154}
155
156static void
157u_free (void *addr, unsigned int size)
158{
159#ifdef _WIN32
160 UnmapViewOfFile (addr);
161#elif defined (MAP_ANONYMOUS)
162 munmap (addr, size);
163#else
164 free (addr);
165#endif
166}
167
168static void *
169u_mmap (u_handle h, unsigned int size)
170{
171 void *addr;
172
173#ifdef _WIN32
174 HANDLE handle = CreateFileMapping (h, 0, PAGE_READONLY, 0, size, NULL);
175
176 if (!handle)
177 return 0;
178
179 addr = MapViewOfFile (handle, FILE_MAP_READ, 0, 0, size);
180
181 CloseHandle (handle);
182#else
183 addr = mmap (0, size, PROT_READ, MAP_SHARED, h, 0);
184
185 if (addr == (void *)-1)
186 addr = 0;
187#endif
188
189 return addr;
190}
191
192static void
193u_munmap (void *addr, unsigned int len)
194{
195#ifdef _WIN32
196 UnmapViewOfFile (addr);
197#else
198 munmap (addr, len);
199#endif
91} 200}
92 201
93static void 202static void
94tmpdir (const char *dir) 203tmpdir (const char *dir)
95{ 204{
106 if (!u_mkdir (tmppath)) 215 if (!u_mkdir (tmppath))
107 return; 216 return;
108 } 217 }
109} 218}
110 219
220static u_handle
221u_lock (const char *path, int excl, int dowait)
222{
223 u_handle h;
224
225 h = u_lockfile (path);
226 if (!u_valid (h))
227 return h;
228
229 u_cloexec (h);
230
231 for (;;)
232 {
233 int success;
234
235 // acquire the lock
236#ifdef _WIN32
237 OVERLAPPED ov = { 0 };
238
239 success = LockFileEx (h,
240 (excl ? LOCKFILE_EXCLUSIVE_LOCK : 0)
241 | (dowait ? 0 : LOCKFILE_FAIL_IMMEDIATELY),
242 0,
243 1, 0,
244 &ov);
245#else
246 struct flock lck = { 0 };
247
248 lck.l_type = excl ? F_WRLCK : F_RDLCK;
249 lck.l_whence = SEEK_SET;
250 lck.l_len = 1;
251
252 success = !fcntl (h, dowait ? F_SETLKW : F_SETLK, &lck);
253#endif
254
255 if (!success)
256 break;
257
258 // we have the lock, now verify that the lockfile still exists
259
260#ifdef _WIN32
261 // apparently, we have to open the file to get its info :(
262 BY_HANDLE_FILE_INFORMATION s1, s2;
263 u_handle h2 = u_lockfile (path);
264 if (!u_valid (h))
265 break;
266
267 success = GetFileInformationByHandle (h, &s1)
268 && GetFileInformationByHandle (h2, &s2);
269
270 u_close (h2);
271
272 if (!success)
273 break;
274
275 success = s1.dwVolumeSerialNumber == s2.dwVolumeSerialNumber
276 && s1.nFileIndexHigh == s2.nFileIndexHigh
277 && s1.nFileIndexLow == s2.nFileIndexLow;
278#else
279 struct stat s1, s2;
280
281 if (fstat (h, &s1) || stat (path, &s2))
282 break;
283
284 success = s1.st_dev == s2.st_dev
285 && s1.st_ino == s2.st_ino;
286#endif
287
288 if (success)
289 return h; // lock successfully acquired
290
291 // files differ, close and retry - should be very rare
292 u_close (h);
293 }
294
295 // failure
296 u_close (h);
297 return u_invalid_handle;
298}
299
111static void 300static void
112systemv (const char *const argv[], int dowait) 301systemv (const char *const argv[])
113{ 302{
114#ifdef _WIN32 303#ifdef _WIN32
115 _spawnv (P_WAIT, argv [0], argv); 304 _spawnv (P_WAIT, argv [0], argv);
116#else 305#else
117 pid_t pid = dowait ? fork () : 0; 306 pid_t pid = fork ();
118 307
119 if (pid < 0) 308 if (pid < 0)
120 fatal ("fork failure"); 309 fatal ("fork failure");
121 310
122 if (!pid) 311 if (!pid)
138 const char *argv[] = { getenv ("COMSPEC"), "/c", "rd", "/s", "/q", buf, 0 }; 327 const char *argv[] = { getenv ("COMSPEC"), "/c", "rd", "/s", "/q", buf, 0 };
139 sprintf (buf, "\"%s\"", path); 328 sprintf (buf, "\"%s\"", path);
140 #else 329 #else
141 const char *argv[] = { "/bin/rm", "-rf", path, 0 }; 330 const char *argv[] = { "/bin/rm", "-rf", path, 0 };
142 #endif 331 #endif
143 systemv (argv, 1); 332 systemv (argv);
144} 333}
145 334
146enum 335enum
147{ 336{
148 T_NULL, // 5 337 T_NULL, // 5
149 T_META, // 1 : exe_id, exe_ver 338 T_META, // 1 : exe_id, exe_ver
150 T_ARG, // 2 : arg
151 T_ENV, // 3 : name, value 339 T_ENV, // 2 : name, value
340 T_ARG, // 3 : arg
152 T_DIR, // 4+: path 341 T_DIR, // 4+: path
153 T_FILE, // 4+: path, data 342 T_FILE, // 4+: path, data
154 T_NUM 343 T_NUM
155}; 344};
156 345
176}; 365};
177 366
178static char *pack_base, *pack_end; 367static char *pack_base, *pack_end;
179static struct hdr *pack_cur; 368static struct hdr *pack_cur;
180static char *scratch; 369static char *scratch;
181static unsigned int scratch_len; 370static unsigned int scratch_size;
182 371
183#define PACK_NAME ((char *)(pack_cur + 1)) 372#define PACK_NAME ((char *)(pack_cur + 1))
184#define PACK_DATA (PACK_NAME + u_16 (pack_cur->namelen) + 1) 373#define PACK_DATA (PACK_NAME + u_16 (pack_cur->namelen) + 1)
185#define PACK_VALID pack_cur->type 374#define PACK_VALID pack_cur->type
186 375
193} 382}
194 383
195static void 384static void
196pack_unmap (void) 385pack_unmap (void)
197{ 386{
198 if (!pack_base) 387 if (pack_base)
199 return; 388 {
200
201 free (scratch);
202
203#ifdef _WIN32
204 UnmapViewOfFile (pack_base);
205#else
206 munmap (pack_base, pack_end - pack_base); 389 u_munmap (pack_base, pack_end - pack_base);
207#endif 390 pack_base = 0;
391 }
392
393 if (scratch)
394 {
395 u_free (scratch, scratch_size);
396 scratch = 0;
397 }
208} 398}
209 399
210static int 400static int
211pack_map (void) 401pack_map (void)
212{ 402{
403 char *addr;
404 unsigned int size;
405
213#ifdef _WIN32 406#ifdef _WIN32
214 BY_HANDLE_FILE_INFORMATION fi; 407 BY_HANDLE_FILE_INFORMATION fi;
215 408
216 if (!GetFileInformationByHandle (pack_handle, &fi)) 409 if (!GetFileInformationByHandle (pack_handle, &fi))
217 return 0; 410 return 0;
218 411
219 if (fi.nFileSizeHigh) // too big 412 size = fi.nFileSizeLow;
413#else
414 size = lseek (pack_handle, 0, SEEK_END);
415#endif
416
417 addr = u_mmap (pack_handle, size);
418 if (!addr)
220 return 0; 419 return 0;
221 420
222 HANDLE handle = CreateFileMapping (pack_handle, 0, PAGE_READONLY, 0, fi.nFileSizeLow, NULL);
223
224 if (!handle)
225 return 0;
226
227 pack_unmap (); 421 pack_unmap ();
228 422
229 pack_base = MapViewOfFile (handle, FILE_MAP_READ, 0, 0, fi.nFileSizeLow);
230
231 CloseHandle (handle);
232
233 pack_end = pack_base + fi.nFileSizeLow;
234#else
235 off_t len = lseek (pack_handle - 1, 0, SEEK_END);
236
237 pack_unmap ();
238
239 pack_base = mmap (0, len, PROT_READ, MAP_SHARED, pack_handle - 1, 0);
240 if (pack_base == (void *)-1)
241 pack_base = 0; 423 pack_base = addr;
242
243 pack_end = pack_base + len; 424 pack_end = pack_base + size;
244#endif
245
246 if (!pack_base)
247 return 0;
248 425
249 struct tail *tail; 426 struct tail *tail;
250 427
251 tail = (void *)(pack_end - sizeof (*tail)); 428 tail = (void *)(pack_end - sizeof (*tail));
252 429
253 if (memcmp (tail->magic, TAIL_MAGIC, sizeof (TAIL_MAGIC) - 1)) 430 if (memcmp (tail->magic, TAIL_MAGIC, sizeof (TAIL_MAGIC) - 1))
254 return 0; 431 return 0;
255 432
256 pack_cur = (struct hdr *)(pack_end - u_32 (tail->size)); 433 pack_cur = (struct hdr *)(pack_end - u_32 (tail->size));
257 434
258 free (scratch);
259 scratch = malloc (scratch_len = u_32 (tail->max_filesize)); 435 scratch = u_malloc (scratch_size = u_32 (tail->max_filesize));
436 if (!scratch)
437 return 0;
260 438
261 return 1; 439 return 1;
262} 440}
263 441
264static void 442static void
284 462
285 if (u_chdir (exe_dir)) 463 if (u_chdir (exe_dir))
286 fatal ("unable to change to application data directory"); 464 fatal ("unable to change to application data directory");
287 465
288 u_handle h = u_open ("override"); 466 u_handle h = u_open ("override");
289 if (h) 467 if (u_valid (h))
290 { 468 {
291 u_handle oh = pack_handle; 469 u_handle oh = pack_handle;
292 470
293 pack_handle = h; 471 pack_handle = h;
294 if (!pack_map ()) 472 if (!pack_map ())
304 fatal ("unable to locate override metadata"); 482 fatal ("unable to locate override metadata");
305 483
306 strcpy (exe_ver, PACK_DATA); 484 strcpy (exe_ver, PACK_DATA);
307 pack_next (); 485 pack_next ();
308 486
487 for (;;)
488 {
489 if (pack_cur->type == T_ENV)
490 u_setenv (PACK_NAME, PACK_DATA);
309 while (pack_cur->type == T_ARG) 491 else if (pack_cur->type == T_ARG)
310 { 492 {
311 exe_argv [exe_argc++] = strdup (PACK_NAME); 493 int len = u_16 (pack_cur->namelen) + 1;
494 exe_argv [exe_argc++] = exe_args + exe_argo;
495 memcpy (exe_args + exe_argo, PACK_NAME, len);
496 exe_argo += len;
497 }
498 else
499 break;
500
312 pack_next (); 501 pack_next ();
313 } 502 }
314 503
315 while (pack_cur->type == T_ENV) 504done_env_arg:
316 {
317 u_setenv (PACK_NAME, PACK_DATA);
318 pack_next ();
319 }
320
321 strcpy (execdir, exe_dir); 505 strcpy (execdir, exe_dir);
322 u_append (execdir, "i-"); 506 u_append (execdir, "i-");
323 strcat (execdir, exe_ver); 507 strcat (execdir, exe_ver);
508
509 strcat (strcpy (tmppath, execdir), ".lck");
510 lock_handle = u_lock (tmppath, 0, 1);
511 if (!lock_handle)
512 fatal ("unable to lock application instance");
324 513
325 if (access (execdir, F_OK)) 514 if (access (execdir, F_OK))
326 { 515 {
327 // does not exist yet, so unpack and move 516 // does not exist yet, so unpack and move
328 tmpdir (exe_dir); 517 tmpdir (exe_dir);
343 u_handle h = u_creat (PACK_NAME, pack_cur->flags & F_EXEC); 532 u_handle h = u_creat (PACK_NAME, pack_cur->flags & F_EXEC);
344 unsigned int dlen, len = u_32 (pack_cur->datalen); 533 unsigned int dlen, len = u_32 (pack_cur->datalen);
345 char *data = PACK_DATA; 534 char *data = PACK_DATA;
346 535
347 if (pack_cur->flags & F_LZF) 536 if (pack_cur->flags & F_LZF)
348 if (dlen = lzf_decompress (data, len, scratch, scratch_len)) 537 if (dlen = lzf_decompress (data, len, scratch, scratch_size))
349 { 538 {
350 data = scratch; 539 data = scratch;
351 len = dlen; 540 len = dlen;
352 } 541 }
353 else 542 else
354 fatal ("unable to uncompress file data - pack corrupted?"); 543 fatal ("unable to uncompress file data - pack corrupted?");
355 544
356 if (!h) 545 if (!u_valid (h))
357 fatal ("unable to unpack file from packfile - disk full?"); 546 fatal ("unable to unpack file from packfile - disk full?");
358 547
359 if (u_write (h, data, len) != len) 548 if (u_write (h, data, len) != len)
360 fatal ("unable to unpack file from packfile - disk full?"); 549 fatal ("unable to unpack file from packfile - disk full?");
361 550
551 u_fsync (h);
362 u_close (h); 552 u_close (h);
363 } 553 }
364 break; 554 break;
365 555
366 case T_NULL: 556 case T_NULL:
391 u_setenv ("URLADER_EXECDIR", execdir); 581 u_setenv ("URLADER_EXECDIR", execdir);
392 u_setenv ("URLADER_EXE_ID" , exe_id); 582 u_setenv ("URLADER_EXE_ID" , exe_id);
393 u_setenv ("URLADER_EXE_DIR", exe_dir); 583 u_setenv ("URLADER_EXE_DIR", exe_dir);
394 u_setenv ("URLADER_EXE_VER", exe_ver); 584 u_setenv ("URLADER_EXE_VER", exe_ver);
395 585
586#if 0
396 // yes, this is overkill 587 // yes, this is overkill
397 u_setenv ("SHLIB_PATH" , execdir); // hpux 588 u_setenv ("SHLIB_PATH" , execdir); // hpux
398 u_setenv ("LIBPATH" , execdir); // aix 589 u_setenv ("LIBPATH" , execdir); // aix
399 u_setenv ("LD_LIBRARY_PATH" , execdir); // most elf systems 590 u_setenv ("LD_LIBRARY_PATH" , execdir); // most elf systems
400 u_setenv ("LD_LIBRARY_PATH_32", execdir); // solaris 591 u_setenv ("LD_LIBRARY_PATH_32", execdir); // solaris
401 u_setenv ("LD_LIBRARY_PATH_64", execdir); // solaris 592 u_setenv ("LD_LIBRARY_PATH_64", execdir); // solaris
402 u_setenv ("LD_LIBRARYN32_PATH", execdir); // irix 593 u_setenv ("LD_LIBRARYN32_PATH", execdir); // irix
403 u_setenv ("LD_LIBRARY64_PATH" , execdir); // irix 594 u_setenv ("LD_LIBRARY64_PATH" , execdir); // irix
404 u_setenv ("DYLD_LIBRARY_PATH" , execdir); // os sucks from apple 595 u_setenv ("DYLD_LIBRARY_PATH" , execdir); // os sucks from apple
596#endif
405} 597}
406 598
407static void 599static void
408execute (void) 600execute (void)
409{ 601{
410 exe_argv [exe_argc] = 0; 602 exe_argv [exe_argc] = 0;
411 systemv (exe_argv, 0); 603 systemv (exe_argv);
412} 604}
413 605
414#ifdef _WIN32 606#ifdef _WIN32
415 607
416int APIENTRY 608int APIENTRY
417WinMain (HINSTANCE hI, HINSTANCE hP, LPSTR argv, int command_show) 609WinMain (HINSTANCE hI, HINSTANCE hP, LPSTR argv, int command_show)
418{ 610{
419 if (!GetModuleFileName (hI, tmppath, sizeof (tmppath))) 611 if (!GetModuleFileName (hI, tmppath, sizeof (tmppath)))
420 fatal ("unable to find executable pack"); 612 fatal ("unable to find executable pack");
421 613
422 if (!(pack_handle = u_open (tmppath))) 614 pack_handle = u_open (tmppath);
615 if (!u_valid (pack_handle))
423 fatal ("unable to open executable pack"); 616 fatal ("unable to open executable pack");
424 617
425 exe_info (); 618 exe_info ();
426 619
427 if (!GetCurrentDirectory (sizeof (currdir), currdir)) 620 if (!GetCurrentDirectory (sizeof (currdir), currdir))
444int 637int
445main (int argc, char *argv[]) 638main (int argc, char *argv[])
446{ 639{
447 char *home = getenv ("HOME"); 640 char *home = getenv ("HOME");
448 641
449 // we assume fd 0 and 2 are "normal"
450
451 if (!(pack_handle = u_open (argv [0]))) 642 pack_handle = u_open (argv [0]);
643 if (!u_valid (pack_handle))
452 fatal ("unable to open executable pack"); 644 fatal ("unable to open executable pack");
453 645
454 exe_info (); 646 exe_info ();
455 647
456 if (!home) 648 if (!home)
465 657
466 if (!getcwd (currdir, sizeof (currdir))) 658 if (!getcwd (currdir, sizeof (currdir)))
467 strcpy (currdir, "."); 659 strcpy (currdir, ".");
468 660
469 u_mkdir (home); 661 u_mkdir (home);
662 //strcat (strcat (strcpy (datadir, home), "/."), URLADER);
470 sprintf (datadir, "%s/.%s", home, URLADER); 663 sprintf (datadir, "%s/.%s", home, URLADER);
471 u_mkdir (datadir); 664 u_mkdir (datadir);
472 665
666#if 0
473 if (gethostname (tmppath, sizeof (tmppath))) 667 if (gethostname (tmppath, sizeof (tmppath)))
474 strcpy (tmppath, "default"); 668 strcpy (tmppath, "default");
475 669
476 u_append (datadir, tmppath); 670 u_append (datadir, tmppath);
671#endif
477 672
478 load (); 673 load ();
479 execute (); 674 execute ();
480 675
481 return 0; 676 return 0;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines