2 * spawn.h - this file is part of Geany, a fast and lightweight IDE
4 * Copyright 2013 Dimitar Toshkov Zhekov <dimitar(dot)zhekov(at)gmail(dot)com>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program 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
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #define GEANY_SPAWN_H 1
28 # define WIFEXITED(status) TRUE
29 # define WEXITSTATUS(status) (status)
30 # define WIFSIGNALLED(status) FALSE
32 # include <sys/types.h>
33 # include <sys/wait.h>
38 gchar
*spawn_get_program_name(const gchar
*command_line
, GError
**error
);
40 gboolean
spawn_check_command(const gchar
*command_line
, gboolean execute
, GError
**error
);
42 gboolean
spawn_kill_process(GPid pid
, GError
**error
);
44 gboolean
spawn_async_with_pipes(const gchar
*working_directory
, const gchar
*command_line
,
45 gchar
**argv
, gchar
**envp
, GPid
*child_pid
, gint
*stdin_fd
, gint
*stdout_fd
,
46 gint
*stderr_fd
, GError
**error
);
48 gboolean
spawn_async(const gchar
*working_directory
, const gchar
*command_line
, gchar
**argv
,
49 gchar
**envp
, GPid
*child_pid
, GError
**error
);
51 /** Flags passed to @c spawn_with_callbacks(), which see. */
54 SPAWN_ASYNC
= 0x00, /**< Asynchronous execution [default]. */
55 SPAWN_SYNC
= 0x01, /**< Synchronous execution. */
57 SPAWN_LINE_BUFFERED
= 0x00, /**< stdout/stderr are line buffered [default]. */
58 SPAWN_STDOUT_UNBUFFERED
= 0x02, /**< stdout is not buffered. */
59 SPAWN_STDERR_UNBUFFERED
= 0x04, /**< stderr is not buffered. */
60 SPAWN_UNBUFFERED
= 0x06, /**< stdout/stderr are not buffered. */
62 SPAWN_STDIN_RECURSIVE
= 0x08, /**< The stdin callback is recursive. */
63 SPAWN_STDOUT_RECURSIVE
= 0x10, /**< The stdout callback is recursive. */
64 SPAWN_STDERR_RECURSIVE
= 0x20, /**< The stderr callback is recursive. */
65 SPAWN_RECURSIVE
= 0x38 /**< All callbacks are recursive. */
69 * Specifies the type of function passed to @c spawn_with_callbacks() as stdout or stderr
72 * In unbuffered mode, the @a string may contain nuls, while in line buffered mode, it may
73 * contain only a single nul as a line termination character at @a string->len - 1. In all
74 * cases, the @a string will be terminated with a nul character that is not part of the data
77 * If @c G_IO_IN or @c G_IO_PRI are set, the @a string will contain at least one character.
79 * @param string contains the child data if @c G_IO_IN or @c G_IO_PRI are set.
80 * @param condition the I/O condition which has been satisfied.
81 * @param data the passed to @c spawn_with_callbacks() with the callback.
83 typedef void (*SpawnReadFunc
)(GString
*string
, GIOCondition condition
, gpointer data
);
85 gboolean
spawn_with_callbacks(const gchar
*working_directory
, const gchar
*command_line
,
86 gchar
**argv
, gchar
**envp
, SpawnFlags spawn_flags
, GIOFunc stdin_cb
, gpointer stdin_data
,
87 SpawnReadFunc stdout_cb
, gpointer stdout_data
, gsize stdout_max_length
,
88 SpawnReadFunc stderr_cb
, gpointer stderr_data
, gsize stderr_max_length
,
89 GChildWatchFunc exit_cb
, gpointer exit_data
, GPid
*child_pid
, GError
**error
);
92 * A simple structure used by @c spawn_write_data() to write data to a channel.
93 * See @c spawn_write_data() for more information.
95 typedef struct _SpawnWriteData
97 const gchar
*ptr
; /**< Pointer to the data. May be NULL if the size is 0. */
98 gsize size
; /**< Size of the data. */
101 gboolean
spawn_write_data(GIOChannel
*channel
, GIOCondition condition
, SpawnWriteData
*data
);
103 void spawn_get_exit_status_cb(GPid pid
, gint status
, gpointer exit_status
);
105 gboolean
spawn_sync(const gchar
*working_directory
, const gchar
*command_line
, gchar
**argv
,
106 gchar
**envp
, SpawnWriteData
*stdin_data
, GString
*stdout_data
, GString
*stderr_data
,
107 gint
*exit_status
, GError
**error
);
111 #endif /* GEANY_SPAWN_H */