fgetln.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*-
  2. * Copyright (c) 2007, 2009
  3. * Thorsten Glaser <tg@mirbsd.org>
  4. *
  5. * Provided that these terms and disclaimer and all copyright notices
  6. * are retained or reproduced in an accompanying document, permission
  7. * is granted to deal in this work without restriction, including un-
  8. * limited rights to use, publicly perform, distribute, sell, modify,
  9. * merge, give away, or sublicence.
  10. *
  11. * This work is provided "AS IS" and WITHOUT WARRANTY of any kind, to
  12. * the utmost extent permitted by applicable law, neither express nor
  13. * implied; without malicious intent or gross negligence. In no event
  14. * may a licensor, author or contributor be held liable for indirect,
  15. * direct, other damage, loss, or other issues arising in any way out
  16. * of dealing in the work, even if advised of the possibility of such
  17. * damage or existence of a defect, except proven that it results out
  18. * of said person's immediate fault when using the work as intended.
  19. *-
  20. * fgetln() wrapper for operating systems with getline() – glibc
  21. */
  22. #undef _GNU_SOURCE
  23. #define _GNU_SOURCE /* for getline() */
  24. #include <sys/types.h>
  25. #include <stdio.h>
  26. #include <string.h>
  27. __RCSID("$MirOS: contrib/code/mirmake/dist/contrib/fgetln.c,v 1.7 2014/12/20 22:23:29 tg Exp $");
  28. char *fgetln(FILE *, size_t *);
  29. char *
  30. fgetln(FILE *stream, size_t *len)
  31. {
  32. static char *lb = NULL;
  33. static size_t lbsz = 0;
  34. if ((*len = getline(&lb, &lbsz, stream)) != (size_t)-1)
  35. /* getdelim ensures *len is not 0 here */
  36. return (lb);
  37. /* not required by manpage, but reference implementation does this */
  38. *len = 0;
  39. /* not required to zero lb or lbsz: getdelim manages it */
  40. return (NULL);
  41. }