home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / gnu / glibc-1.06 / sysdeps / mach / hurd / __read.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-02-22  |  2.1 KB  |  76 lines

  1. /* Copyright (C) 1993 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3.  
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Library General Public License as
  6. published by the Free Software Foundation; either version 2 of the
  7. License, or (at your option) any later version.
  8.  
  9. The GNU C Library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  12. Library General Public License for more details.
  13.  
  14. You should have received a copy of the GNU Library General Public
  15. License along with the GNU C Library; see the file COPYING.LIB.  If
  16. not, write to the Free Software Foundation, Inc., 675 Mass Ave,
  17. Cambridge, MA 02139, USA.  */
  18.  
  19. #include <ansidecl.h>
  20. #include <errno.h>
  21. #include <unistd.h>
  22. #include <hurd.h>
  23.  
  24. /* Read NBYTES into BUF from FD.  Return the number read or -1.  */
  25. ssize_t
  26. DEFUN(__read, (fd, buf, nbytes),
  27.       int fd AND PTR buf AND size_t nbytes)
  28. {
  29.   error_t err;
  30.   char *data;
  31.   size_t nread;
  32.  
  33.   data = buf;
  34.   _HURD_DPORT_USE
  35.     (fd,
  36.      ({
  37.      call:
  38.        err = __io_read (port, &data, &nread, -1, nbytes);
  39.        if (ctty != MACH_PORT_NULL && err == EBACKGROUND)
  40.      {
  41.        struct _hurd_sigstate *ss
  42.          = _hurd_thread_sigstate (__mach_thread_self ());
  43.        if (_hurd_orphaned ||
  44.            __sigismember (SIGTTIN, &ss->blocked) ||
  45.            ss->actions[SIGTTIN].sa_handler == SIG_IGN)
  46.          {
  47.            /* We are orphaned, or are blocking or ignoring SIGTTIN.
  48.           Return EOF instead of stopping.  */
  49.            __mutex_unlock (&ss->lock);
  50.            nread = 0;
  51.            err = 0;
  52.          }
  53.        else
  54.          {
  55.            const int restart = ss->actions[SIGTTIN].sa_flags & SA_RESTART;
  56.            _hurd_raise_signal (ss, SIGTTIN, 0); /* Unlocks SS->lock.  */
  57.            if (restart)
  58.          goto call;
  59.            else
  60.          err = EINTR;    /* XXX Is this right? */
  61.          }
  62.      }
  63.      }));
  64.  
  65.   if (err)
  66.     return __hurd_dfail (fd, err);
  67.  
  68.   if (data != buf)
  69.     {
  70.       memcpy (buf, data, nread);
  71.       __vm_deallocate (__mach_task_self (), data, nread);
  72.     }
  73.  
  74.   return nread;
  75. }
  76.