[PATCH v2 12/20] lib/cobalt: select: Move select services into wrappers_time64.c

Florian Bezdeka <[email protected]>
Newsgroups dev.linux.lists.xenomai
Message-ID <20260302-wip-flo-fix-time64-32bit-native-v2-12-7caefce29bcd@siemens.com>
select.c is no longer needed as everything inside is time64_t affected.

Signed-off-by: Florian Bezdeka <[email protected]>
---
 lib/cobalt/Makefile.am       |   1 -
 lib/cobalt/select.c          | 108 -------------------------------------------
 lib/cobalt/wrappers_time64.c |  87 ++++++++++++++++++++++++++++++++++
 3 files changed, 87 insertions(+), 109 deletions(-)

diff --git a/lib/cobalt/Makefile.am b/lib/cobalt/Makefile.am
index 68900c35104ff9bd94d1cb7534dfdc10b9795a18..be678eedf18f2d8a60afbf36060e27f2511383ec 100644
--- a/lib/cobalt/Makefile.am
+++ b/lib/cobalt/Makefile.am
@@ -33,7 +33,6 @@ libcobalt_la_SOURCES =		\
 	printf.c		\
 	rtdm.c			\
 	sched.c			\
-	select.c		\
 	semaphore.c		\
 	signal.c		\
 	sigshadow.c		\
diff --git a/lib/cobalt/select.c b/lib/cobalt/select.c
deleted file mode 100644
index 5472e991e126c2f521b346a7cf3c884bbf6f6317..0000000000000000000000000000000000000000
--- a/lib/cobalt/select.c
+++ /dev/null
@@ -1,108 +0,0 @@
-/*
- * Copyright (C) 2010 Gilles Chanteperdrix <[email protected]>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
-
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.
- */
-
-#include <errno.h>
-#include <pthread.h>
-#include <sys/select.h>
-#include <asm/xenomai/syscall.h>
-
-#if __USE_TIME_BITS64 && __TIMESIZE == 32
-
-#define USEC_PER_SEC	1000000L
-#define NSEC_PER_USEC	1000L
-
-/*
- * The time64 wrapper for select() is a little different:
- * There is no y2038 safe syscall for select() itself, but we have pselect()
- * without signal support.
- */
-static inline int do_select(int __nfds, fd_set *__restrict __readfds,
-			      fd_set *__restrict __writefds,
-			      fd_set *__restrict __exceptfds,
-			      struct timeval *__restrict __timeout)
-{
-	struct timespec to;
-	int err, oldtype;
-
-	if (__timeout) {
-		to.tv_sec =
-			__timeout->tv_sec + (__timeout->tv_usec / USEC_PER_SEC);
-		to.tv_nsec =
-			(__timeout->tv_usec % USEC_PER_SEC) * NSEC_PER_USEC;
-	}
-
-	pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldtype);
-
-	/*
-	 * Note: No sigmask here, we already reached the limit of 5
-	 * syscall parameters
-	 */
-	err = XENOMAI_SYSCALL5(sc_cobalt_pselect64, __nfds, __readfds,
-			       __writefds, __exceptfds, __timeout ? &to : NULL);
-
-	pthread_setcanceltype(oldtype, NULL);
-
-	if (err == -EADV || err == -EPERM || err == -ENOSYS) {
-		err = __STD(__select64(__nfds, __readfds, __writefds,
-				       __exceptfds, __timeout));
-	} else if (__timeout) {
-		__timeout->tv_sec = to.tv_sec;
-		__timeout->tv_usec = to.tv_nsec / 1000;
-	}
-
-	if (err >= 0)
-		return err;
-
-	errno = -err;
-	return -1;
-}
-#else
-static inline int do_select(int __nfds, fd_set *__restrict __readfds,
-			    fd_set *__restrict __writefds,
-			    fd_set *__restrict __exceptfds,
-			    struct timeval *__restrict __timeout)
-{
-	int err, oldtype;
-
-	pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldtype);
-
-	err = XENOMAI_SYSCALL5(sc_cobalt_select, __nfds,
-			       __readfds, __writefds, __exceptfds, __timeout);
-
-	pthread_setcanceltype(oldtype, NULL);
-
-	if (err == -EADV || err == -EPERM || err == -ENOSYS)
-		return __STD(select(__nfds, __readfds,
-				    __writefds, __exceptfds, __timeout));
-
-	if (err >= 0)
-		return err;
-
-	errno = -err;
-	return -1;
-}
-#endif
-
-COBALT_IMPL_TIME64(int, select, __select64,
-		   (int __nfds, fd_set *__restrict __readfds,
-		    fd_set *__restrict __writefds,
-		    fd_set *__restrict __exceptfds,
-		    struct timeval *__restrict __timeout))
-{
-	return do_select(__nfds, __readfds, __writefds, __exceptfds, __timeout);
-}
diff --git a/lib/cobalt/wrappers_time64.c b/lib/cobalt/wrappers_time64.c
index 1e830945f381117ac6180476dd95a3608b5596b6..524d2774d3dad551e599de30aea4919967719bab 100644
--- a/lib/cobalt/wrappers_time64.c
+++ b/lib/cobalt/wrappers_time64.c
@@ -2,6 +2,7 @@
 
 /*
  * Copyright (C) 2026 Florian Bezdeka <[email protected]>.
+ * Copyright (C) 2010 Gilles Chanteperdrix <[email protected]>.
  * Copyright (C) 2005 Philippe Gerum <[email protected]>.
  */
 
@@ -761,3 +762,89 @@ COBALT_IMPL_TIME64(int, setsockopt, __setsockopt64,
 
 	return __STD(setsockopt(fd, level, optname, optval, optlen));
 }
+
+#if __USE_TIME_BITS64 && __TIMESIZE == 32
+
+#define USEC_PER_SEC	1000000L
+#define NSEC_PER_USEC	1000L
+
+/*
+ * The time64 wrapper for select() is a little different:
+ * There is no y2038 safe syscall for select() itself, but we have pselect()
+ * without signal support.
+ */
+static inline int do_select(int __nfds, fd_set *__restrict __readfds,
+			      fd_set *__restrict __writefds,
+			      fd_set *__restrict __exceptfds,
+			      struct timeval *__restrict __timeout)
+{
+	struct timespec to;
+	int err, oldtype;
+
+	if (__timeout) {
+		to.tv_sec =
+			__timeout->tv_sec + (__timeout->tv_usec / USEC_PER_SEC);
+		to.tv_nsec =
+			(__timeout->tv_usec % USEC_PER_SEC) * NSEC_PER_USEC;
+	}
+
+	pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldtype);
+
+	/*
+	 * Note: No sigmask here, we already reached the limit of 5
+	 * syscall parameters
+	 */
+	err = XENOMAI_SYSCALL5(sc_cobalt_pselect64, __nfds, __readfds,
+			       __writefds, __exceptfds, __timeout ? &to : NULL);
+
+	pthread_setcanceltype(oldtype, NULL);
+
+	if (err == -EADV || err == -EPERM || err == -ENOSYS) {
+		err = __STD(__select64(__nfds, __readfds, __writefds,
+				       __exceptfds, __timeout));
+	} else if (__timeout) {
+		__timeout->tv_sec = to.tv_sec;
+		__timeout->tv_usec = to.tv_nsec / 1000;
+	}
+
+	if (err >= 0)
+		return err;
+
+	errno = -err;
+	return -1;
+}
+#else
+static inline int do_select(int __nfds, fd_set *__restrict __readfds,
+			    fd_set *__restrict __writefds,
+			    fd_set *__restrict __exceptfds,
+			    struct timeval *__restrict __timeout)
+{
+	int err, oldtype;
+
+	pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldtype);
+
+	err = XENOMAI_SYSCALL5(sc_cobalt_select, __nfds,
+			       __readfds, __writefds, __exceptfds, __timeout);
+
+	pthread_setcanceltype(oldtype, NULL);
+
+	if (err == -EADV || err == -EPERM || err == -ENOSYS)
+		return __STD(select(__nfds, __readfds,
+				    __writefds, __exceptfds, __timeout));
+
+	if (err >= 0)
+		return err;
+
+	errno = -err;
+	return -1;
+}
+#endif
+
+COBALT_IMPL_TIME64(int, select, __select64,
+		   (int __nfds, fd_set *__restrict __readfds,
+		    fd_set *__restrict __writefds,
+		    fd_set *__restrict __exceptfds,
+		    struct timeval *__restrict __timeout))
+{
+	return do_select(__nfds, __readfds, __writefds, __exceptfds, __timeout);
+}

-- 
2.53.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.