/**********************************************************************
 
	Copyright (C) 2003 Hirohisa MORI <joshua@nichibun.ac.jp>
 
	This program is free software; you can redistribute it 
	and/or modify it under the terms of the GLOBALBASE 
	Library General Public License (G-LGPL) as published by 

	http://www.globalbase.org/
 
	This program is distributed in the hope that it will be 
	useful, but WITHOUT ANY WARRANTY; without even the 
	implied warranty of MERCHANTABILITY or FITNESS FOR A 
	PARTICULAR PURPOSE.

**********************************************************************/


#include	"machine/include.h"
#include	<stdio.h>
#include	<string.h>
#include	"r64.h"
#include	"r64_types.h"

int
_fill_background(R64_FILE * f,int len)
{
unsigned char buf[999];
int i;
int er;
int size1,size2;
	for ( i = 0 ; i < 333 ; i ++ )
		memcpy(&buf[3*i],f->background,3);
	er = 0;
	for ( ; er < len ; ) {
		size1 = len-er < 999 ? len-er : 999;
		size2 = write(f->fd,buf,size1);
		if ( size2 != size1 ) {
perror("fill_background");
			r64_error = E_SYS;
			return -1;
		}
		er += size1;
	}
	return 0;
}
