aboutsummaryrefslogtreecommitdiffstats
path: root/man/zsave.3
blob: fc1cdf9db51034eb531daef6f76183b5dfea3e98 (plain) (blame)
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
.TH ZSAVE 3 libzahl
.SH NAME
zsave - Marshal a big integer into a buffer
.SH SYNOPSIS
.nf
#include <zahl.h>

size_t zsave(z_t \fIa\fP, void *\fIbuf\fP);
.fi
.SH DESCRIPTION
.B zsave
marshals
.I a
into the buffer
.IR buf
unless
.IR buf
is
.IR 0 .
The data stored is not necessarily transferable
between machines or between different versions
of libzahl. For such use,
use
.BR zstr (3)
instead.
.P
Upon successful completion,
.I (*(int*)buf)
will always be either -1, 0, or 1.
.SH RETURN VALUE
The number of bytes written to
.IR buf ,
or the number bytes that would have been written if
.IR buf
was not
.IR 0 .
.SH ERRORS
This function cannot detect failure.
.SH EXAMPLE
.nf
#include <zahl.h>
#include <stdlib.h>

int buffer_z(z_t num, char **buf, size_t *off) {
	size_t n = zsave(num, 0);
	char *new = realloc(*buf, *off + n);
	if (!new) {
		return -1;
	}
	*buf = new;
	assert(zsave(num, *buf + *off) == n);
	*off += n;
	return 0;
}
.fi
.SH RATIONALE
This makes it possible to fork a process and send
result between the parent and the child, as long as
none of the process re-execute themself.
.B zsave
is much faster than
.BR zstr (3).
.SH SEE ALSO
.BR zload (3),
.BR zstr (3)