After an error occurs, I call perror()
, naturally. But I'm getting a segmentation fault when I do this or printf("error: %s\n", strerror(errno));
I have no idea what is happing.
int fd;
if((fd = open(FILENAME, O_RDONLY)) == -1) {
perror("fbi");
exit(1);
}
for(;;) {
readed = read(fd, buffer, BUFSIZE);
if(readed == 0)
break;
if(readed == -1) {
perror("fbi"); // <- here's the error
exit(1);
}
How to fix this?
Update:
printf("%d\n", errno); // given 9
UPDATE2:
Looks like there is a relation with the buffer size passed in the recv()
function. if BUFSIZE
is 1
, give the above error. But if BUFSIZE
is e.g, 128
no error. Can someone explain this behavior?