File: nbdkit_parse_int.pod

package info (click to toggle)
nbdkit 1.42.6-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 14,700 kB
  • sloc: ansic: 59,169; sh: 16,858; makefile: 6,452; python: 1,837; cpp: 1,116; perl: 502; ml: 498; tcl: 62
file content (81 lines) | stat: -rw-r--r-- 2,534 bytes parent folder | download | duplicates (2)
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
=head1 NAME

nbdkit_parse_int, nbdkit_parse_unsigned,
nbdkit_parse_int8_t, nbdkit_parse_int16_t,
nbdkit_parse_int32_t, nbdkit_parse_int64_t,
nbdkit_parse_uint8_t, nbdkit_parse_uint16_t,
nbdkit_parse_uint32_t, nbdkit_parse_uint64_t - parse numbers for nbdkit

=head1 SYNOPSIS

 #include <nbdkit-plugin.h>

 int nbdkit_parse_int (const char *what, const char *str, int *r);
 int nbdkit_parse_unsigned (const char *what,
                            const char *str, unsigned *r);
 int nbdkit_parse_int8_t (const char *what,
                          const char *str, int8_t *r);
 int nbdkit_parse_uint8_t (const char *what,
                           const char *str, uint8_t *r);
 int nbdkit_parse_int16_t (const char *what,
                           const char *str, int16_t *r);
 int nbdkit_parse_uint16_t (const char *what,
                            const char *str, uint16_t *r);
 int nbdkit_parse_int32_t (const char *what,
                           const char *str, int32_t *r);
 int nbdkit_parse_uint32_t (const char *what,
                            const char *str, uint32_t *r);
 int nbdkit_parse_int64_t (const char *what,
                           const char *str, int64_t *r);
 int nbdkit_parse_uint64_t (const char *what,
                            const char *str, uint64_t *r);

=head1 DESCRIPTION

Parse string C<str> into an integer of various types.  These functions
parse a decimal, hexadecimal (C<"0x...">) or octal (C<"0...">) number.

These functions deal correctly with overflow, out of range and parse
errors, and you should use them instead of unsafe functions like
L<sscanf(3)>, L<atoi(3)> and similar.

The C<what> parameter is printed in error messages to provide context.
It should usually be a short descriptive string of what you are trying
to parse, eg:

 if (nbdkit_parse_int ("random seed", value, &seed) == -1)
   return -1;

might print an error:

 random seed: could not parse number: "lalala"

=head1 RETURN VALUE

On success the functions return C<0> and set C<*r> to the parsed value
(unless C<*r == NULL> in which case the result is discarded).

On error, L<nbdkit_error(3)> is called and the functions return C<-1>.
On error C<*r> is always unchanged.

=head1 HISTORY

C<nbdkit_parse_int> and the others were added in nbdkit 1.16.

=head1 SEE ALSO

L<nbdkit(1)>,
L<nbdkit_parse_bool(3)>,
L<nbdkit_parse_delay(3)>,
L<nbdkit_parse_probability(3)>,
L<nbdkit_parse_size(3)>,
L<nbdkit-plugin(3)>,
L<nbdkit-filter(3)>.

=head1 AUTHORS

Richard W.M. Jones

=head1 COPYRIGHT

Copyright Red Hat