packrat.c
// Append placeholder entry to a Pack Rat Zero archive
Append placeholder entry to a Pack Rat Zero archive
Append placeholder entry to a Pack Rat Zero archive
static int packrat_write_zero_placeholder(const char * const pathPri, const int bitsPos, const int bitsLen) {
	const int pri = open(pathPri, O_WRONLY | O_APPEND);
	if (pri < 0) return PACKRAT_ERROR_OPEN;
	if (flock(pri, LOCK_EX) != 0) {close(pri); return PACKRAT_ERROR_LOCK;}
	const int infoBytes = bytesInBits(bitsPos + bitsLen, bytesInBits_UP);
	const int id = (lseek(pri, 0, SEEK_END) - 5) / infoBytes; 
	char zeroes[infoBytes];
	bzero(zeroes, infoBytes);
	const int ret = write(pri, zeroes, infoBytes);
	flock(pri, LOCK_UN);
	close(pri);
	return (ret == infoBytes) ? id : PACKRAT_ERROR_READWRITE;
}
static int packrat_write_zero_placeholder ( const char * const pathPri , const int bitsPos , const int bitsLen ) { const int pri = open ( pathPri , O_WRONLY | O_APPEND ) ; if ( pri < 0 ) return PACKRAT_ERROR_OPEN ; if ( flock ( pri , LOCK_EX ) != 0 ) { close ( pri ) ; return PACKRAT_ERROR_LOCK ; } const int infoBytes = bytesInBits ( bitsPos + bitsLen , bytesInBits_UP ) ; const int id = ( lseek ( pri , 0 , SEEK_END ) - 5 ) / infoBytes ; char zeroes [ infoBytes ] ; bzero ( zeroes , infoBytes ) ; const int ret = write ( pri , zeroes , infoBytes ) ; flock ( pri , LOCK_UN ) ; close ( pri ) ; return ( ret == infoBytes ) ? id : PACKRAT_ERROR_READWRITE ; }
Append placeholder entry to a Pack Rat Zero archive
Append placeholder entry to a Pack Rat Zero archive
// Ignore first five bytes (the file header)