diff -ur links-2.1pre33.orig/os_dep.c links-2.1pre33/os_dep.c --- links-2.1pre33.orig/os_dep.c 2007-12-28 09:40:31.000000000 +0300 +++ links-2.1pre33/os_dep.c 2008-04-24 23:41:27.000000000 +0400 @@ -324,16 +334,91 @@ return pipe(fd); } -#elif defined(OS2) || defined(WIN32) +#elif defined(OS2) || defined(WIN32) || defined(DJGPP) void set_bin(int fd) { setmode(fd, O_BINARY); } +#if defined(DJGPP) + +/* A stripped down socketpair(2) implementation */ +int socketpipe (int *fd) +{ + int insock, outsock, newsock; + struct sockaddr_in sock_in, sock_out; + socklen_t len; + + newsock = socket (AF_INET, SOCK_STREAM, 0); + if (newsock == -1) + return -1; + + /* Bind the socket to any unused port */ + sock_in.sin_family = AF_INET; + sock_in.sin_port = 0; + sock_in.sin_addr.s_addr = INADDR_ANY; + if (bind (newsock, (struct sockaddr *) &sock_in, sizeof (sock_in)) < 0) { + close (newsock); + return -1; + } + + len = sizeof (sock_in); + + if (getsockname (newsock, (struct sockaddr *) &sock_in, &len) < 0) { + close (newsock); + return -1; + } + + /* For stream sockets, create a listener */ + listen (newsock, 2); + + /* Create a connecting socket */ + outsock = socket (AF_INET, SOCK_STREAM, 0); + if (outsock == -1) { + close (newsock); + return -1; + } + + sock_in.sin_addr.s_addr = htonl (INADDR_LOOPBACK); + + /* Do a connect */ + if (connect (outsock, (struct sockaddr *) &sock_in, sizeof (sock_in)) < 0) { + close (newsock); + close (outsock); + return -1; + } + + /* For stream sockets, accept the connection and close the listener */ + len = sizeof (sock_in); + insock = accept (newsock, (struct sockaddr *) &sock_in, &len); + if (insock == -1) { + close (newsock); + close (outsock); + return -1; + } + close (newsock); + + if (insock > 0 && outsock > 0) { + fd[0] = insock; + fd[1] = outsock; + return 0; + } + + close (insock); + close (outsock); + return -1; +} + +#endif /* DJGPP */ + int c_pipe(int *fd) { +#if defined(DJGPP) + int r = socketpipe(fd); +#else int r = pipe(fd); +#endif if (!r) set_bin(fd[0]), set_bin(fd[1]); return r; }