home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / unix / volume26 / mcast / part01 / libmcast / mc_read.c < prev    next >
C/C++ Source or Header  |  1993-04-06  |  3KB  |  84 lines

  1. /*
  2.  * $Header: /u0/casey/src/mcast/libmcast/RCS/mc_read.c,v 1.1 92/10/16 18:22:47 casey Exp $
  3.  */
  4.  
  5. /*
  6.  * Copyright (c) 1992 The Regents of the University of California.
  7.  * All rights reserved.
  8.  *
  9.  * Redistribution and use in source and binary forms, with or without
  10.  * modification, are permitted provided that the following conditions
  11.  * are met:
  12.  * 1. Redistributions of source code must retain the above copyright
  13.  *    notice, this list of conditions and the following disclaimer.
  14.  * 2. Redistributions in binary form must reproduce the above copyright
  15.  *    notice, this list of conditions and the following disclaimer in the
  16.  *    documentation and/or other materials provided with the distribution.
  17.  * 3. All advertising materials mentioning features or use of this software
  18.  *    must display the following acknowledgement:
  19.  *    This product includes software developed by the University of
  20.  *    California, Lawrence Livermore National Laboratory and its
  21.  *    contributors.
  22.  * 4. Neither the name of the University nor the names of its contributors
  23.  *    may be used to endorse or promote products derived from this software
  24.  *    without specific prior written permission.
  25.  *
  26.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  27.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  28.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  29.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  30.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  31.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  32.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  33.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  34.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  35.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  36.  * SUCH DAMAGE.
  37.  */
  38.  
  39. #ifndef lint
  40. static char rcsid[] = "$Header: /u0/casey/src/mcast/libmcast/RCS/mc_read.c,v 1.1 92/10/16 18:22:47 casey Exp $";
  41. static char copyright[] =
  42.     "Copyright (c) 1992 The Regents of the University of California.\n"
  43.     "All rights reserved.\n";
  44. static char classification[] =
  45.     "Unclassified\n";
  46. #endif
  47.  
  48.  
  49. /*
  50.  * MCAST SYSLIB PUBLIC: mc_read: read(2) system call emulation routine.
  51.  */
  52.  
  53.  
  54. #include "mc_lib.h"
  55.  
  56.  
  57. int
  58. mc_read(int s, void *buf, size_t len)
  59. {
  60.     mc_state *sp = &_mc_state[s];
  61.  
  62.     if (s < 0 || s >= MC_MAX_CONNECTIONS
  63.         || !(sp->state & MC_VALID)) {
  64.         /* return(read(s, buf, len)); */
  65.         errno = EBADF;
  66.         return(-1);
  67.     }
  68.     if (sp->state & MC_CORRUPTED) {
  69.         errno = EIO;
  70.         return(-1);
  71.     }
  72.     if ((int)len <= 0) {
  73.         errno = EINVAL;
  74.         return(-1);
  75.     }
  76.     if (!(sp->state & MC_BOUND)) {
  77.         errno = EPIPE;
  78.         return(-1);
  79.     }
  80.     if (sp->state & MC_SHUTDOWNRECV)
  81.         return(0);
  82.     return(_mc_read(s, buf, len, 0, NULL));
  83. }
  84.