X-Git-Url: https://harishankar.org/repos/?p=biaweb2.git;a=blobdiff_plain;f=biawebutil.hpp;h=c8603ea106530e7cdc55e52168cc8a0d7e8827e9;hp=b5196158a421b085737a9ce668d67b3e59fb8e0e;hb=44d5fb1ff24147859c5f198dd47f6956ec5fea51;hpb=f56e2150cc79638c890ef23ef82097a4bdffd2ce diff --git a/biawebutil.hpp b/biawebutil.hpp index b519615..c8603ea 100644 --- a/biawebutil.hpp +++ b/biawebutil.hpp @@ -1,6 +1,7 @@ #ifndef __BIAWEBUTIL__ #define __BIAWEBUTIL__ #include + // "discount" markdown library is a C library and hence requires to be wrapped in // extern "C" extern "C" { @@ -10,8 +11,8 @@ extern "C" { // utility functions for Biaweb that don't fit into any class and can be used by // any class namespace biaweb { - // convert markdown + // convert markdown std::string convert_to_markdown (std::string str) { // discount is a C library and it doesn't work well with C++ streams // and there seems no way to get the output of any of these functions @@ -22,16 +23,19 @@ namespace biaweb { // till a cleaner solution can be found. MMIOT *doc; doc = mkd_string (str.c_str(), str.size(), 0); - FILE *f = fopen (".biaweb.tmp", "w"); + char tempfile[20]; + strcpy (tempfile, "/tmp/biawebXXXXXX"); + int fd = mkstemp (tempfile); + FILE *f = fdopen (fd, "w"); markdown (doc, f, 0); fclose (f); - std::ifstream ftmp (".biaweb.tmp"); + std::ifstream ftmp (tempfile); std::string tmpl ( (std::istreambuf_iterator (ftmp)), (std::istreambuf_iterator ()) ); ftmp.close (); mkd_cleanup (doc); - remove (".biaweb.tmp"); + remove (tempfile); return tmpl; }