home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 3 / TheARMClub_PDCD3.iso / hensa / unix / unixlib_1 / !UnixLib37_netlib_netlib_c_socket < prev    next >
Encoding:
Text File  |  1996-10-31  |  887 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. socket (int af, int type, int protocol)
  24. {
  25.   register struct file *f;
  26.   int fd;
  27.   int sd;
  28.  
  29.   if ((sd = _socket (af, type, protocol)) < 0)
  30.     return (-1);
  31.  
  32.   if ((fd = __fdalloc ()) < 0)
  33.     return (-1);
  34.  
  35. /* printf("U! socket: sd=%d fd=%d\n",sd,fd); */
  36.  
  37.   f = __u->file + fd;
  38.   f->oflag = O_RDWR | O_BINARY;
  39.   f->r[0] = sd;
  40.   f->r[1] = af;
  41.   f->r[2] = type;
  42.   f->r[3] = protocol;
  43.  
  44.   f->dev = makedev (DEV_SOCKET, sd);
  45.  
  46.   f->dup = f;
  47.   f->pid = __u->pid;
  48.  
  49.   return (fd);
  50. }
  51.