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