wrapstdio.c 703 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*
  2. * Standard I/O wrapper functions.
  3. */
  4. #include "unp.h"
  5. void
  6. Fclose(FILE *fp)
  7. {
  8. if (fclose(fp) != 0)
  9. err_sys("fclose error");
  10. }
  11. FILE *
  12. Fdopen(int fd, const char *type)
  13. {
  14. FILE *fp;
  15. if ( (fp = fdopen(fd, type)) == NULL)
  16. err_sys("fdopen error");
  17. return(fp);
  18. }
  19. char *
  20. Fgets(char *ptr, int n, FILE *stream)
  21. {
  22. char *rptr;
  23. if ( (rptr = fgets(ptr, n, stream)) == NULL && ferror(stream))
  24. err_sys("fgets error");
  25. return (rptr);
  26. }
  27. FILE *
  28. Fopen(const char *filename, const char *mode)
  29. {
  30. FILE *fp;
  31. if ( (fp = fopen(filename, mode)) == NULL)
  32. err_sys("fopen error");
  33. return(fp);
  34. }
  35. void
  36. Fputs(const char *ptr, FILE *stream)
  37. {
  38. if (fputs(ptr, stream) == EOF)
  39. err_sys("fputs error");
  40. }