From 412adaa4926414234039f5d0a0dcf2087e1db186ead314df1c434599472c9799 Mon Sep 17 00:00:00 2001 From: ADAM David Alan Martin Date: Sat, 23 Aug 2025 02:20:05 -0400 Subject: [PATCH] Rename getline function to unsafe, to make it greppable. Now i can trim them one-by-one. --- dlib/dlib.cc | 30 +++++++++++++++--------------- dlib/dlib.hh | 3 ++- dpi/bookmarks.cc | 2 +- dpid/dpi.cc | 2 +- dpid/dpid.cc | 4 ++-- dpid/dpidc.cc | 2 +- dpip/dpip.cc | 2 +- src/IO/dpi.cc | 2 +- src/domain.cc | 2 +- src/keys.cc | 2 +- src/prefsparser.cc | 2 +- 11 files changed, 27 insertions(+), 26 deletions(-) diff --git a/dlib/dlib.cc b/dlib/dlib.cc index 280d125..a8b0809 100644 --- a/dlib/dlib.cc +++ b/dlib/dlib.cc @@ -942,7 +942,7 @@ char *dGethomedir (void) * Get a line from a FILE stream. * Return value: read line on success, NULL on EOF. */ -char *dGetline (FILE *stream) +char *dGetline_unsafe (FILE *stream) { int ch; Dstr *dstr; @@ -963,24 +963,24 @@ char *dGetline (FILE *stream) } std::optional< std::string > -dGetline_string (FILE *stream) +dGetline( FILE *const stream ) { - int ch; - Dstr *dstr; + std::string rv; + int ch; - if( stream == nullptr ) return std::nullopt; + if( stream == nullptr ) return std::nullopt; - dstr = dStr_sized_new(64); - while ((ch = fgetc(stream)) != EOF) { - dStr_append_c(dstr, ch); - if (ch == '\n') - break; - } + while( ( ch= fgetc( stream ) ) != EOF ) + { + rv+= ch; + if (ch == '\n') + break; + } - std::optional< std::string > line; - if(dstr->len) line= dstr->str; - dStr_free(dstr, 1); - return line; + std::optional< std::string > line; + if(rv.size()) line= std::move( rv ); + + return line; } /** diff --git a/dlib/dlib.hh b/dlib/dlib.hh index 4ae7e1b..c437553 100644 --- a/dlib/dlib.hh +++ b/dlib/dlib.hh @@ -186,7 +186,8 @@ void dLib_show_messages(bool show); char *dGetcwd(void); char *dGethomedir(void); std::optional< std::string > dGetline_string(FILE *stream); -char *dGetline(FILE *stream); +char *dGetline_unsafe(FILE *stream); +std::optional< std::string > dGetline(FILE *stream); int dClose(int fd); int dUsleep(unsigned long us); diff --git a/dpi/bookmarks.cc b/dpi/bookmarks.cc index ffa81be..96ac5e6 100644 --- a/dpi/bookmarks.cc +++ b/dpi/bookmarks.cc @@ -628,7 +628,7 @@ static int Bms_load(void) } /* load bm file into memory */ - while ((buf = dGetline(BmTxt)) != NULL) { + while ((buf = dGetline_unsafe(BmTxt)) != NULL) { if (buf[0] == 's') { /* get section, url and title */ section = strtol(buf + 1, NULL, 10); diff --git a/dpid/dpi.cc b/dpid/dpi.cc index 965ed3e..824e0a5 100644 --- a/dpid/dpi.cc +++ b/dpid/dpi.cc @@ -64,7 +64,7 @@ char *a_Dpi_rd_dpi_socket_dir(char *dirname) dFree(rcpath); if ((dir = fopen(dirname, "r")) != NULL) { - sockdir = dGetline(dir); + sockdir = dGetline_unsafe(dir); fclose(dir); } else if (errno == ENOENT) { ERRMSG("a_Dpi_rd_dpi_socket_dir", "fopen", errno); diff --git a/dpid/dpid.cc b/dpid/dpid.cc index 0b14258..30c2304 100644 --- a/dpid/dpid.cc +++ b/dpid/dpid.cc @@ -189,7 +189,7 @@ char *get_dpi_dir(char *dpidrc) return (NULL); } - while ((rcline = dGetline(In)) != NULL) { + while ((rcline = dGetline_unsafe(In)) != NULL) { if (strncmp(rcline, "dpi_dir", 7) == 0) break; dFree(rcline); @@ -497,7 +497,7 @@ int fill_services_list(struct dp *attlist, int numdpis, Dlist **services_list) *services_list = dList_new(8); /* dpidrc parser loop */ - for (;(line = dGetline(dpidrc_stream)) != NULL; dFree(line)) { + for (;(line = dGetline_unsafe(dpidrc_stream)) != NULL; dFree(line)) { st = dParser_parse_rc_line(&line, &service, &path); if (st < 0) { MSG_ERR("dpid: Syntax error in %s: service=\"%s\" path=\"%s\"\n", diff --git a/dpid/dpidc.cc b/dpid/dpidc.cc index 9fcd606..3f61f17 100644 --- a/dpid/dpidc.cc +++ b/dpid/dpidc.cc @@ -55,7 +55,7 @@ static int Dpi_read_comm_keys(int *port) fname = dStrconcat(dGethomedir(), "/.flenser/dpid_comm_keys", NULL); if ((In = fopen(fname, "r")) == NULL) { MSG_ERR("[Dpi_read_comm_keys] %s\n", dStrerror(errno)); - } else if ((rcline = dGetline(In)) == NULL) { + } else if ((rcline = dGetline_unsafe(In)) == NULL) { MSG_ERR("[Dpi_read_comm_keys] empty file: %s\n", fname); } else { *port = strtol(rcline, &tail, 10); diff --git a/dpip/dpip.cc b/dpip/dpip.cc index b4cc1eb..efac64b 100644 --- a/dpip/dpip.cc +++ b/dpip/dpip.cc @@ -215,7 +215,7 @@ int a_Dpip_check_auth(const char *auth_tag) fname = dStrconcat(dGethomedir(), "/.flenser/dpid_comm_keys", NULL); if ((In = fopen(fname, "r")) == NULL) { MSG_ERR("[a_Dpip_check_auth] %s\n", dStrerror(errno)); - } else if ((rcline = dGetline(In)) == NULL) { + } else if ((rcline = dGetline_unsafe(In)) == NULL) { MSG_ERR("[a_Dpip_check_auth] empty file: %s\n", fname); } else { port = strtol(rcline, &tail, 10); diff --git a/src/IO/dpi.cc b/src/IO/dpi.cc index f904aed..06de526 100644 --- a/src/IO/dpi.cc +++ b/src/IO/dpi.cc @@ -400,7 +400,7 @@ static int Dpi_read_comm_keys(int *port) fname = dStrconcat(dGethomedir(), "/.flenser/dpid_comm_keys", NULL); if ((In = fopen(fname, "r")) == NULL) { MSG_ERR("[Dpi_read_comm_keys] %s\n", dStrerror(errno)); - } else if ((rcline = dGetline(In)) == NULL) { + } else if ((rcline = dGetline_unsafe(In)) == NULL) { MSG_ERR("[Dpi_read_comm_keys] empty file: %s\n", fname); } else { *port = strtol(rcline, &tail, 10); diff --git a/src/domain.cc b/src/domain.cc index 5787d67..c476b01 100644 --- a/src/domain.cc +++ b/src/domain.cc @@ -36,7 +36,7 @@ void a_Domain_parse(FILE *fp) _MSG("Reading domainrc...\n"); - while ((line = dGetline(fp)) != NULL) { + while ((line = dGetline_unsafe(fp)) != NULL) { ++lineno; /* Remove leading and trailing whitespace */ diff --git a/src/keys.cc b/src/keys.cc index 052535b..8b7e45f 100644 --- a/src/keys.cc +++ b/src/keys.cc @@ -406,7 +406,7 @@ void Keys::parse(FILE *fp) int st, lineno = 1; // scan the file line by line - while ((line = dGetline(fp)) != NULL) { + while ((line = dGetline_unsafe(fp)) != NULL) { st = dParser_parse_rc_line(&line, &keycomb, &command); if (st == 0) { diff --git a/src/prefsparser.cc b/src/prefsparser.cc index 6ba2fea..b02750e 100644 --- a/src/prefsparser.cc +++ b/src/prefsparser.cc @@ -256,7 +256,7 @@ void PrefsParser::parse(FILE *fp) setlocale(LC_NUMERIC, "C"); // scan the file line by line - while ((line = dGetline(fp)) != NULL) { + while ((line = dGetline_unsafe(fp)) != NULL) { st = dParser_parse_rc_line(&line, &name, &value); if (st == 0) {