Rename getline function to unsafe, to make it greppable.

Now i can trim them one-by-one.
This commit is contained in:
2025-08-23 02:20:05 -04:00
parent f283391b46
commit 412adaa492
11 changed files with 27 additions and 26 deletions

View File

@ -942,7 +942,7 @@ char *dGethomedir (void)
* Get a line from a FILE stream. * Get a line from a FILE stream.
* Return value: read line on success, NULL on EOF. * Return value: read line on success, NULL on EOF.
*/ */
char *dGetline (FILE *stream) char *dGetline_unsafe (FILE *stream)
{ {
int ch; int ch;
Dstr *dstr; Dstr *dstr;
@ -963,23 +963,23 @@ char *dGetline (FILE *stream)
} }
std::optional< std::string > std::optional< std::string >
dGetline_string (FILE *stream) dGetline( FILE *const stream )
{ {
std::string rv;
int ch; int ch;
Dstr *dstr;
if( stream == nullptr ) return std::nullopt; if( stream == nullptr ) return std::nullopt;
dstr = dStr_sized_new(64); while( ( ch= fgetc( stream ) ) != EOF )
while ((ch = fgetc(stream)) != EOF) { {
dStr_append_c(dstr, ch); rv+= ch;
if (ch == '\n') if (ch == '\n')
break; break;
} }
std::optional< std::string > line; std::optional< std::string > line;
if(dstr->len) line= dstr->str; if(rv.size()) line= std::move( rv );
dStr_free(dstr, 1);
return line; return line;
} }

View File

@ -186,7 +186,8 @@ void dLib_show_messages(bool show);
char *dGetcwd(void); char *dGetcwd(void);
char *dGethomedir(void); char *dGethomedir(void);
std::optional< std::string > dGetline_string(FILE *stream); 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 dClose(int fd);
int dUsleep(unsigned long us); int dUsleep(unsigned long us);

View File

@ -628,7 +628,7 @@ static int Bms_load(void)
} }
/* load bm file into memory */ /* load bm file into memory */
while ((buf = dGetline(BmTxt)) != NULL) { while ((buf = dGetline_unsafe(BmTxt)) != NULL) {
if (buf[0] == 's') { if (buf[0] == 's') {
/* get section, url and title */ /* get section, url and title */
section = strtol(buf + 1, NULL, 10); section = strtol(buf + 1, NULL, 10);

View File

@ -64,7 +64,7 @@ char *a_Dpi_rd_dpi_socket_dir(char *dirname)
dFree(rcpath); dFree(rcpath);
if ((dir = fopen(dirname, "r")) != NULL) { if ((dir = fopen(dirname, "r")) != NULL) {
sockdir = dGetline(dir); sockdir = dGetline_unsafe(dir);
fclose(dir); fclose(dir);
} else if (errno == ENOENT) { } else if (errno == ENOENT) {
ERRMSG("a_Dpi_rd_dpi_socket_dir", "fopen", errno); ERRMSG("a_Dpi_rd_dpi_socket_dir", "fopen", errno);

View File

@ -189,7 +189,7 @@ char *get_dpi_dir(char *dpidrc)
return (NULL); return (NULL);
} }
while ((rcline = dGetline(In)) != NULL) { while ((rcline = dGetline_unsafe(In)) != NULL) {
if (strncmp(rcline, "dpi_dir", 7) == 0) if (strncmp(rcline, "dpi_dir", 7) == 0)
break; break;
dFree(rcline); dFree(rcline);
@ -497,7 +497,7 @@ int fill_services_list(struct dp *attlist, int numdpis, Dlist **services_list)
*services_list = dList_new(8); *services_list = dList_new(8);
/* dpidrc parser loop */ /* 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); st = dParser_parse_rc_line(&line, &service, &path);
if (st < 0) { if (st < 0) {
MSG_ERR("dpid: Syntax error in %s: service=\"%s\" path=\"%s\"\n", MSG_ERR("dpid: Syntax error in %s: service=\"%s\" path=\"%s\"\n",

View File

@ -55,7 +55,7 @@ static int Dpi_read_comm_keys(int *port)
fname = dStrconcat(dGethomedir(), "/.flenser/dpid_comm_keys", NULL); fname = dStrconcat(dGethomedir(), "/.flenser/dpid_comm_keys", NULL);
if ((In = fopen(fname, "r")) == NULL) { if ((In = fopen(fname, "r")) == NULL) {
MSG_ERR("[Dpi_read_comm_keys] %s\n", dStrerror(errno)); 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); MSG_ERR("[Dpi_read_comm_keys] empty file: %s\n", fname);
} else { } else {
*port = strtol(rcline, &tail, 10); *port = strtol(rcline, &tail, 10);

View File

@ -215,7 +215,7 @@ int a_Dpip_check_auth(const char *auth_tag)
fname = dStrconcat(dGethomedir(), "/.flenser/dpid_comm_keys", NULL); fname = dStrconcat(dGethomedir(), "/.flenser/dpid_comm_keys", NULL);
if ((In = fopen(fname, "r")) == NULL) { if ((In = fopen(fname, "r")) == NULL) {
MSG_ERR("[a_Dpip_check_auth] %s\n", dStrerror(errno)); 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); MSG_ERR("[a_Dpip_check_auth] empty file: %s\n", fname);
} else { } else {
port = strtol(rcline, &tail, 10); port = strtol(rcline, &tail, 10);

View File

@ -400,7 +400,7 @@ static int Dpi_read_comm_keys(int *port)
fname = dStrconcat(dGethomedir(), "/.flenser/dpid_comm_keys", NULL); fname = dStrconcat(dGethomedir(), "/.flenser/dpid_comm_keys", NULL);
if ((In = fopen(fname, "r")) == NULL) { if ((In = fopen(fname, "r")) == NULL) {
MSG_ERR("[Dpi_read_comm_keys] %s\n", dStrerror(errno)); 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); MSG_ERR("[Dpi_read_comm_keys] empty file: %s\n", fname);
} else { } else {
*port = strtol(rcline, &tail, 10); *port = strtol(rcline, &tail, 10);

View File

@ -36,7 +36,7 @@ void a_Domain_parse(FILE *fp)
_MSG("Reading domainrc...\n"); _MSG("Reading domainrc...\n");
while ((line = dGetline(fp)) != NULL) { while ((line = dGetline_unsafe(fp)) != NULL) {
++lineno; ++lineno;
/* Remove leading and trailing whitespace */ /* Remove leading and trailing whitespace */

View File

@ -406,7 +406,7 @@ void Keys::parse(FILE *fp)
int st, lineno = 1; int st, lineno = 1;
// scan the file line by line // 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); st = dParser_parse_rc_line(&line, &keycomb, &command);
if (st == 0) { if (st == 0) {

View File

@ -256,7 +256,7 @@ void PrefsParser::parse(FILE *fp)
setlocale(LC_NUMERIC, "C"); setlocale(LC_NUMERIC, "C");
// scan the file line by line // 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); st = dParser_parse_rc_line(&line, &name, &value);
if (st == 0) { if (st == 0) {