sbsv2/raptor/util/talon/testbuffer.c
changeset 2 39c28ec933dd
child 13 c327db0664bb
equal deleted inserted replaced
1:820b22e13ff1 2:39c28ec933dd
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     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: 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 #include <stdio.h>
       
    22 #include <string.h>
       
    23 #include "buffer.h"
       
    24 #include <unistd.h>
       
    25 
       
    26 #include <sys/types.h>
       
    27 #include <sys/stat.h>
       
    28 #include <fcntl.h>
       
    29 
       
    30 #define OSIZE 40
       
    31 #define ISIZEMAX 2049
       
    32 
       
    33 int main(int argc, char *argv[])
       
    34 {
       
    35 	int nbytes = 0;
       
    36 	byteblock *bb=NULL;
       
    37 	buffer *b;
       
    38 	char *pointertospace = NULL;
       
    39 	int iterator = 0;
       
    40 	int ofile;
       
    41 	unsigned int space=51;
       
    42 
       
    43 	b = buffer_new();
       
    44 
       
    45 	do {
       
    46 // space %= 5;
       
    47 //		space++;
       
    48 		pointertospace = buffer_makespace(b, space);
       
    49 		if (!pointertospace)
       
    50 			exit(1);
       
    51 
       
    52 		nbytes = read(STDIN_FILENO, pointertospace, space);
       
    53 		if (nbytes == -1)
       
    54 			break;
       
    55 
       
    56 		buffer_usespace(b, nbytes);
       
    57 	}
       
    58 	while (nbytes == space);
       
    59 
       
    60 	iterator = 0;
       
    61 	ofile = open("/tmp/outfile", O_CREAT | O_WRONLY, 00777);
       
    62 
       
    63 	if (ofile <= 0)
       
    64 	{
       
    65 		perror("error");
       
    66 		return 1;
       
    67 	}
       
    68 	
       
    69 	while ((bb = buffer_getbytes(b, &iterator)))
       
    70 	{
       
    71 		write(ofile, &bb->byte0, bb->fill);
       
    72 	}
       
    73 	close(ofile);
       
    74 
       
    75 	buffer_free(&b);
       
    76 	return 0;
       
    77 }