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

Comparing Urlader/urlader.c (file contents):
Revision 1.1 by root, Thu Dec 29 00:44:21 2011 UTC vs.
Revision 1.6 by root, Fri Dec 30 12:21:28 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>
10#include <string.h> 13#include <string.h>
11#include <time.h> 14#include <time.h>
12#include <fcntl.h> 15#include <fcntl.h>
13 16
14#include "lzf_d.c" 17#include "liblzf/lzf_d.c"
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 45
39#else 46 #define u_fsync(handle) FlushFileBuffers (handle)
47 #define u_sync()
40 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 // acquire shared in addition to excl, then unlock excl
52 #define u_lock_write_to_read(wait) u_lock (U_LOCK_READ, 1); u_lock (U_UNLOCK, 1);
53
54#else
55
56 #define _GNU_SOURCE 1
57 #define _BSD_SOURCE 1
58 // the above increases our chances of getting MAP_ANONYMOUS
59
41 #include <sys/mman.h> 60 #include <sys/mman.h>
42 #include <sys/types.h> 61 #include <sys/types.h>
43 #include <pwd.h> 62 #include <pwd.h>
44 63
64 #if defined (MAP_ANON) && !defined (MAP_ANONYMOUS)
65 #define MAP_ANONYMOUS MAP_ANON
66 #endif
67
45 #ifdef PATH_MAX 68 #ifdef PATH_MAX
46 #define MAX_PATH (PATH_MAX < 4096 ? 4096 : PATH_MAX) 69 #define MAX_PATH (PATH_MAX < 4096 ? 4096 : PATH_MAX)
47 #else 70 #else
48 #define MAX_PATH 4096 71 #define MAX_PATH 4096
49 #endif 72 #endif
50 73
51 #define u_handle int 74 #define u_handle int
75 #define u_invalid_handle -1
76 #define u_valid(fd) ((fd) >= 0)
77
52 #define u_setenv(name,value) setenv (name, value, 1) 78 #define u_setenv(name,value) setenv (name, value, 1)
53 #define u_mkdir(path) mkdir (path, 0777) 79 #define u_mkdir(path) mkdir (path, 0777)
54 #define u_chdir(path) chdir (path) 80 #define u_chdir(path) chdir (path)
55 #define u_rename(fr,to) rename (fr, to) 81 #define u_rename(fr,to) rename (fr, to)
56 #define u_open(path) open (path, O_RDONLY) + 1 82 #define u_open(path) open (path, O_RDONLY)
57 #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)
58 #define u_close(handle) close (handle - 1) 84 #define u_close(handle) close (handle)
59 #define u_append(path,add) strcat (strcat (path, "/"), add) 85 #define u_append(path,add) strcat (strcat (path, "/"), add)
60 #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)
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)
94 #define u_lock_write_to_read(wait) u_lock (U_LOCK_READ, 1);
61 95
62#endif 96#endif
63 97
64#define u_16(ptr) (((ptr)[0] << 8) | (ptr)[1]) 98#define u_16(ptr) (((ptr)[0] << 8) | (ptr)[1])
65#define u_32(ptr) (((ptr)[0] << 24) | ((ptr)[1] << 16) | ((ptr)[2] << 8) | (ptr)[3]) 99#define u_32(ptr) (((ptr)[0] << 24) | ((ptr)[1] << 16) | ((ptr)[2] << 8) | (ptr)[3])
66 100
101/* some simple? dynamic memory management for paths might save ltos of ram */
67static u_handle pack_handle; 102static u_handle pack_handle;
103static u_handle lock_handle;
68static char tmppath[MAX_PATH]; 104static char tmppath[MAX_PATH];
69static char currdir[MAX_PATH]; 105static char currdir[MAX_PATH];
70static char datadir[MAX_PATH]; // %AppData%/urlader 106static char datadir[MAX_PATH]; // %AppData%/urlader
71static char exe_dir[MAX_PATH]; // %AppData%/urlader/EXE_ID 107static char exe_dir[MAX_PATH]; // %AppData%/urlader/EXE_ID
72static char execdir[MAX_PATH]; // %AppData%/urlader/EXE_ID/EXE_VER 108static char execdir[MAX_PATH]; // %AppData%/urlader/EXE_ID/EXE_VER
73static char exe_id[MAX_PATH]; 109static char exe_id[MAX_PATH];
74static char exe_ver[MAX_PATH]; 110static char exe_ver[MAX_PATH];
75 111
76static int exe_argc; 112static int exe_argc;
77static const char *exe_argv[32]; 113static const char *exe_argv[MAX_ARGC];
114static char exe_args[MAX_ARGS]; /* actual arguments strings copied here */
115static unsigned int exe_argo;
78 116
79static void 117static void
80fatal (const char *msg) 118fatal (const char *msg)
81{ 119{
82#ifdef _WIN32 120#ifdef _WIN32
83 MessageBox (0, msg, URLADER, 0); 121 MessageBox (0, msg, URLADER, 0);
84#else 122#else
85 fprintf (stderr, "%s: %s\n", URLADER, msg); 123 write (2, URLADER ": ", sizeof (URLADER ": ") - 1);
124 write (2, msg, strlen (msg));
125 write (2, "\n", 1);
86#endif 126#endif
87 127
88 _exit (1); 128 _exit (1);
129}
130
131static void *
132u_malloc (unsigned int size)
133{
134 void *addr;
135
136#ifdef _WIN32
137 HANDLE handle = CreateFileMapping (0, 0, PAGE_READWRITE, 0, size, NULL);
138
139 if (!handle)
140 return 0;
141
142 addr = MapViewOfFile (handle, FILE_MAP_WRITE, 0, 0, size);
143
144 CloseHandle (handle);
145#elif defined (MAP_ANONYMOUS)
146 addr = mmap (0, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0);
147
148 if (addr == (void *)-1)
149 addr = 0;
150#else
151 addr = malloc (size);
152#endif
153
154 return addr;
155}
156
157static void
158u_free (void *addr, unsigned int size)
159{
160#ifdef _WIN32
161 UnmapViewOfFile (addr);
162#elif defined (MAP_ANONYMOUS)
163 munmap (addr, size);
164#else
165 free (addr);
166#endif
167}
168
169static void *
170u_mmap (u_handle h, unsigned int size)
171{
172 void *addr;
173
174#ifdef _WIN32
175 HANDLE handle = CreateFileMapping (h, 0, PAGE_READONLY, 0, size, NULL);
176
177 if (!handle)
178 return 0;
179
180 addr = MapViewOfFile (handle, FILE_MAP_READ, 0, 0, size);
181
182 CloseHandle (handle);
183#else
184 addr = mmap (0, size, PROT_READ, MAP_SHARED, h, 0);
185
186 if (addr == (void *)-1)
187 addr = 0;
188#endif
189
190 return addr;
191}
192
193static void
194u_munmap (void *addr, unsigned int len)
195{
196#ifdef _WIN32
197 UnmapViewOfFile (addr);
198#else
199 munmap (addr, len);
200#endif
89} 201}
90 202
91static void 203static void
92tmpdir (const char *dir) 204tmpdir (const char *dir)
93{ 205{
102// #endif 214// #endif
103 215
104 if (!u_mkdir (tmppath)) 216 if (!u_mkdir (tmppath))
105 return; 217 return;
106 } 218 }
219}
220
221enum
222{
223 U_UNLOCK,
224 U_LOCK_READ,
225 U_LOCK_WRITE
226};
227
228static int
229u_lock (int mode, int dowait)
230{
231#ifdef _WIN32
232 if (mode == U_UNLOCK)
233 return !UnlockFile (lock_handle, 0, 0, 1, 0);
234 else
235 {
236 OVERLAPPED ov = { 0 };
237
238 return !LockFileEx (lock_handle,
239 0
240 | (mode == U_LOCK_WRITE ? LOCKFILE_EXCLUSIVE_LOCK : 0)
241 | (dowait ? 0 : LOCKFILE_FAIL_IMMEDIATELY),
242 0,
243 1, 0,
244 &ov);
245 }
246#else
247 static short mode2lck [] = { F_UNLCK, F_RDLCK, F_WRLCK };
248 struct flock lck;
249 lck.l_type = mode2lck [mode];
250 lck.l_whence = SEEK_SET;
251 lck.l_start = 0;
252 lck.l_len = 1;
253
254 return fcntl (lock_handle, dowait ? F_SETLKW : F_SETLK, &lck);
255#endif
107} 256}
108 257
109static void 258static void
110systemv (const char *const argv[]) 259systemv (const char *const argv[])
111{ 260{
139 const char *argv[] = { "/bin/rm", "-rf", path, 0 }; 288 const char *argv[] = { "/bin/rm", "-rf", path, 0 };
140 #endif 289 #endif
141 systemv (argv); 290 systemv (argv);
142} 291}
143 292
144static void
145execute (void)
146{
147 exe_argv [exe_argc] = 0;
148 systemv (exe_argv);
149}
150
151enum 293enum
152{ 294{
153 T_NULL, // 5 295 T_NULL, // 5
154 T_META, // 1 : exe_id, exe_ver 296 T_META, // 1 : exe_id, exe_ver
155 T_ARG, // 2 : arg
156 T_ENV, // 3 : name, value 297 T_ENV, // 2 : name, value
298 T_ARG, // 3 : arg
157 T_DIR, // 4+: path 299 T_DIR, // 4+: path
158 T_FILE, // 4+: path, data 300 T_FILE, // 4+: path, data
159 T_NUM 301 T_NUM
160}; 302};
161 303
180 char magic[12]; 322 char magic[12];
181}; 323};
182 324
183static char *pack_base, *pack_end; 325static char *pack_base, *pack_end;
184static struct hdr *pack_cur; 326static struct hdr *pack_cur;
327static char *scratch;
328static unsigned int scratch_size;
185 329
186#define PACK_NAME ((char *)(pack_cur + 1)) 330#define PACK_NAME ((char *)(pack_cur + 1))
187#define PACK_DATA (PACK_NAME + u_16 (pack_cur->namelen) + 1) 331#define PACK_DATA (PACK_NAME + u_16 (pack_cur->namelen) + 1)
188#define PACK_VALID pack_cur->type 332#define PACK_VALID pack_cur->type
189 333
196} 340}
197 341
198static void 342static void
199pack_unmap (void) 343pack_unmap (void)
200{ 344{
201 if (!pack_base) 345 if (pack_base)
202 return; 346 {
203
204#ifdef _WIN32
205 UnmapViewOfFile (pack_base);
206#else
207 munmap (pack_base, pack_end - pack_base); 347 u_munmap (pack_base, pack_end - pack_base);
208#endif 348 pack_base = 0;
349 }
350
351 if (scratch)
352 {
353 u_free (scratch, scratch_size);
354 scratch = 0;
355 }
209} 356}
210 357
211static int 358static int
212pack_map (void) 359pack_map (void)
213{ 360{
361 char *addr;
362 unsigned int size;
363
214#ifdef _WIN32 364#ifdef _WIN32
215 BY_HANDLE_FILE_INFORMATION fi; 365 BY_HANDLE_FILE_INFORMATION fi;
216 366
217 if (!GetFileInformationByHandle (pack_handle, &fi)) 367 if (!GetFileInformationByHandle (pack_handle, &fi))
218 return 0; 368 return 0;
219 369
220 if (fi.nFileSizeHigh) // too big 370 size = fi.nFileSizeLow;
371#else
372 size = lseek (pack_handle, 0, SEEK_END);
373#endif
374
375 addr = u_mmap (pack_handle, size);
376 if (!addr)
221 return 0; 377 return 0;
222 378
223 HANDLE handle = CreateFileMapping (pack_handle, 0, PAGE_READONLY, 0, fi.nFileSizeLow, NULL);
224
225 if (!handle)
226 return 0;
227
228 pack_unmap (); 379 pack_unmap ();
229 380
230 pack_base = MapViewOfFile (handle, FILE_MAP_READ, 0, 0, fi.nFileSizeLow);
231
232 CloseHandle (handle);
233
234 pack_end = pack_base + fi.nFileSizeLow;
235#else
236 off_t len = lseek (pack_handle - 1, 0, SEEK_END);
237
238 pack_unmap ();
239
240 pack_base = mmap (0, len, PROT_READ, MAP_SHARED, pack_handle - 1, 0);
241 if (pack_base == (void *)-1)
242 pack_base = 0; 381 pack_base = addr;
243
244 pack_end = pack_base + len; 382 pack_end = pack_base + size;
245#endif
246
247 if (!pack_base)
248 return 0;
249 383
250 struct tail *tail; 384 struct tail *tail;
251 385
252 tail = (void *)(pack_end - sizeof (*tail)); 386 tail = (void *)(pack_end - sizeof (*tail));
253 387
254 if (memcmp (tail->magic, TAIL_MAGIC, sizeof (TAIL_MAGIC) - 1)) 388 if (memcmp (tail->magic, TAIL_MAGIC, sizeof (TAIL_MAGIC) - 1))
255 return 0; 389 return 0;
256 390
257 pack_cur = (struct hdr *)(pack_end - u_32 (tail->size)); 391 pack_cur = (struct hdr *)(pack_end - u_32 (tail->size));
392
393 scratch = u_malloc (scratch_size = u_32 (tail->max_filesize));
394 if (!scratch)
395 return 0;
258 396
259 return 1; 397 return 1;
260} 398}
261 399
262static void 400static void
282 420
283 if (u_chdir (exe_dir)) 421 if (u_chdir (exe_dir))
284 fatal ("unable to change to application data directory"); 422 fatal ("unable to change to application data directory");
285 423
286 u_handle h = u_open ("override"); 424 u_handle h = u_open ("override");
287 if (h) 425 if (u_valid (h))
288 { 426 {
289 u_handle oh = pack_handle; 427 u_handle oh = pack_handle;
290 428
291 pack_handle = h; 429 pack_handle = h;
292 if (!pack_map ()) 430 if (!pack_map ())
302 fatal ("unable to locate override metadata"); 440 fatal ("unable to locate override metadata");
303 441
304 strcpy (exe_ver, PACK_DATA); 442 strcpy (exe_ver, PACK_DATA);
305 pack_next (); 443 pack_next ();
306 444
445 for (;;)
446 {
447 if (pack_cur->type == T_ENV)
448 u_setenv (PACK_NAME, PACK_DATA);
307 while (pack_cur->type == T_ARG) 449 else if (pack_cur->type == T_ARG)
308 { 450 {
309 exe_argv [exe_argc++] = strdup (PACK_NAME); 451 int len = u_16 (pack_cur->namelen) + 1;
452 exe_argv [exe_argc++] = exe_args + exe_argo;
453 memcpy (exe_args + exe_argo, PACK_NAME, len);
454 exe_argo += len;
455 }
456 else
457 break;
458
310 pack_next (); 459 pack_next ();
311 } 460 }
312 461
313 while (pack_cur->type == T_ENV) 462done_env_arg:
314 {
315 u_setenv (PACK_NAME, PACK_DATA);
316 pack_next ();
317 }
318
319 strcpy (execdir, exe_dir); 463 strcpy (execdir, exe_dir);
320 u_append (execdir, "i-"); 464 u_append (execdir, "i-");
321 strcat (execdir, exe_ver); 465 strcat (execdir, exe_ver);
466
467 strcat (strcpy (tmppath, execdir), ".lck");
468 lock_handle = u_lockfile (tmppath);
469 if (!lock_handle)
470 fatal ("unable to create lock file");
471
472 u_cloexec (lock_handle);
473
474 // all users that uee an instance acquire a shared lock
475 // acquiring an exclusive lock is enough to delete the dir
476 // deleeting the lockfile is another topic altogether
477 u_lock (U_LOCK_READ, 1);
322 478
323 if (access (execdir, F_OK)) 479 if (access (execdir, F_OK))
324 { 480 {
325 // does not exist yet, so unpack and move 481 // does not exist yet, so unpack and move
326 tmpdir (exe_dir); 482 tmpdir (exe_dir);
337 break; 493 break;
338 494
339 case T_FILE: 495 case T_FILE:
340 { 496 {
341 u_handle h = u_creat (PACK_NAME, pack_cur->flags & F_EXEC); 497 u_handle h = u_creat (PACK_NAME, pack_cur->flags & F_EXEC);
342 unsigned int len = u_32 (pack_cur->datalen); 498 unsigned int dlen, len = u_32 (pack_cur->datalen);
499 char *data = PACK_DATA;
343 500
501 if (pack_cur->flags & F_LZF)
502 if (dlen = lzf_decompress (data, len, scratch, scratch_size))
503 {
504 data = scratch;
505 len = dlen;
506 }
507 else
508 fatal ("unable to uncompress file data - pack corrupted?");
509
344 if (!h) 510 if (!u_valid (h))
345 fatal ("unable to unpack file from packfile - disk full?"); 511 fatal ("unable to unpack file from packfile - disk full?");
346 512
347 if (u_write (h, PACK_DATA, len) != len) 513 if (u_write (h, data, len) != len)
348 fatal ("unable to unpack file from packfile - disk full?"); 514 fatal ("unable to unpack file from packfile - disk full?");
349 515
516 u_fsync (h);
350 u_close (h); 517 u_close (h);
351 } 518 }
352 break; 519 break;
353 520
354 case T_NULL: 521 case T_NULL:
360 527
361done: 528done:
362 if (u_chdir (datadir)) 529 if (u_chdir (datadir))
363 fatal ("unable to change to data directory"); 530 fatal ("unable to change to data directory");
364 531
532 u_sync ();
533
365 if (u_rename (tmppath, execdir)) 534 if (u_rename (tmppath, execdir))
366 deltree (tmppath); // if move fails, delete new, assume other process created it independently 535 deltree (tmppath); // if move fails, delete new, assume other process created it independently
367
368 if (u_chdir (execdir))
369 fatal ("unable to change to application instance directory");
370 } 536 }
371 537
372 pack_unmap (); 538 pack_unmap ();
373 u_close (pack_handle); 539 u_close (pack_handle);
540
541 if (u_chdir (execdir))
542 fatal ("unable to change to application instance directory");
374 543
375 u_setenv ("URLADER_VERSION", URLADER_VERSION); 544 u_setenv ("URLADER_VERSION", URLADER_VERSION);
376 u_setenv ("URLADER_DATADIR", datadir); 545 u_setenv ("URLADER_DATADIR", datadir);
377 u_setenv ("URLADER_EXECDIR", execdir); 546 u_setenv ("URLADER_EXECDIR", execdir);
378 u_setenv ("URLADER_EXE_ID" , exe_id); 547 u_setenv ("URLADER_EXE_ID" , exe_id);
379 u_setenv ("URLADER_EXE_DIR", exe_dir); 548 u_setenv ("URLADER_EXE_DIR", exe_dir);
380 u_setenv ("URLADER_EXE_VER", exe_ver); 549 u_setenv ("URLADER_EXE_VER", exe_ver);
381 550
551#if 0
382 // yes, this is overkill 552 // yes, this is overkill
383 u_setenv ("SHLIB_PATH" , execdir); // hpux 553 u_setenv ("SHLIB_PATH" , execdir); // hpux
384 u_setenv ("LIBPATH" , execdir); // aix 554 u_setenv ("LIBPATH" , execdir); // aix
385 u_setenv ("LD_LIBRARY_PATH" , execdir); // most elf systems 555 u_setenv ("LD_LIBRARY_PATH" , execdir); // most elf systems
386 u_setenv ("LD_LIBRARY_PATH_32", execdir); // solaris 556 u_setenv ("LD_LIBRARY_PATH_32", execdir); // solaris
387 u_setenv ("LD_LIBRARY_PATH_64", execdir); // solaris 557 u_setenv ("LD_LIBRARY_PATH_64", execdir); // solaris
388 u_setenv ("LD_LIBRARYN32_PATH", execdir); // irix 558 u_setenv ("LD_LIBRARYN32_PATH", execdir); // irix
389 u_setenv ("LD_LIBRARY64_PATH" , execdir); // irix 559 u_setenv ("LD_LIBRARY64_PATH" , execdir); // irix
390 u_setenv ("DYLD_LIBRARY_PATH" , execdir); // os sucks from apple 560 u_setenv ("DYLD_LIBRARY_PATH" , execdir); // os sucks from apple
561#endif
562}
563
564static void
565execute (void)
566{
567 exe_argv [exe_argc] = 0;
568 systemv (exe_argv);
391} 569}
392 570
393#ifdef _WIN32 571#ifdef _WIN32
394 572
395int APIENTRY 573int APIENTRY
396WinMain (HINSTANCE hI, HINSTANCE hP, LPSTR argv, int command_show) 574WinMain (HINSTANCE hI, HINSTANCE hP, LPSTR argv, int command_show)
397{ 575{
398 if (!GetModuleFileName (hI, tmppath, sizeof (tmppath))) 576 if (!GetModuleFileName (hI, tmppath, sizeof (tmppath)))
399 fatal ("unable to find executable pack"); 577 fatal ("unable to find executable pack");
400 578
401 if (!(pack_handle = u_open (tmppath))) 579 pack_handle = u_open (tmppath);
580 if (!u_valid (pack_handle))
402 fatal ("unable to open executable pack"); 581 fatal ("unable to open executable pack");
403 582
404 exe_info (); 583 exe_info ();
405 584
406 if (!GetCurrentDirectory (sizeof (currdir), currdir)) 585 if (!GetCurrentDirectory (sizeof (currdir), currdir))
423int 602int
424main (int argc, char *argv[]) 603main (int argc, char *argv[])
425{ 604{
426 char *home = getenv ("HOME"); 605 char *home = getenv ("HOME");
427 606
428 // we assume fd 0 and 2 are "normal"
429
430 if (!(pack_handle = u_open (argv [0]))) 607 pack_handle = u_open (argv [0]);
608 if (!u_valid (pack_handle))
431 fatal ("unable to open executable pack"); 609 fatal ("unable to open executable pack");
432 610
433 exe_info (); 611 exe_info ();
434 612
435 if (!home) 613 if (!home)
444 622
445 if (!getcwd (currdir, sizeof (currdir))) 623 if (!getcwd (currdir, sizeof (currdir)))
446 strcpy (currdir, "."); 624 strcpy (currdir, ".");
447 625
448 u_mkdir (home); 626 u_mkdir (home);
627 //strcat (strcat (strcpy (datadir, home), "/."), URLADER);
449 sprintf (datadir, "%s/.%s", home, URLADER); 628 sprintf (datadir, "%s/.%s", home, URLADER);
450 u_mkdir (datadir); 629 u_mkdir (datadir);
451 630
631#if 0
452 if (gethostname (tmppath, sizeof (tmppath))) 632 if (gethostname (tmppath, sizeof (tmppath)))
453 strcpy (tmppath, "default"); 633 strcpy (tmppath, "default");
454 634
455 u_append (datadir, tmppath); 635 u_append (datadir, tmppath);
636#endif
456 637
457 load (); 638 load ();
458 execute (); 639 execute ();
459 640
460 return 0; 641 return 0;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines