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.
* 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;
}
/**

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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",

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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 */

View File

@ -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) {

View File

@ -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) {