From 9089744290a277fbec5e8220932d4d9e9de42740 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Fri, 3 Apr 2020 14:20:40 +0900 Subject: [PATCH] [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. --- tools/qfcc/include/strpool.h | 2 ++ tools/qfcc/source/strpool.c | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/tools/qfcc/include/strpool.h b/tools/qfcc/include/strpool.h index e6e065cb8..6cdc8eb83 100644 --- a/tools/qfcc/include/strpool.h +++ b/tools/qfcc/include/strpool.h @@ -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); diff --git a/tools/qfcc/source/strpool.c b/tools/qfcc/source/strpool.c index 8fb7642e6..0f10f81ee 100644 --- a/tools/qfcc/source/strpool.c +++ b/tools/qfcc/source/strpool.c @@ -39,6 +39,7 @@ #endif #include #include +#include #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) {