]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - ncurses/tinfo/lib_napms.c
ncurses 6.1 - patch 20181215
[ncurses.git] / ncurses / tinfo / lib_napms.c
index a85304bf1cb687a455c2286c6e19d101a26340ac..e1a0587028ed75e78b8f47542d42840299fe6d42 100644 (file)
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998 Free Software Foundation, Inc.                        *
+ * Copyright (c) 1998-2014,2017 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
 /****************************************************************************
  *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
  *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ *     and: Thomas E. Dickey                        1996-on                 *
+ *     and: Juergen Pfeifer                         2009                    *
  ****************************************************************************/
 
-
 /*
  *     lib_napms.c
  *
  *     The routine napms.
  *
+ *     (This file was originally written by Eric Raymond; however except for
+ *     comments, none of the original code remains - T.Dickey).
  */
 
 #include <curses.priv.h>
 
 #if HAVE_NANOSLEEP
 #include <time.h>
-#elif USE_FUNC_POLL
-#include <stropts.h>
-#include <poll.h>
 #if HAVE_SYS_TIME_H
-#include <sys/time.h>
-#endif
-#elif HAVE_SELECT
-#if HAVE_SYS_TIME_H && HAVE_SYS_TIME_SELECT
-#include <sys/time.h>
-#endif
-#if HAVE_SYS_SELECT_H
-#include <sys/select.h>
+#include <sys/time.h>          /* needed for MacOS X DP3 */
 #endif
 #endif
 
-MODULE_ID("$Id: lib_napms.c,v 1.6 1999/10/21 23:01:41 tom Exp $")
+MODULE_ID("$Id: lib_napms.c,v 1.25 2017/07/01 21:05:56 tom Exp $")
 
-int napms(int ms)
+NCURSES_EXPORT(int)
+NCURSES_SP_NAME(napms) (NCURSES_SP_DCLx int ms)
 {
-       T((T_CALLED("napms(%d)"), ms));
+    T((T_CALLED("napms(%d)"), ms));
 
+#ifdef USE_TERM_DRIVER
+    CallDriver_1(SP_PARM, td_nap, ms);
+#else /* !USE_TERM_DRIVER */
+#if NCURSES_SP_FUNCS
+    (void) sp;
+#endif
 #if HAVE_NANOSLEEP
-       {
-               struct timespec ts;
-               ts.tv_sec = ms / 1000;
-               ts.tv_nsec = (ms % 1000) * 1000000;
-               nanosleep(&ts, NULL);
-       }
-#elif USE_FUNC_POLL
-       {
-               struct pollfd fds[1];
-               poll(fds, 0, ms);
-       }
-#elif HAVE_SELECT
-       {
-               struct timeval tval;
-               tval.tv_sec = ms / 1000;
-               tval.tv_usec = (ms % 1000) * 1000;
-               select(0, NULL, NULL, NULL, &tval);
+    {
+       struct timespec request, remaining;
+       request.tv_sec = ms / 1000;
+       request.tv_nsec = (ms % 1000) * 1000000;
+       while (nanosleep(&request, &remaining) == -1
+              && errno == EINTR) {
+           request = remaining;
        }
+    }
+#else
+    _nc_timed_wait(0, 0, ms, (int *) 0 EVENTLIST_2nd(0));
 #endif
-       returnCode(OK);
+#endif /* !USE_TERM_DRIVER */
+
+    returnCode(OK);
 }
+
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(int)
+napms(int ms)
+{
+    return NCURSES_SP_NAME(napms) (CURRENT_SCREEN, ms);
+}
+#endif