docs: use "Returns:" consistently
[platform/upstream/glib.git] / glib / gpoll.c
index 0fc2d9e..2620c9a 100644 (file)
@@ -16,9 +16,7 @@
  * 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.
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
 
 /*
@@ -33,6 +31,8 @@
  */
 
 #include "config.h"
+#include "glibconfig.h"
+#include "giochannel.h"
 
 /* Uncomment the next line (and the corresponding line in gmain.c) to
  * enable debugging printouts if the environment variable
 #define G_MAIN_POLL_DEBUG
 #endif
 
-#include "glib.h"
 #include <sys/types.h>
 #include <time.h>
 #include <stdlib.h>
 #ifdef HAVE_SYS_TIME_H
 #include <sys/time.h>
 #endif /* HAVE_SYS_TIME_H */
-#ifdef GLIB_HAVE_SYS_POLL_H
-#  include <sys/poll.h>
-#  undef events         /* AIX 4.1.5 & 4.3.2 define this for SVR3,4 compatibility */
-#  undef revents /* AIX 4.1.5 & 4.3.2 define this for SVR3,4 compatibility */
+#ifdef HAVE_POLL
+#  include <poll.h>
 
 /* The poll() emulation on OS/X doesn't handle fds=NULL, nfds=0,
  * so we prefer our own poll emulation.
@@ -67,9 +64,9 @@
 #endif
 
 #endif /* GLIB_HAVE_SYS_POLL_H */
-#ifdef HAVE_UNISTD_H
+#ifdef G_OS_UNIX
 #include <unistd.h>
-#endif /* HAVE_UNISTD_H */
+#endif /* G_OS_UNIX */
 #include <errno.h>
 
 #ifdef G_OS_WIN32
 #include <windows.h>
 #endif /* G_OS_WIN32 */
 
-#include "galias.h"
+#include "gpoll.h"
+
+#ifdef G_OS_WIN32
+#include "gprintf.h"
+#endif
 
 #ifdef G_MAIN_POLL_DEBUG
-extern gboolean g_main_poll_debug;
+extern gboolean _g_main_poll_debug;
 #endif
 
 #ifdef HAVE_POLL
-/* SunOS has poll, but doesn't provide a prototype. */
-#  if defined (sun) && !defined (__SVR4)
-extern gint poll (struct pollfd *fds, guint nfsd, gint timeout);
-#  endif  /* !sun */
 
 /**
  * g_poll:
@@ -111,9 +108,9 @@ extern gint poll (struct pollfd *fds, guint nfsd, gint timeout);
  * file descriptor, but the situation is much more complicated on
  * Windows. If you need to use g_poll() in code that has to run on
  * Windows, the easiest solution is to construct all of your
- * #GPollFD<!-- -->s with g_io_channel_win32_make_pollfd().
+ * #GPollFDs with g_io_channel_win32_make_pollfd().
  *
- * Return value: the number of entries in @fds whose %revents fields
+ * Returns: the number of entries in @fds whose %revents fields
  * were filled in, or 0 if the operation timed out, or -1 on error or
  * if the call was interrupted.
  *
@@ -148,7 +145,7 @@ poll_rest (gboolean  poll_msgs,
       /* Wait for either messages or handles
        * -> Use MsgWaitForMultipleObjectsEx
        */
-      if (g_main_poll_debug)
+      if (_g_main_poll_debug)
        g_print ("  MsgWaitForMultipleObjectsEx(%d, %d)\n", nhandles, timeout);
 
       ready = MsgWaitForMultipleObjectsEx (nhandles, handles, timeout,
@@ -177,7 +174,7 @@ poll_rest (gboolean  poll_msgs,
       /* Wait for just handles
        * -> Use WaitForMultipleObjectsEx
        */
-      if (g_main_poll_debug)
+      if (_g_main_poll_debug)
        g_print ("  WaitForMultipleObjectsEx(%d, %d)\n", nhandles, timeout);
 
       ready = WaitForMultipleObjectsEx (nhandles, handles, FALSE, timeout, TRUE);
@@ -189,7 +186,7 @@ poll_rest (gboolean  poll_msgs,
        }
     }
 
-  if (g_main_poll_debug)
+  if (_g_main_poll_debug)
     g_print ("  wait returns %ld%s\n",
             ready,
             (ready == WAIT_FAILED ? " (WAIT_FAILED)" :
@@ -226,7 +223,7 @@ poll_rest (gboolean  poll_msgs,
          if ((HANDLE) f->fd == handles[ready - WAIT_OBJECT_0])
            {
              f->revents = f->events;
-             if (g_main_poll_debug)
+             if (_g_main_poll_debug)
                g_print ("  got event %p\n", (HANDLE) f->fd);
            }
        }
@@ -237,6 +234,7 @@ poll_rest (gboolean  poll_msgs,
       if (timeout == 0 && nhandles > 1)
        {
          /* Remove the handle that fired */
+         int i;
          if (ready < nhandles - 1)
            for (i = ready - WAIT_OBJECT_0 + 1; i < nhandles; i++)
              handles[i-1] = handles[i];
@@ -250,8 +248,7 @@ poll_rest (gboolean  poll_msgs,
   return 0;
 }
 
-
-static gint
+gint
 g_poll (GPollFD *fds,
        guint    nfds,
        gint     timeout)
@@ -262,13 +259,13 @@ g_poll (GPollFD *fds,
   gint nhandles = 0;
   int retval;
 
-  if (g_main_poll_debug)
+  if (_g_main_poll_debug)
     g_print ("g_poll: waiting for");
 
   for (f = fds; f < &fds[nfds]; ++f)
     if (f->fd == G_WIN32_MSG_HANDLE && (f->events & G_IO_IN))
       {
-       if (g_main_poll_debug && !poll_msgs)
+       if (_g_main_poll_debug && !poll_msgs)
          g_print (" MSG");
        poll_msgs = TRUE;
       }
@@ -293,14 +290,14 @@ g_poll (GPollFD *fds,
              }
            else
              {
-               if (g_main_poll_debug)
+               if (_g_main_poll_debug)
                  g_print (" %p", (HANDLE) f->fd);
                handles[nhandles++] = (HANDLE) f->fd;
              }
          }
       }
 
-  if (g_main_poll_debug)
+  if (_g_main_poll_debug)
     g_print ("\n");
 
   for (f = fds; f < &fds[nfds]; ++f)
@@ -354,10 +351,6 @@ g_poll (GPollFD *fds,
 #include <sys/select.h>
 #endif /* HAVE_SYS_SELECT_H */
 
-#ifdef G_OS_BEOS
-#undef NO_FD_SET
-#endif /* G_OS_BEOS */
-
 #ifndef NO_FD_SET
 #  define SELECT_MASK fd_set
 #else /* !NO_FD_SET */
@@ -425,6 +418,3 @@ g_poll (GPollFD *fds,
 #endif /* !G_OS_WIN32 */
 
 #endif /* !HAVE_POLL */
-
-#define __G_POLL_C__
-#include "galiasdef.c"