Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22016

perror() give seg. fault

$
0
0

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, 128no error. Can someone explain this behavior?


Viewing all articles
Browse latest Browse all 22016

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>