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 WIFSIGNALED(status) FALSE
32 # include <sys/types.h>
33 # include <sys/wait.h>
38 gboolean
spawn_check_command(const gchar
*command_line
, gboolean execute
, GError
**error
);
40 gboolean
spawn_kill_process(GPid pid
, GError
**error
);
42 gboolean
spawn_async(const gchar
*working_directory
, const gchar
*command_line
, gchar
**argv
,
43 gchar
**envp
, GPid
*child_pid
, GError
**error
);
45 /** Flags passed to @c spawn_with_callbacks(), which see. */
48 SPAWN_ASYNC
= 0x00, /**< Asynchronous execution [default]. */
49 SPAWN_SYNC
= 0x01, /**< Synchronous execution. */
51 SPAWN_LINE_BUFFERED
= 0x00, /**< stdout/stderr are line buffered [default]. */
52 SPAWN_STDOUT_UNBUFFERED
= 0x02, /**< stdout is not buffered. */
53 SPAWN_STDERR_UNBUFFERED
= 0x04, /**< stderr is not buffered. */
54 SPAWN_UNBUFFERED
= 0x06, /**< stdout/stderr are not buffered. */
56 SPAWN_STDIN_RECURSIVE
= 0x08, /**< The stdin callback is recursive. */
57 SPAWN_STDOUT_RECURSIVE
= 0x10, /**< The stdout callback is recursive. */
58 SPAWN_STDERR_RECURSIVE
= 0x20, /**< The stderr callback is recursive. */
59 SPAWN_RECURSIVE
= 0x38 /**< All callbacks are recursive. */
63 * Specifies the type of function passed to @c spawn_with_callbacks() as stdout or stderr
66 * In unbuffered mode, the @a string may contain nuls, while in line buffered mode, it may
67 * contain only a single nul as a line termination character at @a string->len - 1. In all
68 * cases, the @a string will be terminated with a nul character that is not part of the data
71 * If @c G_IO_IN or @c G_IO_PRI are set, the @a string will contain at least one character.
73 * @param string contains the child data if @c G_IO_IN or @c G_IO_PRI are set.
74 * @param condition the I/O condition which has been satisfied.
75 * @param data the passed to @c spawn_with_callbacks() with the callback.
77 typedef void (*SpawnReadFunc
)(GString
*string
, GIOCondition condition
, gpointer data
);
79 gboolean
spawn_with_callbacks(const gchar
*working_directory
, const gchar
*command_line
,
80 gchar
**argv
, gchar
**envp
, SpawnFlags spawn_flags
, GIOFunc stdin_cb
, gpointer stdin_data
,
81 SpawnReadFunc stdout_cb
, gpointer stdout_data
, gsize stdout_max_length
,
82 SpawnReadFunc stderr_cb
, gpointer stderr_data
, gsize stderr_max_length
,
83 GChildWatchFunc exit_cb
, gpointer exit_data
, GPid
*child_pid
, GError
**error
);
86 * A simple structure used by @c spawn_write_data() to write data to a channel.
87 * See @c spawn_write_data() for more information.
89 typedef struct _SpawnWriteData
91 const gchar
*ptr
; /**< Pointer to the data. May be NULL if the size is 0. */
92 gsize size
; /**< Size of the data. */
95 gboolean
spawn_write_data(GIOChannel
*channel
, GIOCondition condition
, SpawnWriteData
*data
);
97 gboolean
spawn_sync(const gchar
*working_directory
, const gchar
*command_line
, gchar
**argv
,
98 gchar
**envp
, SpawnWriteData
*stdin_data
, GString
*stdout_data
, GString
*stderr_data
,
99 gint
*exit_status
, GError
**error
);
103 #endif /* GEANY_SPAWN_H */