4 * $author: Salvatore Sanfilippo <antirez@invece.org>$
5 * $copyright: Copyright (C) 1999 by Salvatore Sanfilippo$
6 * $license: This software is under GPL version 2 of license$
7 * $date: Fri Nov 5 11:55:47 MET 1999$
11 /* $Id: datafiller.c,v 1.2 2003/09/01 00:22:06 antirez Exp $ */
16 #include <sys/types.h>
19 #include <string.h> /* memset */
24 void datafiller(char *p, int size)
30 fd = open(datafilename, O_RDONLY);
32 perror("[datafiller] open()");
33 fd = 0; /* will retry to open the file for
40 if (p == NULL && fd != -1) { /* seek operation */
41 /* size-1 because packet with id 1 start from 0 */
42 lseek(fd, (data_size-signlen)*(size-1), SEEK_SET);
46 restart: /* if EOF occurs, after rewind, restart */
48 readed = read(fd, p, size);
51 else if (readed == -1) {
52 perror("[datafiller] read()");
54 fd = 0; /* will retry to open the file for the next packet */
58 else if (readed < size && opt_end == FALSE) {
59 lseek(fd, 0, SEEK_SET);
63 else if (readed < size && opt_end == TRUE) {
64 fprintf(stderr, "EOF reached, wait some second than press "
68 printf("[datafiller.c INTERNAL ERROR] readed = %d - "
69 "opt_end == %d\n", readed, opt_end);
73 memset(p+readed, '\0', diff); /* padding */
74 lseek(fd, 0, SEEK_SET);