orangeduck / BuildYourOwnLisp

Learn C and build your own programming language in under 1000 lines of code!
http://www.buildyourownlisp.com/
Other
2.84k stars 392 forks source link

Chapter 4: Cleanup _WIN32 readline() dummy function. #149

Closed peanutbutterandcrackers closed 3 years ago

peanutbutterandcrackers commented 3 years ago
  1. Allocate only stlen(buffer)-bytes for char* cpy.
  2. Remove un-needed addition of '\0' to char* cpy.

Reasons (based on the GNU/Linux man pages):

  1. fgets "reads in at most one less than size characters from stream"
  2. fgets stores a "... terminating null byte ('\0') ... after the last character in the buffer" and strcpy "copies the string ... includ- ing the terminating null byte ('\0')"
peanutbutterandcrackers commented 3 years ago

Sorry, I messed up a bit. Closing this and submitting a new one.