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