sdl3_sys/generated/process.rs
1//! Process control support.
2//!
3//! These functions provide a cross-platform way to spawn and manage OS-level
4//! processes.
5//!
6//! You can create a new subprocess with [`SDL_CreateProcess()`] and optionally
7//! read and write to it using [`SDL_ReadProcess()`] or [`SDL_GetProcessInput()`] and
8//! [`SDL_GetProcessOutput()`]. If more advanced functionality like chaining input
9//! between processes is necessary, you can use
10//! [`SDL_CreateProcessWithProperties()`].
11//!
12//! You can get the status of a created process with [`SDL_WaitProcess()`], or
13//! terminate the process with [`SDL_KillProcess()`].
14//!
15//! Don't forget to call [`SDL_DestroyProcess()`] to clean up, whether the process
16//! process was killed, terminated on its own, or is still running!
17
18use super::stdinc::*;
19
20use super::error::*;
21
22use super::iostream::*;
23
24use super::properties::*;
25
26unsafe extern "C" {
27 /// Create a new process.
28 ///
29 /// The path to the executable is supplied in args\[0\]. args\[1..N\] are
30 /// additional arguments passed on the command line of the new process, and the
31 /// argument list should be terminated with a NULL, e.g.:
32 ///
33 /// ```c
34 /// const char *args[] = { "myprogram", "argument", NULL };
35 /// ```
36 ///
37 /// Setting pipe_stdio to true is equivalent to setting
38 /// [`SDL_PROP_PROCESS_CREATE_STDIN_NUMBER`] and
39 /// [`SDL_PROP_PROCESS_CREATE_STDOUT_NUMBER`] to [`SDL_PROCESS_STDIO_APP`], and
40 /// will allow the use of [`SDL_ReadProcess()`] or [`SDL_GetProcessInput()`] and
41 /// [`SDL_GetProcessOutput()`].
42 ///
43 /// See [`SDL_CreateProcessWithProperties()`] for more details.
44 ///
45 /// ## Parameters
46 /// - `args`: the path and arguments for the new process.
47 /// - `pipe_stdio`: true to create pipes to the process's standard input and
48 /// from the process's standard output, false for the process
49 /// to have no input and inherit the application's standard
50 /// output.
51 ///
52 /// ## Return value
53 /// Returns the newly created and running process, or NULL if the process
54 /// couldn't be created.
55 ///
56 /// ## Thread safety
57 /// It is safe to call this function from any thread.
58 ///
59 /// ## Availability
60 /// This function is available since SDL 3.2.0.
61 ///
62 /// ## See also
63 /// - [`SDL_CreateProcessWithProperties`]
64 /// - [`SDL_GetProcessProperties`]
65 /// - [`SDL_ReadProcess`]
66 /// - [`SDL_GetProcessInput`]
67 /// - [`SDL_GetProcessOutput`]
68 /// - [`SDL_KillProcess`]
69 /// - [`SDL_WaitProcess`]
70 /// - [`SDL_DestroyProcess`]
71 pub fn SDL_CreateProcess(
72 args: *const *const ::core::ffi::c_char,
73 pipe_stdio: ::core::primitive::bool,
74 ) -> *mut SDL_Process;
75}
76
77/// Description of where standard I/O should be directed when creating a
78/// process.
79///
80/// If a standard I/O stream is set to [`SDL_PROCESS_STDIO_INHERITED`], it will go
81/// to the same place as the application's I/O stream. This is the default for
82/// standard output and standard error.
83///
84/// If a standard I/O stream is set to [`SDL_PROCESS_STDIO_NULL`], it is connected
85/// to `NUL:` on Windows and `/dev/null` on POSIX systems. This is the default
86/// for standard input.
87///
88/// If a standard I/O stream is set to [`SDL_PROCESS_STDIO_APP`], it is connected
89/// to a new [`SDL_IOStream`] that is available to the application. Standard input
90/// will be available as [`SDL_PROP_PROCESS_STDIN_POINTER`] and allows
91/// [`SDL_GetProcessInput()`], standard output will be available as
92/// [`SDL_PROP_PROCESS_STDOUT_POINTER`] and allows [`SDL_ReadProcess()`] and
93/// [`SDL_GetProcessOutput()`], and standard error will be available as
94/// [`SDL_PROP_PROCESS_STDERR_POINTER`] in the properties for the created
95/// process.
96///
97/// If a standard I/O stream is set to [`SDL_PROCESS_STDIO_REDIRECT`], it is
98/// connected to an existing [`SDL_IOStream`] provided by the application. Standard
99/// input is provided using [`SDL_PROP_PROCESS_CREATE_STDIN_POINTER`], standard
100/// output is provided using [`SDL_PROP_PROCESS_CREATE_STDOUT_POINTER`], and
101/// standard error is provided using [`SDL_PROP_PROCESS_CREATE_STDERR_POINTER`]
102/// in the creation properties. These existing streams should be closed by the
103/// application once the new process is created.
104///
105/// In order to use an [`SDL_IOStream`] with [`SDL_PROCESS_STDIO_REDIRECT`], it must
106/// have [`SDL_PROP_IOSTREAM_WINDOWS_HANDLE_POINTER`] or
107/// [`SDL_PROP_IOSTREAM_FILE_DESCRIPTOR_NUMBER`] set. This is true for streams
108/// representing files and process I/O.
109///
110/// ## Availability
111/// This enum is available since SDL 3.2.0.
112///
113/// ## See also
114/// - [`SDL_CreateProcessWithProperties`]
115/// - [`SDL_GetProcessProperties`]
116/// - [`SDL_ReadProcess`]
117/// - [`SDL_GetProcessInput`]
118/// - [`SDL_GetProcessOutput`]
119///
120/// ## Known values (`sdl3-sys`)
121/// | Associated constant | Global constant | Description |
122/// | ------------------- | --------------- | ----------- |
123/// | [`INHERITED`](SDL_ProcessIO::INHERITED) | [`SDL_PROCESS_STDIO_INHERITED`] | The I/O stream is inherited from the application. |
124/// | [`NULL`](SDL_ProcessIO::NULL) | [`SDL_PROCESS_STDIO_NULL`] | The I/O stream is ignored. |
125/// | [`APP`](SDL_ProcessIO::APP) | [`SDL_PROCESS_STDIO_APP`] | The I/O stream is connected to a new [`SDL_IOStream`] that the application can read or write |
126/// | [`REDIRECT`](SDL_ProcessIO::REDIRECT) | [`SDL_PROCESS_STDIO_REDIRECT`] | The I/O stream is redirected to an existing [`SDL_IOStream`]. |
127#[repr(transparent)]
128#[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
129pub struct SDL_ProcessIO(pub ::core::ffi::c_int);
130
131impl ::core::cmp::PartialEq<::core::ffi::c_int> for SDL_ProcessIO {
132 #[inline(always)]
133 fn eq(&self, other: &::core::ffi::c_int) -> bool {
134 &self.0 == other
135 }
136}
137
138impl ::core::cmp::PartialEq<SDL_ProcessIO> for ::core::ffi::c_int {
139 #[inline(always)]
140 fn eq(&self, other: &SDL_ProcessIO) -> bool {
141 self == &other.0
142 }
143}
144
145impl From<SDL_ProcessIO> for ::core::ffi::c_int {
146 #[inline(always)]
147 fn from(value: SDL_ProcessIO) -> Self {
148 value.0
149 }
150}
151
152#[cfg(feature = "debug-impls")]
153impl ::core::fmt::Debug for SDL_ProcessIO {
154 fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
155 #[allow(unreachable_patterns)]
156 f.write_str(match *self {
157 Self::INHERITED => "SDL_PROCESS_STDIO_INHERITED",
158 Self::NULL => "SDL_PROCESS_STDIO_NULL",
159 Self::APP => "SDL_PROCESS_STDIO_APP",
160 Self::REDIRECT => "SDL_PROCESS_STDIO_REDIRECT",
161
162 _ => return write!(f, "SDL_ProcessIO({})", self.0),
163 })
164 }
165}
166
167impl SDL_ProcessIO {
168 /// The I/O stream is inherited from the application.
169 pub const INHERITED: Self = Self((0 as ::core::ffi::c_int));
170 /// The I/O stream is ignored.
171 pub const NULL: Self = Self((1 as ::core::ffi::c_int));
172 /// The I/O stream is connected to a new [`SDL_IOStream`] that the application can read or write
173 pub const APP: Self = Self((2 as ::core::ffi::c_int));
174 /// The I/O stream is redirected to an existing [`SDL_IOStream`].
175 pub const REDIRECT: Self = Self((3 as ::core::ffi::c_int));
176}
177
178/// The I/O stream is inherited from the application.
179pub const SDL_PROCESS_STDIO_INHERITED: SDL_ProcessIO = SDL_ProcessIO::INHERITED;
180/// The I/O stream is ignored.
181pub const SDL_PROCESS_STDIO_NULL: SDL_ProcessIO = SDL_ProcessIO::NULL;
182/// The I/O stream is connected to a new [`SDL_IOStream`] that the application can read or write
183pub const SDL_PROCESS_STDIO_APP: SDL_ProcessIO = SDL_ProcessIO::APP;
184/// The I/O stream is redirected to an existing [`SDL_IOStream`].
185pub const SDL_PROCESS_STDIO_REDIRECT: SDL_ProcessIO = SDL_ProcessIO::REDIRECT;
186
187#[cfg(feature = "metadata")]
188impl sdl3_sys::metadata::GroupMetadata for SDL_ProcessIO {
189 const GROUP_METADATA: &'static sdl3_sys::metadata::Group =
190 &crate::metadata::process::METADATA_SDL_ProcessIO;
191}
192
193unsafe extern "C" {
194 /// Create a new process with the specified properties.
195 ///
196 /// These are the supported properties:
197 ///
198 /// - [`SDL_PROP_PROCESS_CREATE_ARGS_POINTER`]\: an array of strings containing
199 /// the program to run, any arguments, and a NULL pointer, e.g. const char
200 /// *args\[\] = { "myprogram", "argument", NULL }. This is a required property.
201 /// - [`SDL_PROP_PROCESS_CREATE_ENVIRONMENT_POINTER`]\: an [`SDL_Environment`]
202 /// pointer. If this property is set, it will be the entire environment for
203 /// the process, otherwise the current environment is used.
204 /// - [`SDL_PROP_PROCESS_CREATE_WORKING_DIRECTORY_STRING`]\: a UTF-8 encoded
205 /// string representing the working directory for the process, defaults to
206 /// the current working directory.
207 /// - [`SDL_PROP_PROCESS_CREATE_STDIN_NUMBER`]\: an [`SDL_ProcessIO`] value describing
208 /// where standard input for the process comes from, defaults to
209 /// [`SDL_PROCESS_STDIO_NULL`].
210 /// - [`SDL_PROP_PROCESS_CREATE_STDIN_POINTER`]\: an [`SDL_IOStream`] pointer used for
211 /// standard input when [`SDL_PROP_PROCESS_CREATE_STDIN_NUMBER`] is set to
212 /// [`SDL_PROCESS_STDIO_REDIRECT`].
213 /// - [`SDL_PROP_PROCESS_CREATE_STDOUT_NUMBER`]\: an [`SDL_ProcessIO`] value
214 /// describing where standard output for the process goes to, defaults to
215 /// [`SDL_PROCESS_STDIO_INHERITED`].
216 /// - [`SDL_PROP_PROCESS_CREATE_STDOUT_POINTER`]\: an [`SDL_IOStream`] pointer used
217 /// for standard output when [`SDL_PROP_PROCESS_CREATE_STDOUT_NUMBER`] is set
218 /// to [`SDL_PROCESS_STDIO_REDIRECT`].
219 /// - [`SDL_PROP_PROCESS_CREATE_STDERR_NUMBER`]\: an [`SDL_ProcessIO`] value
220 /// describing where standard error for the process goes to, defaults to
221 /// [`SDL_PROCESS_STDIO_INHERITED`].
222 /// - [`SDL_PROP_PROCESS_CREATE_STDERR_POINTER`]\: an [`SDL_IOStream`] pointer used
223 /// for standard error when [`SDL_PROP_PROCESS_CREATE_STDERR_NUMBER`] is set to
224 /// [`SDL_PROCESS_STDIO_REDIRECT`].
225 /// - [`SDL_PROP_PROCESS_CREATE_STDERR_TO_STDOUT_BOOLEAN`]\: true if the error
226 /// output of the process should be redirected into the standard output of
227 /// the process. This property has no effect if
228 /// [`SDL_PROP_PROCESS_CREATE_STDERR_NUMBER`] is set.
229 /// - [`SDL_PROP_PROCESS_CREATE_BACKGROUND_BOOLEAN`]\: true if the process should
230 /// run in the background. In this case the default input and output is
231 /// [`SDL_PROCESS_STDIO_NULL`] and the exitcode of the process is not
232 /// available, and will always be 0.
233 /// - [`SDL_PROP_PROCESS_CREATE_CMDLINE_STRING`]\: a string containing the program
234 /// to run and any parameters. This string is passed directly to
235 /// `CreateProcess` on Windows, and does nothing on other platforms. This
236 /// property is only important if you want to start programs that does
237 /// non-standard command-line processing, and in most cases using
238 /// [`SDL_PROP_PROCESS_CREATE_ARGS_POINTER`] is sufficient.
239 ///
240 /// On POSIX platforms, wait() and waitpid(-1, ...) should not be called, and
241 /// SIGCHLD should not be ignored or handled because those would prevent SDL
242 /// from properly tracking the lifetime of the underlying process. You should
243 /// use [`SDL_WaitProcess()`] instead.
244 ///
245 /// ## Parameters
246 /// - `props`: the properties to use.
247 ///
248 /// ## Return value
249 /// Returns the newly created and running process, or NULL if the process
250 /// couldn't be created.
251 ///
252 /// ## Thread safety
253 /// It is safe to call this function from any thread.
254 ///
255 /// ## Availability
256 /// This function is available since SDL 3.2.0.
257 ///
258 /// ## See also
259 /// - [`SDL_CreateProcess`]
260 /// - [`SDL_GetProcessProperties`]
261 /// - [`SDL_ReadProcess`]
262 /// - [`SDL_GetProcessInput`]
263 /// - [`SDL_GetProcessOutput`]
264 /// - [`SDL_KillProcess`]
265 /// - [`SDL_WaitProcess`]
266 /// - [`SDL_DestroyProcess`]
267 pub fn SDL_CreateProcessWithProperties(props: SDL_PropertiesID) -> *mut SDL_Process;
268}
269
270pub const SDL_PROP_PROCESS_CREATE_ARGS_POINTER: *const ::core::ffi::c_char =
271 c"SDL.process.create.args".as_ptr();
272
273pub const SDL_PROP_PROCESS_CREATE_ENVIRONMENT_POINTER: *const ::core::ffi::c_char =
274 c"SDL.process.create.environment".as_ptr();
275
276pub const SDL_PROP_PROCESS_CREATE_WORKING_DIRECTORY_STRING: *const ::core::ffi::c_char =
277 c"SDL.process.create.working_directory".as_ptr();
278
279pub const SDL_PROP_PROCESS_CREATE_STDIN_NUMBER: *const ::core::ffi::c_char =
280 c"SDL.process.create.stdin_option".as_ptr();
281
282pub const SDL_PROP_PROCESS_CREATE_STDIN_POINTER: *const ::core::ffi::c_char =
283 c"SDL.process.create.stdin_source".as_ptr();
284
285pub const SDL_PROP_PROCESS_CREATE_STDOUT_NUMBER: *const ::core::ffi::c_char =
286 c"SDL.process.create.stdout_option".as_ptr();
287
288pub const SDL_PROP_PROCESS_CREATE_STDOUT_POINTER: *const ::core::ffi::c_char =
289 c"SDL.process.create.stdout_source".as_ptr();
290
291pub const SDL_PROP_PROCESS_CREATE_STDERR_NUMBER: *const ::core::ffi::c_char =
292 c"SDL.process.create.stderr_option".as_ptr();
293
294pub const SDL_PROP_PROCESS_CREATE_STDERR_POINTER: *const ::core::ffi::c_char =
295 c"SDL.process.create.stderr_source".as_ptr();
296
297pub const SDL_PROP_PROCESS_CREATE_STDERR_TO_STDOUT_BOOLEAN: *const ::core::ffi::c_char =
298 c"SDL.process.create.stderr_to_stdout".as_ptr();
299
300pub const SDL_PROP_PROCESS_CREATE_BACKGROUND_BOOLEAN: *const ::core::ffi::c_char =
301 c"SDL.process.create.background".as_ptr();
302
303pub const SDL_PROP_PROCESS_CREATE_CMDLINE_STRING: *const ::core::ffi::c_char =
304 c"SDL.process.create.cmdline".as_ptr();
305
306unsafe extern "C" {
307 /// Get the properties associated with a process.
308 ///
309 /// The following read-only properties are provided by SDL:
310 ///
311 /// - [`SDL_PROP_PROCESS_PID_NUMBER`]\: the process ID of the process.
312 /// - [`SDL_PROP_PROCESS_STDIN_POINTER`]\: an [`SDL_IOStream`] that can be used to
313 /// write input to the process, if it was created with
314 /// [`SDL_PROP_PROCESS_CREATE_STDIN_NUMBER`] set to [`SDL_PROCESS_STDIO_APP`].
315 /// - [`SDL_PROP_PROCESS_STDOUT_POINTER`]\: a non-blocking [`SDL_IOStream`] that can
316 /// be used to read output from the process, if it was created with
317 /// [`SDL_PROP_PROCESS_CREATE_STDOUT_NUMBER`] set to [`SDL_PROCESS_STDIO_APP`].
318 /// - [`SDL_PROP_PROCESS_STDERR_POINTER`]\: a non-blocking [`SDL_IOStream`] that can
319 /// be used to read error output from the process, if it was created with
320 /// [`SDL_PROP_PROCESS_CREATE_STDERR_NUMBER`] set to [`SDL_PROCESS_STDIO_APP`].
321 /// - [`SDL_PROP_PROCESS_BACKGROUND_BOOLEAN`]\: true if the process is running in
322 /// the background.
323 ///
324 /// ## Parameters
325 /// - `process`: the process to query.
326 ///
327 /// ## Return value
328 /// Returns a valid property ID on success or 0 on failure; call
329 /// [`SDL_GetError()`] for more information.
330 ///
331 /// ## Thread safety
332 /// It is safe to call this function from any thread.
333 ///
334 /// ## Availability
335 /// This function is available since SDL 3.2.0.
336 ///
337 /// ## See also
338 /// - [`SDL_CreateProcess`]
339 /// - [`SDL_CreateProcessWithProperties`]
340 pub fn SDL_GetProcessProperties(process: *mut SDL_Process) -> SDL_PropertiesID;
341}
342
343pub const SDL_PROP_PROCESS_PID_NUMBER: *const ::core::ffi::c_char = c"SDL.process.pid".as_ptr();
344
345pub const SDL_PROP_PROCESS_STDIN_POINTER: *const ::core::ffi::c_char =
346 c"SDL.process.stdin".as_ptr();
347
348pub const SDL_PROP_PROCESS_STDOUT_POINTER: *const ::core::ffi::c_char =
349 c"SDL.process.stdout".as_ptr();
350
351pub const SDL_PROP_PROCESS_STDERR_POINTER: *const ::core::ffi::c_char =
352 c"SDL.process.stderr".as_ptr();
353
354pub const SDL_PROP_PROCESS_BACKGROUND_BOOLEAN: *const ::core::ffi::c_char =
355 c"SDL.process.background".as_ptr();
356
357unsafe extern "C" {
358 /// Read all the output from a process.
359 ///
360 /// If a process was created with I/O enabled, you can use this function to
361 /// read the output. This function blocks until the process is complete,
362 /// capturing all output, and providing the process exit code.
363 ///
364 /// The data is allocated with a zero byte at the end (null terminated) for
365 /// convenience. This extra byte is not included in the value reported via
366 /// `datasize`.
367 ///
368 /// The data should be freed with [`SDL_free()`].
369 ///
370 /// ## Parameters
371 /// - `process`: The process to read.
372 /// - `datasize`: a pointer filled in with the number of bytes read, may be
373 /// NULL.
374 /// - `exitcode`: a pointer filled in with the process exit code if the
375 /// process has exited, may be NULL.
376 ///
377 /// ## Return value
378 /// Returns the data or NULL on failure; call [`SDL_GetError()`] for more
379 /// information.
380 ///
381 /// ## Thread safety
382 /// This function is not thread safe.
383 ///
384 /// ## Availability
385 /// This function is available since SDL 3.2.0.
386 ///
387 /// ## See also
388 /// - [`SDL_CreateProcess`]
389 /// - [`SDL_CreateProcessWithProperties`]
390 /// - [`SDL_DestroyProcess`]
391 pub fn SDL_ReadProcess(
392 process: *mut SDL_Process,
393 datasize: *mut ::core::primitive::usize,
394 exitcode: *mut ::core::ffi::c_int,
395 ) -> *mut ::core::ffi::c_void;
396}
397
398unsafe extern "C" {
399 /// Get the [`SDL_IOStream`] associated with process standard input.
400 ///
401 /// The process must have been created with [`SDL_CreateProcess()`] and pipe_stdio
402 /// set to true, or with [`SDL_CreateProcessWithProperties()`] and
403 /// [`SDL_PROP_PROCESS_CREATE_STDIN_NUMBER`] set to [`SDL_PROCESS_STDIO_APP`].
404 ///
405 /// Writing to this stream can return less data than expected if the process
406 /// hasn't read its input. It may be blocked waiting for its output to be read,
407 /// if so you may need to call [`SDL_GetProcessOutput()`] and read the output in
408 /// parallel with writing input.
409 ///
410 /// ## Parameters
411 /// - `process`: The process to get the input stream for.
412 ///
413 /// ## Return value
414 /// Returns the input stream or NULL on failure; call [`SDL_GetError()`] for more
415 /// information.
416 ///
417 /// ## Thread safety
418 /// It is safe to call this function from any thread.
419 ///
420 /// ## Availability
421 /// This function is available since SDL 3.2.0.
422 ///
423 /// ## See also
424 /// - [`SDL_CreateProcess`]
425 /// - [`SDL_CreateProcessWithProperties`]
426 /// - [`SDL_GetProcessOutput`]
427 pub fn SDL_GetProcessInput(process: *mut SDL_Process) -> *mut SDL_IOStream;
428}
429
430unsafe extern "C" {
431 /// Get the [`SDL_IOStream`] associated with process standard output.
432 ///
433 /// The process must have been created with [`SDL_CreateProcess()`] and pipe_stdio
434 /// set to true, or with [`SDL_CreateProcessWithProperties()`] and
435 /// [`SDL_PROP_PROCESS_CREATE_STDOUT_NUMBER`] set to [`SDL_PROCESS_STDIO_APP`].
436 ///
437 /// Reading from this stream can return 0 with [`SDL_GetIOStatus()`] returning
438 /// [`SDL_IO_STATUS_NOT_READY`] if no output is available yet.
439 ///
440 /// ## Parameters
441 /// - `process`: The process to get the output stream for.
442 ///
443 /// ## Return value
444 /// Returns the output stream or NULL on failure; call [`SDL_GetError()`] for more
445 /// information.
446 ///
447 /// ## Thread safety
448 /// It is safe to call this function from any thread.
449 ///
450 /// ## Availability
451 /// This function is available since SDL 3.2.0.
452 ///
453 /// ## See also
454 /// - [`SDL_CreateProcess`]
455 /// - [`SDL_CreateProcessWithProperties`]
456 /// - [`SDL_GetProcessInput`]
457 pub fn SDL_GetProcessOutput(process: *mut SDL_Process) -> *mut SDL_IOStream;
458}
459
460unsafe extern "C" {
461 /// Stop a process.
462 ///
463 /// ## Parameters
464 /// - `process`: The process to stop.
465 /// - `force`: true to terminate the process immediately, false to try to
466 /// stop the process gracefully. In general you should try to stop
467 /// the process gracefully first as terminating a process may
468 /// leave it with half-written data or in some other unstable
469 /// state.
470 ///
471 /// ## Return value
472 /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
473 /// information.
474 ///
475 /// ## Thread safety
476 /// This function is not thread safe.
477 ///
478 /// ## Availability
479 /// This function is available since SDL 3.2.0.
480 ///
481 /// ## See also
482 /// - [`SDL_CreateProcess`]
483 /// - [`SDL_CreateProcessWithProperties`]
484 /// - [`SDL_WaitProcess`]
485 /// - [`SDL_DestroyProcess`]
486 pub fn SDL_KillProcess(
487 process: *mut SDL_Process,
488 force: ::core::primitive::bool,
489 ) -> ::core::primitive::bool;
490}
491
492unsafe extern "C" {
493 /// Wait for a process to finish.
494 ///
495 /// This can be called multiple times to get the status of a process.
496 ///
497 /// The exit code will be the exit code of the process if it terminates
498 /// normally, a negative signal if it terminated due to a signal, or -255
499 /// otherwise. It will not be changed if the process is still running.
500 ///
501 /// If you create a process with standard output piped to the application
502 /// (`pipe_stdio` being true) then you should read all of the process output
503 /// before calling [`SDL_WaitProcess()`]. If you don't do this the process might be
504 /// blocked indefinitely waiting for output to be read and [`SDL_WaitProcess()`]
505 /// will never return true;
506 ///
507 /// ## Parameters
508 /// - `process`: The process to wait for.
509 /// - `block`: If true, block until the process finishes; otherwise, report
510 /// on the process' status.
511 /// - `exitcode`: a pointer filled in with the process exit code if the
512 /// process has exited, may be NULL.
513 ///
514 /// ## Return value
515 /// Returns true if the process exited, false otherwise.
516 ///
517 /// ## Thread safety
518 /// This function is not thread safe.
519 ///
520 /// ## Availability
521 /// This function is available since SDL 3.2.0.
522 ///
523 /// ## See also
524 /// - [`SDL_CreateProcess`]
525 /// - [`SDL_CreateProcessWithProperties`]
526 /// - [`SDL_KillProcess`]
527 /// - [`SDL_DestroyProcess`]
528 pub fn SDL_WaitProcess(
529 process: *mut SDL_Process,
530 block: ::core::primitive::bool,
531 exitcode: *mut ::core::ffi::c_int,
532 ) -> ::core::primitive::bool;
533}
534
535unsafe extern "C" {
536 /// Destroy a previously created process object.
537 ///
538 /// Note that this does not stop the process, just destroys the SDL object used
539 /// to track it. If you want to stop the process you should use
540 /// [`SDL_KillProcess()`].
541 ///
542 /// ## Parameters
543 /// - `process`: The process object to destroy.
544 ///
545 /// ## Thread safety
546 /// This function is not thread safe.
547 ///
548 /// ## Availability
549 /// This function is available since SDL 3.2.0.
550 ///
551 /// ## See also
552 /// - [`SDL_CreateProcess`]
553 /// - [`SDL_CreateProcessWithProperties`]
554 /// - [`SDL_KillProcess`]
555 pub fn SDL_DestroyProcess(process: *mut SDL_Process);
556}
557
558/// An opaque handle representing a system process.
559///
560/// ## Availability
561/// This datatype is available since SDL 3.2.0.
562///
563/// ## See also
564/// - [`SDL_CreateProcess`]
565#[repr(C)]
566pub struct SDL_Process {
567 _opaque: [::core::primitive::u8; 0],
568}
569
570#[cfg(doc)]
571use crate::everything::*;