full-read.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /* full-read.c -- an interface to read that retries after interrupts
  2. Copyright (C) 1993, 1994, 1997, 1999 Free Software Foundation, Inc.
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 2, or (at your option)
  6. any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software Foundation,
  13. Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  14. */
  15. #if HAVE_CONFIG_H
  16. # include <config.h>
  17. #endif
  18. #include <sys/types.h>
  19. #if HAVE_UNISTD_H
  20. # include <unistd.h>
  21. #endif
  22. #include <errno.h>
  23. #ifndef errno
  24. extern int errno;
  25. #endif
  26. /* Read LEN bytes at PTR from descriptor DESC, retrying if interrupted.
  27. Return the actual number of bytes read, zero for EOF, or negative
  28. for an error. */
  29. ssize_t
  30. full_read (int desc, char *ptr, size_t len)
  31. {
  32. for (;;)
  33. {
  34. ssize_t n = read (desc, ptr, len);
  35. #ifdef EINTR
  36. if (n < 0 && errno == EINTR)
  37. continue;
  38. #endif
  39. return n;
  40. }
  41. }