wfopen.c 725 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * Utility routines.
  4. *
  5. * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
  6. *
  7. * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
  8. */
  9. #include "libbb.h"
  10. FILE* FAST_FUNC fopen_or_warn(const char *path, const char *mode)
  11. {
  12. FILE *fp = fopen(path, mode);
  13. if (!fp) {
  14. bb_simple_perror_msg(path);
  15. errno = 0;
  16. }
  17. return fp;
  18. }
  19. FILE* FAST_FUNC fopen_for_read(const char *path)
  20. {
  21. return fopen(path, "r");
  22. }
  23. FILE* FAST_FUNC xfopen_for_read(const char *path)
  24. {
  25. return xfopen(path, "r");
  26. }
  27. FILE* FAST_FUNC fopen_for_write(const char *path)
  28. {
  29. return fopen(path, "w");
  30. }
  31. FILE* FAST_FUNC xfopen_for_write(const char *path)
  32. {
  33. return xfopen(path, "w");
  34. }