… | |
… | |
33 | #define u_open(path) CreateFile (path, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, NULL) |
33 | #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) |
34 | #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) |
35 | #define u_close(handle) CloseHandle (handle) |
36 | #define u_append(path,add) PathAppend (path, add) |
36 | #define u_append(path,add) PathAppend (path, add) |
37 | #define u_write(handle,data,len) (WriteFile (handle, data, len, &dword, 0) ? dword : -1) |
37 | #define u_write(handle,data,len) (WriteFile (handle, data, len, &dword, 0) ? dword : -1) |
|
|
38 | #define u_sync() // use transacted I/O? |
38 | |
39 | |
39 | #else |
40 | #else |
40 | |
41 | |
41 | #include <sys/mman.h> |
42 | #include <sys/mman.h> |
42 | #include <sys/types.h> |
43 | #include <sys/types.h> |
… | |
… | |
56 | #define u_open(path) open (path, O_RDONLY) + 1 |
57 | #define u_open(path) open (path, O_RDONLY) + 1 |
57 | #define u_creat(path,exec) open (path, O_WRONLY | O_CREAT | O_TRUNC, (exec) ? 0777 : 0666) + 1 |
58 | #define u_creat(path,exec) open (path, O_WRONLY | O_CREAT | O_TRUNC, (exec) ? 0777 : 0666) + 1 |
58 | #define u_close(handle) close (handle - 1) |
59 | #define u_close(handle) close (handle - 1) |
59 | #define u_append(path,add) strcat (strcat (path, "/"), add) |
60 | #define u_append(path,add) strcat (strcat (path, "/"), add) |
60 | #define u_write(handle,data,len) write ((handle) - 1, data, len) |
61 | #define u_write(handle,data,len) write ((handle) - 1, data, len) |
|
|
62 | #define u_sync() sync () |
61 | |
63 | |
62 | #endif |
64 | #endif |
63 | |
65 | |
64 | #define u_16(ptr) (((ptr)[0] << 8) | (ptr)[1]) |
66 | #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]) |
67 | #define u_32(ptr) (((ptr)[0] << 24) | ((ptr)[1] << 16) | ((ptr)[2] << 8) | (ptr)[3]) |
… | |
… | |
369 | } |
371 | } |
370 | |
372 | |
371 | done: |
373 | done: |
372 | if (u_chdir (datadir)) |
374 | if (u_chdir (datadir)) |
373 | fatal ("unable to change to data directory"); |
375 | fatal ("unable to change to data directory"); |
|
|
376 | |
|
|
377 | u_sync (); |
374 | |
378 | |
375 | if (u_rename (tmppath, execdir)) |
379 | if (u_rename (tmppath, execdir)) |
376 | deltree (tmppath); // if move fails, delete new, assume other process created it independently |
380 | deltree (tmppath); // if move fails, delete new, assume other process created it independently |
377 | } |
381 | } |
378 | |
382 | |