fake_getline.c - randomcrap - random crap programs of varying quality
 (HTM) git clone git://git.codemadness.org/randomcrap
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
       fake_getline.c (457B)
       ---
            1 /* wrapper function to fake read errors and spoof an error in ferror() */
            2 
            3 #include <errno.h>
            4 #include <stdio.h>
            5 
            6 static size_t getline_ncounter = 0;
            7 
            8 ssize_t
            9 fake_getline(char **lineptr, size_t *n, FILE *stream)
           10 {
           11         /* fail after N lines are read */
           12         if (getline_ncounter++ >= 10) {
           13                 errno = ENOMEM;
           14                 stream->_flags |= __SERR; /* hack: set ferror, works on OpenBSD */
           15                 return -1;
           16         }
           17 
           18         return getline(lineptr, n, stream);
           19 }
           20 
           21 int
           22 main(void)
           23 {
           24         return 0;
           25 }