--- Urlader/urlader.c 2011/12/30 05:27:32 1.4 +++ Urlader/urlader.c 2011/12/30 09:34:20 1.5 @@ -1,7 +1,7 @@ #ifndef URLADER # define URLADER "urlader" #endif -#define URLADER_VERSION "1.0" +#define URLADER_VERSION "1.0" // a decimal number, not a version string #include #include @@ -26,6 +26,8 @@ static DWORD dword; #define u_handle HANDLE + #define u_valid(handle) (!!handle) + #define u_setenv(name,value) SetEnvironmentVariable (name, value) #define u_mkdir(path) !CreateDirectory (path, NULL) #define u_chdir(path) !SetCurrentDirectory (path) @@ -52,15 +54,17 @@ #endif #define u_handle int + #define u_valid(fd) ((fd) >= 0) + #define u_setenv(name,value) setenv (name, value, 1) #define u_mkdir(path) mkdir (path, 0777) #define u_chdir(path) chdir (path) #define u_rename(fr,to) rename (fr, to) - #define u_open(path) open (path, O_RDONLY) + 1 - #define u_creat(path,exec) open (path, O_WRONLY | O_CREAT | O_TRUNC, (exec) ? 0777 : 0666) + 1 - #define u_close(handle) close (handle - 1) + #define u_open(path) open (path, O_RDONLY) + #define u_creat(path,exec) open (path, O_WRONLY | O_CREAT | O_TRUNC, (exec) ? 0777 : 0666) + #define u_close(handle) close (handle) #define u_append(path,add) strcat (strcat (path, "/"), add) - #define u_write(handle,data,len) write ((handle) - 1, data, len) + #define u_write(handle,data,len) write (handle, data, len) // on a mostly idle system, a sync at the end is certainly faster, hope for the best #define u_fsync(handle) @@ -291,7 +295,7 @@ fatal ("unable to change to application data directory"); u_handle h = u_open ("override"); - if (h) + if (u_valid (h)) { u_handle oh = pack_handle; @@ -359,7 +363,7 @@ else fatal ("unable to uncompress file data - pack corrupted?"); - if (!h) + if (!u_valid (h)) fatal ("unable to unpack file from packfile - disk full?"); if (u_write (h, data, len) != len) @@ -400,6 +404,7 @@ u_setenv ("URLADER_EXE_DIR", exe_dir); u_setenv ("URLADER_EXE_VER", exe_ver); +#if 0 // yes, this is overkill u_setenv ("SHLIB_PATH" , execdir); // hpux u_setenv ("LIBPATH" , execdir); // aix @@ -409,6 +414,7 @@ u_setenv ("LD_LIBRARYN32_PATH", execdir); // irix u_setenv ("LD_LIBRARY64_PATH" , execdir); // irix u_setenv ("DYLD_LIBRARY_PATH" , execdir); // os sucks from apple +#endif } static void @@ -426,7 +432,8 @@ if (!GetModuleFileName (hI, tmppath, sizeof (tmppath))) fatal ("unable to find executable pack"); - if (!(pack_handle = u_open (tmppath))) + pack_handle = u_open (tmppath); + if (!u_valid (pack_handle)) fatal ("unable to open executable pack"); exe_info (); @@ -453,9 +460,8 @@ { char *home = getenv ("HOME"); - // we assume fd 0 and 2 are "normal" - - if (!(pack_handle = u_open (argv [0]))) + pack_handle = u_open (argv [0]); + if (!u_valid (pack_handle)) fatal ("unable to open executable pack"); exe_info (); @@ -477,10 +483,12 @@ sprintf (datadir, "%s/.%s", home, URLADER); u_mkdir (datadir); +#if 0 if (gethostname (tmppath, sizeof (tmppath))) strcpy (tmppath, "default"); u_append (datadir, tmppath); +#endif load (); execute ();