| 1 | #include "EXTERN.h" | ||
| 2 | #include "perl.h" | ||
| 3 | #include "XSUB.h" | ||
| 4 | |||
| 5 | #include "ppport.h" | ||
| 6 | |||
| 7 | #include <stdio.h> | ||
| 8 | |||
| 9 | MODULE = File::fgets PACKAGE = File::fgets | ||
| 10 | |||
| 11 | SV* | ||
| 12 | xs_fgets(fh, limit) | ||
| 13 | FILE* fh | ||
| 14 | int limit | ||
| 15 | CODE: | ||
| 16 | 128 | limit++; /* C's fgets gets length - 1 */ | |
| 17 | |||
| 18 | 128 | SV* buffer = newSV(limit); | |
| 19 | 128 | SvPOK_on(buffer); | |
| 20 | |||
| 21 | 128 | char *string = SvPVX(buffer); | |
| 22 | 128 | char *ret = fgets(string, limit, fh); | |
| 23 | 128 | SvCUR_set(buffer, strlen(string)); | |
| 24 | 128 | RETVAL = buffer; | |
| 25 | OUTPUT: | ||
| 26 | RETVAL |