]> code.delx.au - pulseaudio/blob - src/tests/stripnul.c
2f87e877631bbf6a48c2f16b28e49a8609cd01d6
[pulseaudio] / src / tests / stripnul.c
1 /* $Id$ */
2
3 /***
4 This file is part of PulseAudio.
5
6 PulseAudio is free software; you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as published
8 by the Free Software Foundation; either version 2 of the License,
9 or (at your option) any later version.
10
11 PulseAudio is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public License
17 along with PulseAudio; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19 USA.
20 ***/
21
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
25
26 #include <stdio.h>
27 #include <string.h>
28 #include <inttypes.h>
29
30 #include <pulse/xmalloc.h>
31 #include <pulsecore/macro.h>
32
33 int main(int argc, char *argv[]) {
34 FILE *i, *o;
35 size_t granularity;
36 pa_bool_t found;
37 uint8_t *zero;
38
39 pa_assert_se(argc >= 2);
40 pa_assert_se((granularity = atoi(argv[1])) >= 1);
41 pa_assert_se((i = (argc >= 3) ? fopen(argv[2], "r") : stdin));
42 pa_assert_se((o = (argc >= 4) ? fopen(argv[3], "w") : stdout));
43
44 zero = pa_xmalloc0(granularity);
45
46 for (;;) {
47 uint8_t buffer[16*1024], *p;
48 size_t k;
49
50 k = fread(buffer, granularity, sizeof(buffer)/granularity, i);
51
52 if (k <= 0)
53 break;
54
55 if (found)
56 pa_assert_se(fwrite(buffer, granularity, k, o) == k);
57 else {
58 for (p = buffer; (p-buffer)/granularity < k; p += granularity)
59 if (memcmp(p, zero, granularity)) {
60 size_t left;
61 found = TRUE;
62 left = k - (p-buffer)/granularity;
63 pa_assert_se(fwrite(p, granularity, left, o) == left);
64 break;
65 }
66 }
67 }
68
69 fflush(o);
70
71 return 0;
72 }