diff options
author | Jarkko Hietaniemi <jhi@iki.fi> | 2003-07-29 20:09:15 +0000 |
---|---|---|
committer | Jarkko Hietaniemi <jhi@iki.fi> | 2003-07-29 20:09:15 +0000 |
commit | b606c5253377393d8487073ab479f363dd13f330 (patch) | |
tree | 31d3416ff7c80d040fd356da4fae1e8d678bb2ae /mpeix/mpeix.c | |
parent | 8cfab5ff7c21540622402ad6821ff3565a6c7ff5 (diff) | |
download | perl-b606c5253377393d8487073ab479f363dd13f330.tar.gz |
MPE/iX fix from Mark Bixby: fcntl() on sockets on works.
p4raw-id: //depot/perl@20327
Diffstat (limited to 'mpeix/mpeix.c')
-rw-r--r-- | mpeix/mpeix.c | 53 |
1 files changed, 53 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; + } +} |