summaryrefslogtreecommitdiff
path: root/mpeix
diff options
context:
space:
mode:
authorJarkko Hietaniemi <jhi@iki.fi>2003-07-29 20:09:15 +0000
committerJarkko Hietaniemi <jhi@iki.fi>2003-07-29 20:09:15 +0000
commitb606c5253377393d8487073ab479f363dd13f330 (patch)
tree31d3416ff7c80d040fd356da4fae1e8d678bb2ae /mpeix
parent8cfab5ff7c21540622402ad6821ff3565a6c7ff5 (diff)
downloadperl-b606c5253377393d8487073ab479f363dd13f330.tar.gz
MPE/iX fix from Mark Bixby: fcntl() on sockets on works.
p4raw-id: //depot/perl@20327
Diffstat (limited to 'mpeix')
-rw-r--r--mpeix/mpeix.c53
-rw-r--r--mpeix/mpeixish.h2
2 files changed, 55 insertions, 0 deletions
diff --git a/mpeix/mpeix.c b/mpeix/mpeix.c
index b230c50ac2..4805426a9e 100644
--- a/mpeix/mpeix.c
+++ b/mpeix/mpeix.c
@@ -451,3 +451,56 @@ struct timezone *tpz;
return 0;
} /* gettimeofday() */
+
+/*
+** MPE_FCNTL -- shadow function for fcntl()
+**
+** MPE requires sfcntl() for sockets, and fcntl() for everything
+** else. This shadow routine determines the descriptor type and
+** makes the appropriate call.
+**
+** Parameters:
+** same as fcntl().
+**
+** Returns:
+** same as fcntl().
+*/
+
+#include <stdarg.h>
+#include <sys/socket.h>
+
+int
+mpe_fcntl(int fildes, int cmd, ...)
+{
+ int len, result;
+ struct sockaddr sa;
+
+ void *arg;
+ va_list ap;
+
+ va_start(ap, cmd);
+ arg = va_arg(ap, void *);
+ va_end(ap);
+
+ len = sizeof sa;
+ if (getsockname(fildes, &sa, &len) == -1)
+ {
+ if (errno == EAFNOSUPPORT)
+ /* AF_UNIX socket */
+ return sfcntl(fildes, cmd, arg);
+
+ if (errno == ENOTSOCK)
+ /* file or pipe */
+ return fcntl(fildes, cmd, arg);
+
+ /* unknown getsockname() failure */
+ return (-1);
+ }
+ else
+ {
+ /* AF_INET socket */
+ if ((result = sfcntl(fildes, cmd, arg)) != -1 && cmd == F_GETFL)
+ result |= O_RDWR; /* fill in some missing flags */
+ return result;
+ }
+}
diff --git a/mpeix/mpeixish.h b/mpeix/mpeixish.h
index 8fc055a9a1..658e72ef87 100644
--- a/mpeix/mpeixish.h
+++ b/mpeix/mpeixish.h
@@ -153,3 +153,5 @@ extern void srand48(long int seedval);
extern int ftruncate(int fd, long wantsize);
extern int gettimeofday( struct timeval *tp, struct timezone *tpz );
extern int truncate(const char *pathname, off_t length);
+
+#define fcntl mpe_fcntl