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

Function GetJsonFile

storage/connect/jsonudf.cpp:1904–1937  ·  view source on GitHub ↗

/ Return a json file contains. */ /

Source from the content-addressed store, hash-verified

1902/* Return a json file contains. */
1903/*********************************************************************************/
1904char *GetJsonFile(PGLOBAL g, char *fn)
1905{
1906 char *str;
1907 int h, n, len;
1908
1909#if defined(UNIX) || defined(UNIV_LINUX)
1910 h= open(fn, O_RDONLY);
1911#else
1912 h= open(fn, _O_RDONLY, _O_TEXT);
1913#endif
1914
1915 if (h == -1) {
1916 snprintf(g->Message, sizeof(g->Message), "Error %d opening %-.1024s", errno, fn);
1917 return NULL;
1918 } // endif h
1919
1920 if ((len = _filelength(h)) < 0) {
1921 snprintf(g->Message, sizeof(g->Message), MSG(FILELEN_ERROR), "_filelength", fn);
1922 close(h);
1923 return NULL;
1924 } // endif len
1925
1926 if ((str = (char*)PlgDBSubAlloc(g, NULL, len + 1))) {
1927 if ((n = read(h, str, len)) < 0) {
1928 snprintf(g->Message, sizeof(g->Message), "Error %d reading %d bytes from %-.1024s", errno, len, fn);
1929 return NULL;
1930 } // endif n
1931
1932 str[n] = 0;
1933 close(h);
1934 } // endif str
1935
1936 return str;
1937} // end of GetJsonFile
1938
1939/*********************************************************************************/
1940/* Make a JSON value from the passed argument. */

Callers 6

MakeValueMethod · 0.85
bson_fileFunction · 0.85
bfile_makeFunction · 0.85
MakeValueFunction · 0.85
json_fileFunction · 0.85
jfile_makeFunction · 0.85

Calls 2

_filelengthFunction · 0.85
PlgDBSubAllocFunction · 0.85

Tested by

no test coverage detected