/ Return a json file contains. */ /
| 1902 | /* Return a json file contains. */ |
| 1903 | /*********************************************************************************/ |
| 1904 | char *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. */ |
no test coverage detected