glib-unix.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /* glib-unix.h - Unix specific integration
  2. * Copyright (C) 2011 Red Hat, Inc.
  3. *
  4. * This library is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Library General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2 of the License, or (at your option) any later version.
  8. *
  9. * This library is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Library General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Library General Public
  15. * License along with this library; if not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #ifndef __G_UNIX_H__
  18. #define __G_UNIX_H__
  19. /* We need to include the UNIX headers needed to use the APIs below,
  20. * but we also take this opportunity to include a wide selection of
  21. * other UNIX headers. If one of the headers below is broken on some
  22. * system, work around it here (or better, fix the system or tell
  23. * people to use a better one).
  24. */
  25. #include <unistd.h>
  26. #include <errno.h>
  27. #include <sys/wait.h>
  28. #include <stdlib.h>
  29. #include <fcntl.h>
  30. #include <glib.h>
  31. #ifndef G_OS_UNIX
  32. #error "This header may only be used on UNIX"
  33. #endif
  34. G_BEGIN_DECLS
  35. /**
  36. * G_UNIX_ERROR:
  37. *
  38. * Error domain for API in the g_unix_ namespace. Note that there is no
  39. * exported enumeration mapping %errno. Instead, all functions ensure that
  40. * %errno is relevant. The code for all #G_UNIX_ERROR is always 0, and the
  41. * error message is always generated via g_strerror().
  42. *
  43. * It is expected that most code will not look at %errno from these APIs.
  44. * Important cases where one would want to differentiate between errors are
  45. * already covered by existing cross-platform GLib API, such as e.g. #GFile
  46. * wrapping `ENOENT`. However, it is provided for completeness, at least.
  47. */
  48. #define G_UNIX_ERROR (g_unix_error_quark())
  49. GLIB_AVAILABLE_IN_2_30
  50. GQuark g_unix_error_quark (void);
  51. GLIB_AVAILABLE_IN_2_30
  52. gboolean g_unix_open_pipe (gint *fds,
  53. gint flags,
  54. GError **error);
  55. GLIB_AVAILABLE_IN_2_30
  56. gboolean g_unix_set_fd_nonblocking (gint fd,
  57. gboolean nonblock,
  58. GError **error);
  59. GLIB_AVAILABLE_IN_2_30
  60. GSource *g_unix_signal_source_new (gint signum);
  61. GLIB_AVAILABLE_IN_2_30
  62. guint g_unix_signal_add_full (gint priority,
  63. gint signum,
  64. GSourceFunc handler,
  65. gpointer user_data,
  66. GDestroyNotify notify);
  67. GLIB_AVAILABLE_IN_2_30
  68. guint g_unix_signal_add (gint signum,
  69. GSourceFunc handler,
  70. gpointer user_data);
  71. /**
  72. * GUnixFDSourceFunc:
  73. * @fd: the fd that triggered the event
  74. * @condition: the IO conditions reported on @fd
  75. * @user_data: user data passed to g_unix_fd_add()
  76. *
  77. * The type of functions to be called when a UNIX fd watch source
  78. * triggers.
  79. *
  80. * Returns: %FALSE if the source should be removed
  81. **/
  82. typedef gboolean (*GUnixFDSourceFunc) (gint fd,
  83. GIOCondition condition,
  84. gpointer user_data);
  85. GLIB_AVAILABLE_IN_2_36
  86. GSource *g_unix_fd_source_new (gint fd,
  87. GIOCondition condition);
  88. GLIB_AVAILABLE_IN_2_36
  89. guint g_unix_fd_add_full (gint priority,
  90. gint fd,
  91. GIOCondition condition,
  92. GUnixFDSourceFunc function,
  93. gpointer user_data,
  94. GDestroyNotify notify);
  95. GLIB_AVAILABLE_IN_2_36
  96. guint g_unix_fd_add (gint fd,
  97. GIOCondition condition,
  98. GUnixFDSourceFunc function,
  99. gpointer user_data);
  100. G_END_DECLS
  101. #endif /* __G_UNIX_H__ */