MCPcopy Create free account
hub / github.com/MariaDB/server / ParseJsonFile

Method ParseJsonFile

storage/connect/bsonudf.cpp:1624–1670  ·  view source on GitHub ↗

/ Parse a json file. */ /

Source from the content-addressed store, hash-verified

1622/* Parse a json file. */
1623/*********************************************************************************/
1624PBVAL BJNX::ParseJsonFile(PGLOBAL g, char *fn, int& pty, size_t& len)
1625{
1626 char *memory;
1627 HANDLE hFile;
1628 MEMMAP mm;
1629 PBVAL jsp;
1630
1631 // Create the mapping file object
1632 hFile = CreateFileMap(g, fn, &mm, MODE_READ, false);
1633
1634 if (hFile == INVALID_HANDLE_VALUE) {
1635 DWORD rc = GetLastError();
1636
1637 if (!(*g->Message))
1638 snprintf(g->Message, sizeof(g->Message), MSG(OPEN_MODE_ERROR), "map", (int)rc, fn);
1639
1640 return NULL;
1641 } // endif hFile
1642
1643 // Get the file size
1644 len = (size_t)mm.lenL;
1645
1646 if (mm.lenH)
1647 len += mm.lenH;
1648
1649 memory = (char *)mm.memory;
1650
1651 if (!len) { // Empty or deleted file
1652 CloseFileHandle(hFile);
1653 return NULL;
1654 } // endif len
1655
1656 if (!memory) {
1657 CloseFileHandle(hFile);
1658 snprintf(g->Message, sizeof(g->Message), MSG(MAP_VIEW_ERROR), fn, GetLastError());
1659 return NULL;
1660 } // endif Memory
1661
1662 CloseFileHandle(hFile); // Not used anymore
1663
1664 // Parse the json file and allocate its tree structure
1665 g->Message[0] = 0;
1666 jsp = ParseJson(g, memory, len);
1667 pty = pretty;
1668 CloseMemMap(memory, len);
1669 return jsp;
1670} // end of ParseJsonFile
1671
1672/*********************************************************************************/
1673/* Make the result according to the first argument type. */

Callers 2

bson_fileFunction · 0.80
bbin_fileFunction · 0.80

Calls 5

CreateFileMapFunction · 0.85
GetLastErrorFunction · 0.85
CloseFileHandleFunction · 0.85
ParseJsonFunction · 0.85
CloseMemMapFunction · 0.85

Tested by

no test coverage detected