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>
36 gchar
*spawn_get_program_name(const gchar
*command_line
, GError
**error
);
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_with_pipes(const gchar
*working_directory
, const gchar
*command_line
,
43 gchar
**argv
, gchar
**envp
, GPid
*child_pid
, gint
*stdin_fd
, gint
*stdout_fd
,
44 gint
*stderr_fd
, GError
**error
);
46 gboolean
spawn_async(const gchar
*working_directory
, const gchar
*command_line
, gchar
**argv
,
47 gchar
**envp
, GPid
*child_pid
, GError
**error
);
49 /** Flags passed to @c spawn_with_callbacks(), which see. */
52 SPAWN_ASYNC
= 0x00, /**< Asynchronous execution [default]. */
53 SPAWN_SYNC
= 0x01, /**< Synchronous execution. */
55 SPAWN_LINE_BUFFERED
= 0x00, /**< stdout/stderr are line buffered [default]. */
56 SPAWN_STDOUT_UNBUFFERED
= 0x02, /**< stdout is not buffered. */
57 SPAWN_STDERR_UNBUFFERED
= 0x04, /**< stderr is not buffered. */
58 SPAWN_UNBUFFERED
= 0x06, /**< stdout/stderr are not buffered. */
60 SPAWN_STDIN_RECURSIVE
= 0x08, /**< The stdin callback is recursive. */
61 SPAWN_STDOUT_RECURSIVE
= 0x10, /**< The stdout callback is recursive. */
62 SPAWN_STDERR_RECURSIVE
= 0x20, /**< The stderr callback is recursive. */
63 SPAWN_RECURSIVE
= 0x38 /**< All callbacks are recursive. */
67 * Specifies the type of function passed to @c spawn_with_callbacks() as stdout or stderr
70 * In unbuffered mode, the @a string may contain nuls, while in line buffered mode, it may
71 * contain only a single nul as a line termination character at @a string->len - 1. In all
72 * cases, the @a string will be terminated with a nul character that is not part of the data
75 * If @c G_IO_IN or @c G_IO_PRI are set, the @a string will contain at least one character.
77 * @param string contains the child data if @c G_IO_IN or @c G_IO_PRI are set.
78 * @param condition the I/O condition which has been satisfied.
79 * @param data the passed to @c spawn_with_callbacks() with the callback.
81 typedef void (*SpawnReadFunc
)(GString
*string
, GIOCondition condition
, gpointer data
);
83 gboolean
spawn_with_callbacks(const gchar
*working_directory
, const gchar
*command_line
,
84 gchar
**argv
, gchar
**envp
, SpawnFlags spawn_flags
, GIOFunc stdin_cb
, gpointer stdin_data
,
85 SpawnReadFunc stdout_cb
, gpointer stdout_data
, gsize stdout_max_length
,
86 SpawnReadFunc stderr_cb
, gpointer stderr_data
, gsize stderr_max_length
,
87 GChildWatchFunc exit_cb
, gpointer exit_data
, GPid
*child_pid
, GError
**error
);
90 * A simple structure used by @c spawn_write_data() to write data to a channel.
91 * See @c spawn_write_data() for more information.
93 typedef struct _SpawnWriteData
95 const gchar
*ptr
; /**< Pointer to the data. May be NULL if the size is 0. */
96 gsize size
; /**< Size of the data. */
99 gboolean
spawn_write_data(GIOChannel
*channel
, GIOCondition condition
, SpawnWriteData
*data
);
101 void spawn_get_exit_status_cb(GPid pid
, gint status
, gpointer exit_status
);
103 gboolean
spawn_sync(const gchar
*working_directory
, const gchar
*command_line
, gchar
**argv
,
104 gchar
**envp
, SpawnWriteData
*stdin_data
, GString
*stdout_data
, GString
*stderr_data
,
105 gint
*exit_status
, GError
**error
);
107 #endif /* GEANY_SPAWN_H */