goat3d

diff src/chunk.cc @ 13:798df5111b56

moving slowly onwards
author John Tsiombikas <nuclear@member.fsf.org>
date Tue, 10 Sep 2013 15:29:45 +0300
parents
children 6b651613bd9f
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/chunk.cc	Tue Sep 10 15:29:45 2013 +0300
     1.3 @@ -0,0 +1,32 @@
     1.4 +#include "goat3d.h"
     1.5 +#include "chunk.h"
     1.6 +
     1.7 +ChunkHeader chunk_header(int id)
     1.8 +{
     1.9 +	ChunkHeader hdr;
    1.10 +	hdr.id = id;
    1.11 +	hdr.size = sizeof hdr;
    1.12 +	return hdr;
    1.13 +}
    1.14 +
    1.15 +bool write_chunk_header(const ChunkHeader *hdr, goat3d_io *io)
    1.16 +{
    1.17 +	io->seek(-hdr->size, SEEK_CUR, io->cls);
    1.18 +	if(io->write(hdr, sizeof *hdr, io->cls) < (ssize_t)sizeof *hdr) {
    1.19 +		return false;
    1.20 +	}
    1.21 +	return true;
    1.22 +}
    1.23 +
    1.24 +bool read_chunk_header(ChunkHeader *hdr, goat3d_io *io)
    1.25 +{
    1.26 +	if(io->read(hdr, sizeof *hdr, io->cls) < (ssize_t)sizeof *hdr) {
    1.27 +		return false;
    1.28 +	}
    1.29 +	return true;
    1.30 +}
    1.31 +
    1.32 +void skip_chunk(const ChunkHeader *hdr, goat3d_io *io)
    1.33 +{
    1.34 +	io->seek(hdr->size - sizeof *hdr, SEEK_CUR, io->cls);
    1.35 +}