*/
#include <sys/types.h>
#include <sys/stat.h>
+#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
+#endif /* ndef HAVE_SYS_TIME_H */
#ifdef HAVE_SYS_POLL_H
#include <sys/poll.h>
#endif /* ndef HAVE_SYS_POLL_H */
#ifdef HAVE_SYS_MMAN_H
#include <sys/mman.h>
#endif /* ndef HAVE_SYS_MMAN_H */
+#ifdef HAVE_UNISTD_H
#include <unistd.h>
+#endif /* ndef HAVE_UNISTD_H */
#include <fcntl.h>
#include <signal.h>
#ifdef HAVE_POLL_H
#ifdef HAVE_SYSLOG_H
#include <syslog.h>
#endif /* ndef HAVE_SYSLOG_H */
+#ifdef HAVE_DIRENT_H
#include <dirent.h>
+#endif /* ndef HAVE_DIRENT_H */
+#ifdef HAVE_UTIME_H
#include <utime.h>
+#endif /* ndef HAVE_UTIME_H */
+#include <time.h>
#include "mph.h"
#include "map.h"
return 0;
}
+int Mono_Posix_FromEpollEvents (unsigned int x, unsigned int *r)
+{
+ *r = 0;
+ if ((x & Mono_Posix_EpollEvents_EPOLLERR) == Mono_Posix_EpollEvents_EPOLLERR)
+#ifdef EPOLLERR
+ *r |= EPOLLERR;
+#else /* def EPOLLERR */
+ {errno = EINVAL; return -1;}
+#endif /* ndef EPOLLERR */
+ if ((x & Mono_Posix_EpollEvents_EPOLLET) == Mono_Posix_EpollEvents_EPOLLET)
+#ifdef EPOLLET
+ *r |= EPOLLET;
+#else /* def EPOLLET */
+ {errno = EINVAL; return -1;}
+#endif /* ndef EPOLLET */
+ if ((x & Mono_Posix_EpollEvents_EPOLLHUP) == Mono_Posix_EpollEvents_EPOLLHUP)
+#ifdef EPOLLHUP
+ *r |= EPOLLHUP;
+#else /* def EPOLLHUP */
+ {errno = EINVAL; return -1;}
+#endif /* ndef EPOLLHUP */
+ if ((x & Mono_Posix_EpollEvents_EPOLLIN) == Mono_Posix_EpollEvents_EPOLLIN)
+#ifdef EPOLLIN
+ *r |= EPOLLIN;
+#else /* def EPOLLIN */
+ {errno = EINVAL; return -1;}
+#endif /* ndef EPOLLIN */
+ if ((x & Mono_Posix_EpollEvents_EPOLLMSG) == Mono_Posix_EpollEvents_EPOLLMSG)
+#ifdef EPOLLMSG
+ *r |= EPOLLMSG;
+#else /* def EPOLLMSG */
+ {errno = EINVAL; return -1;}
+#endif /* ndef EPOLLMSG */
+ if ((x & Mono_Posix_EpollEvents_EPOLLONESHOT) == Mono_Posix_EpollEvents_EPOLLONESHOT)
+#ifdef EPOLLONESHOT
+ *r |= EPOLLONESHOT;
+#else /* def EPOLLONESHOT */
+ {errno = EINVAL; return -1;}
+#endif /* ndef EPOLLONESHOT */
+ if ((x & Mono_Posix_EpollEvents_EPOLLOUT) == Mono_Posix_EpollEvents_EPOLLOUT)
+#ifdef EPOLLOUT
+ *r |= EPOLLOUT;
+#else /* def EPOLLOUT */
+ {errno = EINVAL; return -1;}
+#endif /* ndef EPOLLOUT */
+ if ((x & Mono_Posix_EpollEvents_EPOLLPRI) == Mono_Posix_EpollEvents_EPOLLPRI)
+#ifdef EPOLLPRI
+ *r |= EPOLLPRI;
+#else /* def EPOLLPRI */
+ {errno = EINVAL; return -1;}
+#endif /* ndef EPOLLPRI */
+ if ((x & Mono_Posix_EpollEvents_EPOLLRDBAND) == Mono_Posix_EpollEvents_EPOLLRDBAND)
+#ifdef EPOLLRDBAND
+ *r |= EPOLLRDBAND;
+#else /* def EPOLLRDBAND */
+ {errno = EINVAL; return -1;}
+#endif /* ndef EPOLLRDBAND */
+ if ((x & Mono_Posix_EpollEvents_EPOLLRDHUP) == Mono_Posix_EpollEvents_EPOLLRDHUP)
+#ifdef EPOLLRDHUP
+ *r |= EPOLLRDHUP;
+#else /* def EPOLLRDHUP */
+ {errno = EINVAL; return -1;}
+#endif /* ndef EPOLLRDHUP */
+ if ((x & Mono_Posix_EpollEvents_EPOLLRDNORM) == Mono_Posix_EpollEvents_EPOLLRDNORM)
+#ifdef EPOLLRDNORM
+ *r |= EPOLLRDNORM;
+#else /* def EPOLLRDNORM */
+ {errno = EINVAL; return -1;}
+#endif /* ndef EPOLLRDNORM */
+ if ((x & Mono_Posix_EpollEvents_EPOLLWRBAND) == Mono_Posix_EpollEvents_EPOLLWRBAND)
+#ifdef EPOLLWRBAND
+ *r |= EPOLLWRBAND;
+#else /* def EPOLLWRBAND */
+ {errno = EINVAL; return -1;}
+#endif /* ndef EPOLLWRBAND */
+ if ((x & Mono_Posix_EpollEvents_EPOLLWRNORM) == Mono_Posix_EpollEvents_EPOLLWRNORM)
+#ifdef EPOLLWRNORM
+ *r |= EPOLLWRNORM;
+#else /* def EPOLLWRNORM */
+ {errno = EINVAL; return -1;}
+#endif /* ndef EPOLLWRNORM */
+ if (x == 0)
+ return 0;
+ return 0;
+}
+
+int Mono_Posix_ToEpollEvents (unsigned int x, unsigned int *r)
+{
+ *r = 0;
+ if (x == 0)
+ return 0;
+#ifdef EPOLLERR
+ if ((x & EPOLLERR) == EPOLLERR)
+ *r |= Mono_Posix_EpollEvents_EPOLLERR;
+#endif /* ndef EPOLLERR */
+#ifdef EPOLLET
+ if ((x & EPOLLET) == EPOLLET)
+ *r |= Mono_Posix_EpollEvents_EPOLLET;
+#endif /* ndef EPOLLET */
+#ifdef EPOLLHUP
+ if ((x & EPOLLHUP) == EPOLLHUP)
+ *r |= Mono_Posix_EpollEvents_EPOLLHUP;
+#endif /* ndef EPOLLHUP */
+#ifdef EPOLLIN
+ if ((x & EPOLLIN) == EPOLLIN)
+ *r |= Mono_Posix_EpollEvents_EPOLLIN;
+#endif /* ndef EPOLLIN */
+#ifdef EPOLLMSG
+ if ((x & EPOLLMSG) == EPOLLMSG)
+ *r |= Mono_Posix_EpollEvents_EPOLLMSG;
+#endif /* ndef EPOLLMSG */
+#ifdef EPOLLONESHOT
+ if ((x & EPOLLONESHOT) == EPOLLONESHOT)
+ *r |= Mono_Posix_EpollEvents_EPOLLONESHOT;
+#endif /* ndef EPOLLONESHOT */
+#ifdef EPOLLOUT
+ if ((x & EPOLLOUT) == EPOLLOUT)
+ *r |= Mono_Posix_EpollEvents_EPOLLOUT;
+#endif /* ndef EPOLLOUT */
+#ifdef EPOLLPRI
+ if ((x & EPOLLPRI) == EPOLLPRI)
+ *r |= Mono_Posix_EpollEvents_EPOLLPRI;
+#endif /* ndef EPOLLPRI */
+#ifdef EPOLLRDBAND
+ if ((x & EPOLLRDBAND) == EPOLLRDBAND)
+ *r |= Mono_Posix_EpollEvents_EPOLLRDBAND;
+#endif /* ndef EPOLLRDBAND */
+#ifdef EPOLLRDHUP
+ if ((x & EPOLLRDHUP) == EPOLLRDHUP)
+ *r |= Mono_Posix_EpollEvents_EPOLLRDHUP;
+#endif /* ndef EPOLLRDHUP */
+#ifdef EPOLLRDNORM
+ if ((x & EPOLLRDNORM) == EPOLLRDNORM)
+ *r |= Mono_Posix_EpollEvents_EPOLLRDNORM;
+#endif /* ndef EPOLLRDNORM */
+#ifdef EPOLLWRBAND
+ if ((x & EPOLLWRBAND) == EPOLLWRBAND)
+ *r |= Mono_Posix_EpollEvents_EPOLLWRBAND;
+#endif /* ndef EPOLLWRBAND */
+#ifdef EPOLLWRNORM
+ if ((x & EPOLLWRNORM) == EPOLLWRNORM)
+ *r |= Mono_Posix_EpollEvents_EPOLLWRNORM;
+#endif /* ndef EPOLLWRNORM */
+ return 0;
+}
+
+int Mono_Posix_FromEpollFlags (int x, int *r)
+{
+ *r = 0;
+ if ((x & Mono_Posix_EpollFlags_EPOLL_CLOEXEC) == Mono_Posix_EpollFlags_EPOLL_CLOEXEC)
+#ifdef EPOLL_CLOEXEC
+ *r |= EPOLL_CLOEXEC;
+#else /* def EPOLL_CLOEXEC */
+ {errno = EINVAL; return -1;}
+#endif /* ndef EPOLL_CLOEXEC */
+ if ((x & Mono_Posix_EpollFlags_EPOLL_NONBLOCK) == Mono_Posix_EpollFlags_EPOLL_NONBLOCK)
+#ifdef EPOLL_NONBLOCK
+ *r |= EPOLL_NONBLOCK;
+#else /* def EPOLL_NONBLOCK */
+ {errno = EINVAL; return -1;}
+#endif /* ndef EPOLL_NONBLOCK */
+ if (x == 0)
+ return 0;
+ return 0;
+}
+
+int Mono_Posix_ToEpollFlags (int x, int *r)
+{
+ *r = 0;
+ if (x == 0)
+ return 0;
+#ifdef EPOLL_CLOEXEC
+ if ((x & EPOLL_CLOEXEC) == EPOLL_CLOEXEC)
+ *r |= Mono_Posix_EpollFlags_EPOLL_CLOEXEC;
+#endif /* ndef EPOLL_CLOEXEC */
+#ifdef EPOLL_NONBLOCK
+ if ((x & EPOLL_NONBLOCK) == EPOLL_NONBLOCK)
+ *r |= Mono_Posix_EpollFlags_EPOLL_NONBLOCK;
+#endif /* ndef EPOLL_NONBLOCK */
+ return 0;
+}
+
int Mono_Posix_FromErrno (int x, int *r)
{
*r = 0;
return 0;
}
+#ifdef HAVE_STRUCT_FLOCK
+int
+Mono_Posix_FromFlock (struct Mono_Posix_Flock *from, struct flock *to)
+{
+ _cnm_return_val_if_overflow (off_t, from->l_start, -1);
+ _cnm_return_val_if_overflow (off_t, from->l_len, -1);
+ _cnm_return_val_if_overflow (pid_t, from->l_pid, -1);
+
+ memset (to, 0, sizeof(*to));
+
+ if (Mono_Posix_FromLockType (from->l_type, &to->l_type) != 0) {
+ return -1;
+ }
+ if (Mono_Posix_FromSeekFlags (from->l_whence, &to->l_whence) != 0) {
+ return -1;
+ }
+ to->l_start = from->l_start;
+ to->l_len = from->l_len;
+ to->l_pid = from->l_pid;
+
+ return 0;
+}
+#endif /* ndef HAVE_STRUCT_FLOCK */
+
+
+#ifdef HAVE_STRUCT_FLOCK
+int
+Mono_Posix_ToFlock (struct flock *from, struct Mono_Posix_Flock *to)
+{
+ _cnm_return_val_if_overflow (gint64, from->l_start, -1);
+ _cnm_return_val_if_overflow (gint64, from->l_len, -1);
+ _cnm_return_val_if_overflow (int, from->l_pid, -1);
+
+ memset (to, 0, sizeof(*to));
+
+ if (Mono_Posix_ToLockType (from->l_type, &to->l_type) != 0) {
+ return -1;
+ }
+ if (Mono_Posix_ToSeekFlags (from->l_whence, &to->l_whence) != 0) {
+ return -1;
+ }
+ to->l_start = from->l_start;
+ to->l_len = from->l_len;
+ to->l_pid = from->l_pid;
+
+ return 0;
+}
+#endif /* ndef HAVE_STRUCT_FLOCK */
+
+
int Mono_Posix_FromLockType (short x, short *r)
{
*r = 0;
return 0;
}
+#ifdef HAVE_STRUCT_TIMESPEC
+int
+Mono_Posix_FromTimespec (struct Mono_Posix_Timespec *from, struct timespec *to)
+{
+ _cnm_return_val_if_overflow (time_t, from->tv_sec, -1);
+ _cnm_return_val_if_overflow (gint64, from->tv_nsec, -1);
+
+ memset (to, 0, sizeof(*to));
+
+ to->tv_sec = from->tv_sec;
+ to->tv_nsec = from->tv_nsec;
+
+ return 0;
+}
+#endif /* ndef HAVE_STRUCT_TIMESPEC */
+
+
+#ifdef HAVE_STRUCT_TIMESPEC
+int
+Mono_Posix_ToTimespec (struct timespec *from, struct Mono_Posix_Timespec *to)
+{
+ _cnm_return_val_if_overflow (gint64, from->tv_sec, -1);
+ _cnm_return_val_if_overflow (gint64, from->tv_nsec, -1);
+
+ memset (to, 0, sizeof(*to));
+
+ to->tv_sec = from->tv_sec;
+ to->tv_nsec = from->tv_nsec;
+
+ return 0;
+}
+#endif /* ndef HAVE_STRUCT_TIMESPEC */
+
+
#ifdef HAVE_STRUCT_TIMEVAL
int
Mono_Posix_FromTimeval (struct Mono_Posix_Timeval *from, struct timeval *to)