author | MattD <mattd@symbian.org> |
Mon, 29 Mar 2010 15:05:52 +0100 | |
changeset 311 | 3b0e5fcfce37 |
parent 256 | ac7e607c7d30 |
permissions | -rw-r--r-- |
3 | 1 |
/* |
256
ac7e607c7d30
SF Bug 2000 - tidy up copyright dates
timothy.murphy@nokia.com
parents:
252
diff
changeset
|
2 |
* Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies). |
3 | 3 |
* All rights reserved. |
4 |
* This component and the accompanying materials are made available |
|
5 |
* under the terms of the License "Eclipse Public License v1.0" |
|
6 |
* which accompanies this distribution, and is available |
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 |
* |
|
9 |
* Initial Contributors: |
|
10 |
* Nokia Corporation - initial contribution. |
|
11 |
* |
|
12 |
* Contributors: |
|
13 |
* |
|
14 |
* Description: |
|
252
6846d05399b6
SF Bug 2000 - test code for commandline parsing.
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents:
3
diff
changeset
|
15 |
* This program reads from stdin into a "buffer" structure. It is designed to be |
6846d05399b6
SF Bug 2000 - test code for commandline parsing.
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents:
3
diff
changeset
|
16 |
* run from within valgrind to detect memory corruption errors. |
6846d05399b6
SF Bug 2000 - test code for commandline parsing.
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents:
3
diff
changeset
|
17 |
* The buffer is then written to /tmp/outfile where it can be compared |
6846d05399b6
SF Bug 2000 - test code for commandline parsing.
raptorbot <raptorbot@systemstesthead.symbian.intra>
parents:
3
diff
changeset
|
18 |
* with the input to determine if they are the same |
3 | 19 |
*/ |
20 |
||
21 |
||
22 |
||
23 |
||
24 |
#include <stdio.h> |
|
25 |
#include <string.h> |
|
26 |
#include "buffer.h" |
|
27 |
#include <unistd.h> |
|
28 |
||
29 |
#include <sys/types.h> |
|
30 |
#include <sys/stat.h> |
|
31 |
#include <fcntl.h> |
|
32 |
||
33 |
#define OSIZE 40 |
|
34 |
#define ISIZEMAX 2049 |
|
35 |
||
36 |
int main(int argc, char *argv[]) |
|
37 |
{ |
|
38 |
int nbytes = 0; |
|
39 |
byteblock *bb=NULL; |
|
40 |
buffer *b; |
|
41 |
char *pointertospace = NULL; |
|
42 |
int iterator = 0; |
|
43 |
int ofile; |
|
44 |
unsigned int space=51; |
|
45 |
||
46 |
b = buffer_new(); |
|
47 |
||
48 |
do { |
|
49 |
// space %= 5; |
|
50 |
// space++; |
|
51 |
pointertospace = buffer_makespace(b, space); |
|
52 |
if (!pointertospace) |
|
53 |
exit(1); |
|
54 |
||
55 |
nbytes = read(STDIN_FILENO, pointertospace, space); |
|
56 |
if (nbytes == -1) |
|
57 |
break; |
|
58 |
||
59 |
buffer_usespace(b, nbytes); |
|
60 |
} |
|
61 |
while (nbytes == space); |
|
62 |
||
63 |
iterator = 0; |
|
64 |
ofile = open("/tmp/outfile", O_CREAT | O_WRONLY, 00777); |
|
65 |
||
66 |
if (ofile <= 0) |
|
67 |
{ |
|
68 |
perror("error"); |
|
69 |
return 1; |
|
70 |
} |
|
71 |
||
72 |
while ((bb = buffer_getbytes(b, &iterator))) |
|
73 |
{ |
|
74 |
write(ofile, &bb->byte0, bb->fill); |
|
75 |
} |
|
76 |
close(ofile); |
|
77 |
||
78 |
buffer_free(&b); |
|
79 |
return 0; |
|
80 |
} |