| 1 | #include <time.h> |
|---|
| 2 | #include <windows.h> |
|---|
| 3 | |
|---|
| 4 | typedef int uid_t; |
|---|
| 5 | typedef int gid_t; |
|---|
| 6 | typedef int u_int32_t; |
|---|
| 7 | |
|---|
| 8 | #include "emu.h" |
|---|
| 9 | |
|---|
| 10 | int main(int argc, char** argv) |
|---|
| 11 | { |
|---|
| 12 | time_t time_now = time(NULL); |
|---|
| 13 | char* time_str = strdup(asctime(gmtime(&time_now))); |
|---|
| 14 | time_str[24] = 0; |
|---|
| 15 | |
|---|
| 16 | printf("Time now is %d (%s)\n", time_now, time_str); |
|---|
| 17 | |
|---|
| 18 | char testfile[80]; |
|---|
| 19 | snprintf(testfile, sizeof(testfile), "test.%d", time_now); |
|---|
| 20 | printf("Test file is: %s\n", testfile); |
|---|
| 21 | |
|---|
| 22 | _unlink(testfile); |
|---|
| 23 | |
|---|
| 24 | /* |
|---|
| 25 | int fd = open(testfile, O_RDWR | O_CREAT | O_EXCL); |
|---|
| 26 | if (fd < 0) |
|---|
| 27 | { |
|---|
| 28 | perror("open"); |
|---|
| 29 | exit(1); |
|---|
| 30 | } |
|---|
| 31 | close(fd); |
|---|
| 32 | */ |
|---|
| 33 | |
|---|
| 34 | HANDLE fh = CreateFileA(testfile, FILE_READ_ATTRIBUTES, |
|---|
| 35 | FILE_SHARE_READ | FILE_SHARE_DELETE, NULL, CREATE_ALWAYS, |
|---|
| 36 | FILE_ATTRIBUTE_TEMPORARY | FILE_FLAG_DELETE_ON_CLOSE, NULL); |
|---|
| 37 | |
|---|
| 38 | if (!fh) |
|---|
| 39 | { |
|---|
| 40 | fprintf(stderr, "Failed to open file '%s': error %d\n", |
|---|
| 41 | testfile, GetLastError()); |
|---|
| 42 | exit(1); |
|---|
| 43 | } |
|---|
| 44 | |
|---|
| 45 | BY_HANDLE_FILE_INFORMATION fi; |
|---|
| 46 | |
|---|
| 47 | if (!GetFileInformationByHandle(fh, &fi)) |
|---|
| 48 | { |
|---|
| 49 | fprintf(stderr, "Failed to get file information for '%s': " |
|---|
| 50 | "error %d\n", testfile, GetLastError()); |
|---|
| 51 | exit(1); |
|---|
| 52 | } |
|---|
| 53 | |
|---|
| 54 | if (!CloseHandle(fh)) |
|---|
| 55 | { |
|---|
| 56 | fprintf(stderr, "Failed to close file: error %d\n", |
|---|
| 57 | GetLastError()); |
|---|
| 58 | exit(1); |
|---|
| 59 | } |
|---|
| 60 | |
|---|
| 61 | time_t created_time = ConvertFileTimeToTime_t(&fi.ftCreationTime); |
|---|
| 62 | time_str = strdup(asctime(gmtime(&created_time))); |
|---|
| 63 | time_str[24] = 0; |
|---|
| 64 | |
|---|
| 65 | printf("File created time: %d (%s)\n", created_time, time_str); |
|---|
| 66 | |
|---|
| 67 | printf("Difference is: %d\n", created_time - time_now); |
|---|
| 68 | |
|---|
| 69 | if (abs(created_time - time_now) > 30) |
|---|
| 70 | { |
|---|
| 71 | fprintf(stderr, "Error: time difference too big: " |
|---|
| 72 | "bug in emu.h?\n"); |
|---|
| 73 | exit(1); |
|---|
| 74 | } |
|---|
| 75 | |
|---|
| 76 | /* |
|---|
| 77 | sleep(1); |
|---|
| 78 | |
|---|
| 79 | if (_unlink(testfile) != 0) |
|---|
| 80 | { |
|---|
| 81 | perror("Failed to delete test file"); |
|---|
| 82 | exit(1); |
|---|
| 83 | } |
|---|
| 84 | */ |
|---|
| 85 | |
|---|
| 86 | exit(0); |
|---|
| 87 | } |
|---|