| 7084 | #endif |
| 7085 | |
| 7086 | static void |
| 7087 | read_backend_variables(char *id, Port *port) |
| 7088 | { |
| 7089 | BackendParameters param; |
| 7090 | |
| 7091 | #ifndef WIN32 |
| 7092 | /* Non-win32 implementation reads from file */ |
| 7093 | FILE *fp; |
| 7094 | |
| 7095 | /* Open file */ |
| 7096 | fp = AllocateFile(id, PG_BINARY_R); |
| 7097 | if (!fp) |
| 7098 | { |
| 7099 | write_stderr("could not open backend variables file \"%s\": %s\n", |
| 7100 | id, strerror(errno)); |
| 7101 | exit(1); |
| 7102 | } |
| 7103 | |
| 7104 | if (fread(¶m, sizeof(param), 1, fp) != 1) |
| 7105 | { |
| 7106 | write_stderr("could not read from backend variables file \"%s\": %s\n", |
| 7107 | id, strerror(errno)); |
| 7108 | exit(1); |
| 7109 | } |
| 7110 | |
| 7111 | /* Release file */ |
| 7112 | FreeFile(fp); |
| 7113 | if (unlink(id) != 0) |
| 7114 | { |
| 7115 | write_stderr("could not remove file \"%s\": %s\n", |
| 7116 | id, strerror(errno)); |
| 7117 | exit(1); |
| 7118 | } |
| 7119 | #else |
| 7120 | /* Win32 version uses mapped file */ |
| 7121 | HANDLE paramHandle; |
| 7122 | BackendParameters *paramp; |
| 7123 | |
| 7124 | #ifdef _WIN64 |
| 7125 | paramHandle = (HANDLE) _atoi64(id); |
| 7126 | #else |
| 7127 | paramHandle = (HANDLE) atol(id); |
| 7128 | #endif |
| 7129 | paramp = MapViewOfFile(paramHandle, FILE_MAP_READ, 0, 0, 0); |
| 7130 | if (!paramp) |
| 7131 | { |
| 7132 | write_stderr("could not map view of backend variables: error code %lu\n", |
| 7133 | GetLastError()); |
| 7134 | exit(1); |
| 7135 | } |
| 7136 | |
| 7137 | memcpy(¶m, paramp, sizeof(BackendParameters)); |
| 7138 | |
| 7139 | if (!UnmapViewOfFile(paramp)) |
| 7140 | { |
| 7141 | write_stderr("could not unmap view of backend variables: error code %lu\n", |
| 7142 | GetLastError()); |
| 7143 | exit(1); |
no test coverage detected