[qfcc] Add a function to safely get cwd

getcwd is assumed to use malloc if its buff param is null. This may need
fixing in the future, but it's in one spot. The result in "saved" in the
non-progs pool.
This commit is contained in:
Bill Currie 2020-04-03 14:20:40 +09:00
parent 4b34bf3d95
commit 9089744290
2 changed files with 12 additions and 0 deletions

View file

@ -53,6 +53,8 @@ int strpool_addstr (strpool_t *strpool, const char *str);
*/
const char *save_string (const char *str);
const char *save_cwd (void);
const char *make_string (char *token, char **end);
const char *html_string (const char *str);

View file

@ -39,6 +39,7 @@
#endif
#include <stdlib.h>
#include <ctype.h>
#include <unistd.h>
#include "QF/dstring.h"
#include "QF/hash.h"
@ -140,6 +141,15 @@ save_string (const char *str)
return s;
}
const char *
save_cwd (void)
{
char *cwd = getcwd (0, 0);
const char *str = save_string (cwd);
free (cwd);
return str;
}
const char *
make_string (char *token, char **end)
{