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

Comparing Urlader/urlader.c (file contents):
Revision 1.4 by root, Fri Dec 30 05:27:32 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 45
39 #define u_fsync(handle) FlushFileBuffers (handle) 46 #define u_fsync(handle) FlushFileBuffers (handle)
40 #define u_sync() 47 #define u_sync()
41 48
42#else 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)
43 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
44 #include <sys/mman.h> 58 #include <sys/mman.h>
45 #include <sys/types.h> 59 #include <sys/types.h>
60 #include <sys/stat.h>
61 #include <unistd.h>
46 #include <pwd.h> 62 #include <pwd.h>
47 63
64 #if defined (MAP_ANON) && !defined (MAP_ANONYMOUS)
65 #define MAP_ANONYMOUS MAP_ANON
66 #endif
67
48 #ifdef PATH_MAX 68 #ifdef PATH_MAX
49 #define MAX_PATH (PATH_MAX < 4096 ? 4096 : PATH_MAX) 69 #define MAX_PATH (PATH_MAX < 4096 ? 4096 : PATH_MAX)
50 #else 70 #else
51 #define MAX_PATH 4096 71 #define MAX_PATH 4096
52 #endif 72 #endif
53 73
54 #define u_handle int 74 #define u_handle int
75 #define u_invalid_handle -1
76 #define u_valid(fd) ((fd) >= 0)
77
55 #define u_setenv(name,value) setenv (name, value, 1) 78 #define u_setenv(name,value) setenv (name, value, 1)
56 #define u_mkdir(path) mkdir (path, 0777) 79 #define u_mkdir(path) mkdir (path, 0777)
57 #define u_chdir(path) chdir (path) 80 #define u_chdir(path) chdir (path)
58 #define u_rename(fr,to) rename (fr, to) 81 #define u_rename(fr,to) rename (fr, to)
59 #define u_open(path) open (path, O_RDONLY) + 1 82 #define u_open(path) open (path, O_RDONLY)
60 #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)
61 #define u_close(handle) close (handle - 1) 84 #define u_close(handle) close (handle)
62 #define u_append(path,add) strcat (strcat (path, "/"), add) 85 #define u_append(path,add) strcat (strcat (path, "/"), add)
63 #define u_write(handle,data,len) write ((handle) - 1, data, len) 86 #define u_write(handle,data,len) write (handle, data, len)
64 87
65 // on a mostly idle system, a sync at the end is certainly faster, hope for the best 88 // on a mostly idle system, a sync at the end is certainly faster, hope for the best
66 #define u_fsync(handle) 89 #define u_fsync(handle)
67 #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)
68 94
69#endif 95#endif
70 96
71#define u_16(ptr) (((ptr)[0] << 8) | (ptr)[1]) 97#define u_16(ptr) (((ptr)[0] << 8) | (ptr)[1])
72#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])
73 99
100/* some simple? dynamic memory management for paths might save ltos of ram */
74static u_handle pack_handle; 101static u_handle pack_handle;
102static u_handle lock_handle;
75static char tmppath[MAX_PATH]; 103static char tmppath[MAX_PATH];
76static char currdir[MAX_PATH]; 104static char currdir[MAX_PATH];
77static char datadir[MAX_PATH]; // %AppData%/urlader 105static char datadir[MAX_PATH]; // %AppData%/urlader
78static char exe_dir[MAX_PATH]; // %AppData%/urlader/EXE_ID 106static char exe_dir[MAX_PATH]; // %AppData%/urlader/EXE_ID
79static char execdir[MAX_PATH]; // %AppData%/urlader/EXE_ID/EXE_VER 107static char execdir[MAX_PATH]; // %AppData%/urlader/EXE_ID/EXE_VER
80static char exe_id[MAX_PATH]; 108static char exe_id[MAX_PATH];
81static char exe_ver[MAX_PATH]; 109static char exe_ver[MAX_PATH];
82 110
83static int exe_argc; 111static int exe_argc;
84static 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;
85 115
86static void 116static void
87fatal (const char *msg) 117fatal (const char *msg)
88{ 118{
89#ifdef _WIN32 119#ifdef _WIN32
90 MessageBox (0, msg, URLADER, 0); 120 MessageBox (0, msg, URLADER, 0);
91#else 121#else
92 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);
93#endif 125#endif
94 126
95 _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
96} 200}
97 201
98static void 202static void
99tmpdir (const char *dir) 203tmpdir (const char *dir)
100{ 204{
111 if (!u_mkdir (tmppath)) 215 if (!u_mkdir (tmppath))
112 return; 216 return;
113 } 217 }
114} 218}
115 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
116static void 300static void
117systemv (const char *const argv[], int dowait) 301systemv (const char *const argv[])
118{ 302{
119#ifdef _WIN32 303#ifdef _WIN32
120 _spawnv (P_WAIT, argv [0], argv); 304 _spawnv (P_WAIT, argv [0], argv);
121#else 305#else
122 pid_t pid = dowait ? fork () : 0; 306 pid_t pid = fork ();
123 307
124 if (pid < 0) 308 if (pid < 0)
125 fatal ("fork failure"); 309 fatal ("fork failure");
126 310
127 if (!pid) 311 if (!pid)
143 const char *argv[] = { getenv ("COMSPEC"), "/c", "rd", "/s", "/q", buf, 0 }; 327 const char *argv[] = { getenv ("COMSPEC"), "/c", "rd", "/s", "/q", buf, 0 };
144 sprintf (buf, "\"%s\"", path); 328 sprintf (buf, "\"%s\"", path);
145 #else 329 #else
146 const char *argv[] = { "/bin/rm", "-rf", path, 0 }; 330 const char *argv[] = { "/bin/rm", "-rf", path, 0 };
147 #endif 331 #endif
148 systemv (argv, 1); 332 systemv (argv);
149} 333}
150 334
151enum 335enum
152{ 336{
153 T_NULL, // 5 337 T_NULL, // 5
181}; 365};
182 366
183static char *pack_base, *pack_end; 367static char *pack_base, *pack_end;
184static struct hdr *pack_cur; 368static struct hdr *pack_cur;
185static char *scratch; 369static char *scratch;
186static unsigned int scratch_len; 370static unsigned int scratch_size;
187 371
188#define PACK_NAME ((char *)(pack_cur + 1)) 372#define PACK_NAME ((char *)(pack_cur + 1))
189#define PACK_DATA (PACK_NAME + u_16 (pack_cur->namelen) + 1) 373#define PACK_DATA (PACK_NAME + u_16 (pack_cur->namelen) + 1)
190#define PACK_VALID pack_cur->type 374#define PACK_VALID pack_cur->type
191 375
198} 382}
199 383
200static void 384static void
201pack_unmap (void) 385pack_unmap (void)
202{ 386{
203 if (!pack_base) 387 if (pack_base)
204 return; 388 {
205
206 free (scratch);
207
208#ifdef _WIN32
209 UnmapViewOfFile (pack_base);
210#else
211 munmap (pack_base, pack_end - pack_base); 389 u_munmap (pack_base, pack_end - pack_base);
212#endif 390 pack_base = 0;
391 }
392
393 if (scratch)
394 {
395 u_free (scratch, scratch_size);
396 scratch = 0;
397 }
213} 398}
214 399
215static int 400static int
216pack_map (void) 401pack_map (void)
217{ 402{
403 char *addr;
404 unsigned int size;
405
218#ifdef _WIN32 406#ifdef _WIN32
219 BY_HANDLE_FILE_INFORMATION fi; 407 BY_HANDLE_FILE_INFORMATION fi;
220 408
221 if (!GetFileInformationByHandle (pack_handle, &fi)) 409 if (!GetFileInformationByHandle (pack_handle, &fi))
222 return 0; 410 return 0;
223 411
224 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)
225 return 0; 419 return 0;
226 420
227 HANDLE handle = CreateFileMapping (pack_handle, 0, PAGE_READONLY, 0, fi.nFileSizeLow, NULL);
228
229 if (!handle)
230 return 0;
231
232 pack_unmap (); 421 pack_unmap ();
233 422
234 pack_base = MapViewOfFile (handle, FILE_MAP_READ, 0, 0, fi.nFileSizeLow);
235
236 CloseHandle (handle);
237
238 pack_end = pack_base + fi.nFileSizeLow;
239#else
240 off_t len = lseek (pack_handle - 1, 0, SEEK_END);
241
242 pack_unmap ();
243
244 pack_base = mmap (0, len, PROT_READ, MAP_SHARED, pack_handle - 1, 0);
245 if (pack_base == (void *)-1)
246 pack_base = 0; 423 pack_base = addr;
247
248 pack_end = pack_base + len; 424 pack_end = pack_base + size;
249#endif
250
251 if (!pack_base)
252 return 0;
253 425
254 struct tail *tail; 426 struct tail *tail;
255 427
256 tail = (void *)(pack_end - sizeof (*tail)); 428 tail = (void *)(pack_end - sizeof (*tail));
257 429
258 if (memcmp (tail->magic, TAIL_MAGIC, sizeof (TAIL_MAGIC) - 1)) 430 if (memcmp (tail->magic, TAIL_MAGIC, sizeof (TAIL_MAGIC) - 1))
259 return 0; 431 return 0;
260 432
261 pack_cur = (struct hdr *)(pack_end - u_32 (tail->size)); 433 pack_cur = (struct hdr *)(pack_end - u_32 (tail->size));
262 434
263 free (scratch);
264 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;
265 438
266 return 1; 439 return 1;
267} 440}
268 441
269static void 442static void
289 462
290 if (u_chdir (exe_dir)) 463 if (u_chdir (exe_dir))
291 fatal ("unable to change to application data directory"); 464 fatal ("unable to change to application data directory");
292 465
293 u_handle h = u_open ("override"); 466 u_handle h = u_open ("override");
294 if (h) 467 if (u_valid (h))
295 { 468 {
296 u_handle oh = pack_handle; 469 u_handle oh = pack_handle;
297 470
298 pack_handle = h; 471 pack_handle = h;
299 if (!pack_map ()) 472 if (!pack_map ())
314 for (;;) 487 for (;;)
315 { 488 {
316 if (pack_cur->type == T_ENV) 489 if (pack_cur->type == T_ENV)
317 u_setenv (PACK_NAME, PACK_DATA); 490 u_setenv (PACK_NAME, PACK_DATA);
318 else if (pack_cur->type == T_ARG) 491 else if (pack_cur->type == T_ARG)
319 exe_argv [exe_argc++] = strdup (PACK_NAME); 492 {
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 }
320 else 498 else
321 break; 499 break;
322 500
323 pack_next (); 501 pack_next ();
324 } 502 }
325 503
326done_env_arg: 504done_env_arg:
327 strcpy (execdir, exe_dir); 505 strcpy (execdir, exe_dir);
328 u_append (execdir, "i-"); 506 u_append (execdir, "i-");
329 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");
330 513
331 if (access (execdir, F_OK)) 514 if (access (execdir, F_OK))
332 { 515 {
333 // does not exist yet, so unpack and move 516 // does not exist yet, so unpack and move
334 tmpdir (exe_dir); 517 tmpdir (exe_dir);
349 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);
350 unsigned int dlen, len = u_32 (pack_cur->datalen); 533 unsigned int dlen, len = u_32 (pack_cur->datalen);
351 char *data = PACK_DATA; 534 char *data = PACK_DATA;
352 535
353 if (pack_cur->flags & F_LZF) 536 if (pack_cur->flags & F_LZF)
354 if (dlen = lzf_decompress (data, len, scratch, scratch_len)) 537 if (dlen = lzf_decompress (data, len, scratch, scratch_size))
355 { 538 {
356 data = scratch; 539 data = scratch;
357 len = dlen; 540 len = dlen;
358 } 541 }
359 else 542 else
360 fatal ("unable to uncompress file data - pack corrupted?"); 543 fatal ("unable to uncompress file data - pack corrupted?");
361 544
362 if (!h) 545 if (!u_valid (h))
363 fatal ("unable to unpack file from packfile - disk full?"); 546 fatal ("unable to unpack file from packfile - disk full?");
364 547
365 if (u_write (h, data, len) != len) 548 if (u_write (h, data, len) != len)
366 fatal ("unable to unpack file from packfile - disk full?"); 549 fatal ("unable to unpack file from packfile - disk full?");
367 550
398 u_setenv ("URLADER_EXECDIR", execdir); 581 u_setenv ("URLADER_EXECDIR", execdir);
399 u_setenv ("URLADER_EXE_ID" , exe_id); 582 u_setenv ("URLADER_EXE_ID" , exe_id);
400 u_setenv ("URLADER_EXE_DIR", exe_dir); 583 u_setenv ("URLADER_EXE_DIR", exe_dir);
401 u_setenv ("URLADER_EXE_VER", exe_ver); 584 u_setenv ("URLADER_EXE_VER", exe_ver);
402 585
586#if 0
403 // yes, this is overkill 587 // yes, this is overkill
404 u_setenv ("SHLIB_PATH" , execdir); // hpux 588 u_setenv ("SHLIB_PATH" , execdir); // hpux
405 u_setenv ("LIBPATH" , execdir); // aix 589 u_setenv ("LIBPATH" , execdir); // aix
406 u_setenv ("LD_LIBRARY_PATH" , execdir); // most elf systems 590 u_setenv ("LD_LIBRARY_PATH" , execdir); // most elf systems
407 u_setenv ("LD_LIBRARY_PATH_32", execdir); // solaris 591 u_setenv ("LD_LIBRARY_PATH_32", execdir); // solaris
408 u_setenv ("LD_LIBRARY_PATH_64", execdir); // solaris 592 u_setenv ("LD_LIBRARY_PATH_64", execdir); // solaris
409 u_setenv ("LD_LIBRARYN32_PATH", execdir); // irix 593 u_setenv ("LD_LIBRARYN32_PATH", execdir); // irix
410 u_setenv ("LD_LIBRARY64_PATH" , execdir); // irix 594 u_setenv ("LD_LIBRARY64_PATH" , execdir); // irix
411 u_setenv ("DYLD_LIBRARY_PATH" , execdir); // os sucks from apple 595 u_setenv ("DYLD_LIBRARY_PATH" , execdir); // os sucks from apple
596#endif
412} 597}
413 598
414static void 599static void
415execute (void) 600execute (void)
416{ 601{
417 exe_argv [exe_argc] = 0; 602 exe_argv [exe_argc] = 0;
418 systemv (exe_argv, 0); 603 systemv (exe_argv);
419} 604}
420 605
421#ifdef _WIN32 606#ifdef _WIN32
422 607
423int APIENTRY 608int APIENTRY
424WinMain (HINSTANCE hI, HINSTANCE hP, LPSTR argv, int command_show) 609WinMain (HINSTANCE hI, HINSTANCE hP, LPSTR argv, int command_show)
425{ 610{
426 if (!GetModuleFileName (hI, tmppath, sizeof (tmppath))) 611 if (!GetModuleFileName (hI, tmppath, sizeof (tmppath)))
427 fatal ("unable to find executable pack"); 612 fatal ("unable to find executable pack");
428 613
429 if (!(pack_handle = u_open (tmppath))) 614 pack_handle = u_open (tmppath);
615 if (!u_valid (pack_handle))
430 fatal ("unable to open executable pack"); 616 fatal ("unable to open executable pack");
431 617
432 exe_info (); 618 exe_info ();
433 619
434 if (!GetCurrentDirectory (sizeof (currdir), currdir)) 620 if (!GetCurrentDirectory (sizeof (currdir), currdir))
451int 637int
452main (int argc, char *argv[]) 638main (int argc, char *argv[])
453{ 639{
454 char *home = getenv ("HOME"); 640 char *home = getenv ("HOME");
455 641
456 // we assume fd 0 and 2 are "normal"
457
458 if (!(pack_handle = u_open (argv [0]))) 642 pack_handle = u_open (argv [0]);
643 if (!u_valid (pack_handle))
459 fatal ("unable to open executable pack"); 644 fatal ("unable to open executable pack");
460 645
461 exe_info (); 646 exe_info ();
462 647
463 if (!home) 648 if (!home)
472 657
473 if (!getcwd (currdir, sizeof (currdir))) 658 if (!getcwd (currdir, sizeof (currdir)))
474 strcpy (currdir, "."); 659 strcpy (currdir, ".");
475 660
476 u_mkdir (home); 661 u_mkdir (home);
662 //strcat (strcat (strcpy (datadir, home), "/."), URLADER);
477 sprintf (datadir, "%s/.%s", home, URLADER); 663 sprintf (datadir, "%s/.%s", home, URLADER);
478 u_mkdir (datadir); 664 u_mkdir (datadir);
479 665
666#if 0
480 if (gethostname (tmppath, sizeof (tmppath))) 667 if (gethostname (tmppath, sizeof (tmppath)))
481 strcpy (tmppath, "default"); 668 strcpy (tmppath, "default");
482 669
483 u_append (datadir, tmppath); 670 u_append (datadir, tmppath);
671#endif
484 672
485 load (); 673 load ();
486 execute (); 674 execute ();
487 675
488 return 0; 676 return 0;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines