/ Copy a json file to another with pretty = 0. */ /
| 6125 | /* Copy a json file to another with pretty = 0. */ |
| 6126 | /*********************************************************************************/ |
| 6127 | char* JUP::UnprettyJsonFile(PGLOBAL g, char *fn, char *outfn, int lrecl) { |
| 6128 | char *ret = NULL; |
| 6129 | HANDLE hFile; |
| 6130 | MEMMAP mm; |
| 6131 | |
| 6132 | /*******************************************************************************/ |
| 6133 | /* Create the mapping file object. */ |
| 6134 | /*******************************************************************************/ |
| 6135 | hFile = CreateFileMap(g, fn, &mm, MODE_READ, false); |
| 6136 | |
| 6137 | if (hFile == INVALID_HANDLE_VALUE) { |
| 6138 | DWORD rc = GetLastError(); |
| 6139 | |
| 6140 | if (!(*g->Message)) |
| 6141 | snprintf(g->Message, sizeof(g->Message), MSG(OPEN_MODE_ERROR), "map", (int)rc, fn); |
| 6142 | |
| 6143 | return NULL; |
| 6144 | } // endif hFile |
| 6145 | |
| 6146 | /*******************************************************************************/ |
| 6147 | /* Get the file size (assuming file is smaller than 4 GB) */ |
| 6148 | /*******************************************************************************/ |
| 6149 | if (!mm.lenL && !mm.lenH) { // Empty or deleted file |
| 6150 | CloseFileHandle(hFile); |
| 6151 | return NULL; |
| 6152 | } else { |
| 6153 | len = (size_t)mm.lenL; |
| 6154 | |
| 6155 | if (mm.lenH) |
| 6156 | len += ((size_t)mm.lenH * 0x000000001LL); |
| 6157 | |
| 6158 | } // endif size |
| 6159 | |
| 6160 | if (!mm.memory) { |
| 6161 | CloseFileHandle(hFile); |
| 6162 | snprintf(g->Message, sizeof(g->Message), MSG(MAP_VIEW_ERROR), fn, GetLastError()); |
| 6163 | return NULL; |
| 6164 | } else |
| 6165 | s = (char*)mm.memory; |
| 6166 | |
| 6167 | CloseFileHandle(hFile); // Not used anymore |
| 6168 | |
| 6169 | /*********************************************************************************/ |
| 6170 | /* Parse the json file and allocate its tree structure. */ |
| 6171 | /*********************************************************************************/ |
| 6172 | if (!(fs = fopen(outfn, "wb"))) { |
| 6173 | snprintf(g->Message, sizeof(g->Message), MSG(OPEN_MODE_ERROR)": %s", |
| 6174 | "w", (int)errno, outfn, strerror(errno)); |
| 6175 | CloseMemMap(mm.memory, len); |
| 6176 | return NULL; |
| 6177 | } // endif fs |
| 6178 | |
| 6179 | g->Message[0] = 0; |
| 6180 | |
| 6181 | if (!unPretty(g, lrecl)) |
| 6182 | ret = outfn; |
| 6183 | |
| 6184 | CloseMemMap(mm.memory, len); |
no test coverage detected