summaryrefslogtreecommitdiff
path: root/man/mpu_popen.3
blob: ed0fd7581ab7129cf2001ab74687658abffb3f61 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
.TH MPU_POPEN 3 "August 2026" "libmpuio" "LIBMPUIO Programmer's Manual"
.SH NAME
mpu_popen, mpu_pclose \- open and close a LIBMPUIO command pipe
.SH SYNOPSIS
.nf
#include <libmpuio.h>

mpu_FILE *mpu_popen( const char *command, const char *mode );
int       mpu_pclose( mpu_FILE *stream );
.fi
.SH DESCRIPTION
.B mpu_popen
starts
.I command
through
.B /bin/sh -c
and returns a unidirectional descriptor-backed LIBMPUIO stream.
The mode is exactly
.B "r"
for reading the command's standard output or
.B "w"
for writing the command's standard input.
.PP
Text operations retain the normal LIBMPUIO boundary: data in the stream is
UCS-2 and the pipe carries external UTF-8 bytes.  Raw
.BR mpu_fread (3)
and
.BR mpu_fwrite (3)
operate directly on pipe bytes.
.PP
.B mpu_pclose
flushes and closes a stream created by
.BR mpu_popen ,
then waits for the command process to terminate.  A command stream must be
finalized with mpu_pclose(), not detached with mpu_freopen() or finalized with
mpu_fclose(), because mpu_pclose() performs the required wait for the child.
.SH RETURN VALUE
.B mpu_popen
returns a stream pointer on success and NULL on failure.
.B mpu_pclose
returns the child wait status on success, or -1 on failure with
.B errno
set.  The status can be examined with the macros described by
.BR waitpid (2).
.SH ERRORS
.B EINVAL
is reported for a NULL command, an unsupported mode, or an attempt to call
.B mpu_pclose
on a stream not created by
.BR mpu_popen .
.BR mpu_freopen (3)
also reports EINVAL when passed a command-pipe stream.
.SH NOTES
The command string is interpreted by the shell and follows normal shell
quoting and expansion rules.  Do not construct it from untrusted text without
appropriate validation or quoting.
.PP
Only the POSIX unidirectional
.B r
and
.B w
modes are supported.  The parent pipe endpoint is close-on-exec so previously
opened command streams are not leaked into subsequently executed commands.
.SH EXAMPLE
.nf
mpu_FILE       *fp = mpu_popen( "printf 'hello\\n'", "r" );
__mpu_char16_t  line[32];
int             status;

if( fp != NULL )
{
  mpu_fgets( line, 32, fp );
  status = mpu_pclose( fp );
}
.fi
.SH SEE ALSO
.BR libmpuio (3),
.BR mpu_fopen (3),
.BR mpu_fclose (3),
.BR mpu_fread (3),
.BR mpu_fwrite (3),
.BR waitpid (2)