Skip to main content

Timeline for Showing the contents of a file

Current License: CC BY-SA 3.0

15 events
when toggle format what by license comment
Jun 1, 2015 at 11:45 vote accept Koray Tugay
Jun 1, 2015 at 11:43 comment added Koray Tugay Somewhere I read that read must be called once before entering a loop. I can not remember where and why :)
May 31, 2015 at 21:59 history edited janos CC BY-SA 3.0
added 117 characters in body
May 31, 2015 at 21:36 comment added chqrlie Another gotcha: if MAX_FILENAME_LENGTH is the maximum length for a filename, the buffer size should be MAX_FILENAME_LENGTH+1. The standard macro FILENAME_MAX is meant to be used as a buffer size.
May 31, 2015 at 20:56 comment added chqrlie The OP uses the low level system call interface instead of the standard library stream functions from <stdio.h>. This is not a good idea in general. The call ` write(1, buf, numBytesRead);` for instance may return a number less than numBytesRead if writing to a device or a pipe, or if it was interrupted by a signal. The programmer needs to handle these conditions. It is much simpler and not necessarily less efficient to use higher level functions.
May 31, 2015 at 19:49 comment added janos Thanks @chqrlie, that's the kind of reasoning I was looking for. I updated my post.
May 31, 2015 at 19:49 history edited janos CC BY-SA 3.0
added 216 characters in body
May 31, 2015 at 19:35 comment added chqrlie This construct is error prone because of the combined assignment/test. I recommend writing: while((numBytesRead = read(fd, buf, bufsize)) > 0). gcc -Wall -W -Werror does not let me compile your code, and also finds more subtle problems and bugs.
May 31, 2015 at 18:45 comment added chqrlie Do not encourage error prone constructs such as while(numBytesRead = read(fd, buf, bufsize))
May 30, 2015 at 19:31 comment added user3629249 Thanks for the suggestion to not repeat the read() of the file statement. I had not placed that in my answer, as I did not want to make suggestions that might confuse the OP.
May 30, 2015 at 19:17 history edited janos CC BY-SA 3.0
added 140 characters in body
May 30, 2015 at 19:11 history edited janos CC BY-SA 3.0
added 140 characters in body
May 30, 2015 at 19:02 history edited janos CC BY-SA 3.0
deleted 312 characters in body
May 30, 2015 at 18:57 history edited janos CC BY-SA 3.0
deleted 312 characters in body
May 30, 2015 at 18:51 history answered janos CC BY-SA 3.0