home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 3 / TheARMClub_PDCD3.iso / hensa / unix / unixlib_1 / !UnixLib37_netlib_netlib_c_accept < prev    next >
Encoding:
Text File  |  1996-10-31  |  963 b   |  51 lines

  1. /****************************************************************************
  2.  *
  3.  * $Source$
  4.  * $Date$
  5.  * $Revision$
  6.  * $State$
  7.  * $Author$
  8.  *
  9.  * $Log$
  10.  * (c) Copyright 1995 Sergio Monesi
  11.  ***************************************************************************/
  12.  
  13. static const char rcs_id[] = "$Id$";
  14.  
  15. #include <errno.h>
  16.  
  17. #include <sys/unix.h>
  18. #include <sys/socket.h>
  19. #include <sys/dev.h>
  20. #include <fcntl.h>
  21.  
  22. int
  23. accept (int s, struct sockaddr *name, int *namelen)
  24. {
  25.   register struct file *f;
  26.   int nfd;
  27.   int nsd;
  28.  
  29. /* printf("U! accept: fd=%d, realsocket=%d\n",s,(__u->file+s)->r[0]); */
  30.  
  31.   if ((nsd = _accept ((__u->file + s)->r[0], name, namelen)) < 0)
  32.     return (-1);
  33.  
  34.   if ((nfd = __fdalloc ()) < 0)
  35.     return (-1);
  36.  
  37. /* printf("U! accept: nsd=%d nfd=%d\n",nsd,nfd); */
  38.  
  39.   f = __u->file + nfd;
  40.   f->oflag = O_RDWR | O_BINARY;
  41.   f->r[0] = nsd;
  42.   f->r[1] = -1;
  43.  
  44.   f->dev = makedev (DEV_SOCKET, nsd);
  45.  
  46.   f->dup = f;
  47.   f->pid = __u->pid;
  48.  
  49.   return (nfd);
  50. }
  51.