diff --git a/doc/src/Developer_utils.rst b/doc/src/Developer_utils.rst index 68c89448cc..499df45bd6 100644 --- a/doc/src/Developer_utils.rst +++ b/doc/src/Developer_utils.rst @@ -19,7 +19,7 @@ In that case, the functions will stop with an error message, indicating the name of the problematic file, if possible unless the *error* argument is a NULL pointer. -The :cpp:func:`fgets_trunc_nl` function will work similar for ``fgets()`` +The :cpp:func:`fgets_trunc` function will work similar for ``fgets()`` but it will read in a whole line (i.e. until the end of line or end of file), but store only as many characters as will fit into the buffer including a final newline character and the terminating NULL byte. @@ -41,7 +41,7 @@ NULL character. .. doxygenfunction:: sfread :project: progguide -.. doxygenfunction:: fgets_trunc_nl +.. doxygenfunction:: fgets_trunc :project: progguide .. doxygenfunction:: read_lines_from_file diff --git a/src/read_data.cpp b/src/read_data.cpp index 4af87a4383..5d0fe5f5c6 100644 --- a/src/read_data.cpp +++ b/src/read_data.cpp @@ -958,7 +958,7 @@ void ReadData::header(int firstpass) // skip 1st line of file if (me == 0) { - char *eof = utils::fgets_trunc_nl(line,MAXLINE,fp); + char *eof = utils::fgets_trunc(line,MAXLINE,fp); if (eof == nullptr) error->one(FLERR,"Unexpected end of data file"); } @@ -967,7 +967,7 @@ void ReadData::header(int firstpass) // read a line and bcast length if (me == 0) { - if (utils::fgets_trunc_nl(line,MAXLINE,fp) == nullptr) n = 0; + if (utils::fgets_trunc(line,MAXLINE,fp) == nullptr) n = 0; else n = strlen(line) + 1; } MPI_Bcast(&n,1,MPI_INT,0,world); @@ -1670,7 +1670,7 @@ void ReadData::bodies(int firstpass, AtomVec *ptr) m = 0; while (nchunk < nmax && nline <= CHUNK-MAXBODY) { - eof = utils::fgets_trunc_nl(&buffer[m],MAXLINE,fp); + eof = utils::fgets_trunc(&buffer[m],MAXLINE,fp); if (eof == nullptr) error->one(FLERR,"Unexpected end of data file"); rv = sscanf(&buffer[m],"%d %d %d",&tmp,&ninteger,&ndouble); if (rv != 3) @@ -1684,7 +1684,7 @@ void ReadData::bodies(int firstpass, AtomVec *ptr) nword = 0; while (nword < ninteger) { - eof = utils::fgets_trunc_nl(&buffer[m],MAXLINE,fp); + eof = utils::fgets_trunc(&buffer[m],MAXLINE,fp); if (eof == nullptr) error->one(FLERR,"Unexpected end of data file"); ncount = utils::trim_and_count_words(&buffer[m]); if (ncount == 0) @@ -1698,7 +1698,7 @@ void ReadData::bodies(int firstpass, AtomVec *ptr) nword = 0; while (nword < ndouble) { - eof = utils::fgets_trunc_nl(&buffer[m],MAXLINE,fp); + eof = utils::fgets_trunc(&buffer[m],MAXLINE,fp); if (eof == nullptr) error->one(FLERR,"Unexpected end of data file"); ncount = utils::trim_and_count_words(&buffer[m]); if (ncount == 0) @@ -2002,15 +2002,15 @@ void ReadData::parse_keyword(int first) if (me == 0) { if (!first) { - if (utils::fgets_trunc_nl(line,MAXLINE,fp) == nullptr) eof = 1; + if (utils::fgets_trunc(line,MAXLINE,fp) == nullptr) eof = 1; } while (eof == 0 && done == 0) { int blank = strspn(line," \t\n\r"); if ((blank == (int)strlen(line)) || (line[blank] == '#')) { - if (utils::fgets_trunc_nl(line,MAXLINE,fp) == nullptr) eof = 1; + if (utils::fgets_trunc(line,MAXLINE,fp) == nullptr) eof = 1; } else done = 1; } - if (utils::fgets_trunc_nl(buffer,MAXLINE,fp) == nullptr) { + if (utils::fgets_trunc(buffer,MAXLINE,fp) == nullptr) { eof = 1; buffer[0] = '\0'; } @@ -2064,7 +2064,7 @@ void ReadData::skip_lines(bigint n) if (me) return; if (n <= 0) return; char *eof = nullptr; - for (bigint i = 0; i < n; i++) eof = utils::fgets_trunc_nl(line,MAXLINE,fp); + for (bigint i = 0; i < n; i++) eof = utils::fgets_trunc(line,MAXLINE,fp); if (eof == nullptr) error->one(FLERR,"Unexpected end of data file"); } diff --git a/src/utils.cpp b/src/utils.cpp index fe5904dc38..fbd00d1494 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -168,7 +168,7 @@ const char *utils::guesspath(char *buf, int len, FILE *fp) // read line into buffer. if line is too long keep reading until EOL or EOF // but return only the first part with a newline at the end. -char *utils::fgets_trunc_nl(char *buf, int size, FILE *fp) +char *utils::fgets_trunc(char *buf, int size, FILE *fp) { constexpr int MAXDUMMY = 256; char dummy[MAXDUMMY]; @@ -271,7 +271,7 @@ int utils::read_lines_from_file(FILE *fp, int nlines, int nmax, if (me == 0) { if (fp) { for (int i = 0; i < nlines; i++) { - ptr = fgets_trunc_nl(ptr,nmax,fp); + ptr = fgets_trunc(ptr,nmax,fp); if (!ptr) break; // EOF? // advance ptr to end of string ptr += strlen(ptr); diff --git a/src/utils.h b/src/utils.h index 752d1c06d0..d0a41fafb8 100644 --- a/src/utils.h +++ b/src/utils.h @@ -75,7 +75,7 @@ namespace LAMMPS_NS { * \param size size of buffer s (max number of bytes returned) * \param fp file pointer used by fgets() */ - char *fgets_trunc_nl(char *s, int size, FILE *fp); + char *fgets_trunc(char *s, int size, FILE *fp); /** Safe wrapper around fgets() which aborts on errors * or EOF and prints a suitable error message to help debugging.