goat3d

annotate 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
rev   line source
nuclear@13 1 #include "goat3d.h"
nuclear@13 2 #include "chunk.h"
nuclear@13 3
nuclear@13 4 ChunkHeader chunk_header(int id)
nuclear@13 5 {
nuclear@13 6 ChunkHeader hdr;
nuclear@13 7 hdr.id = id;
nuclear@13 8 hdr.size = sizeof hdr;
nuclear@13 9 return hdr;
nuclear@13 10 }
nuclear@13 11
nuclear@13 12 bool write_chunk_header(const ChunkHeader *hdr, goat3d_io *io)
nuclear@13 13 {
nuclear@13 14 io->seek(-hdr->size, SEEK_CUR, io->cls);
nuclear@13 15 if(io->write(hdr, sizeof *hdr, io->cls) < (ssize_t)sizeof *hdr) {
nuclear@13 16 return false;
nuclear@13 17 }
nuclear@13 18 return true;
nuclear@13 19 }
nuclear@13 20
nuclear@13 21 bool read_chunk_header(ChunkHeader *hdr, goat3d_io *io)
nuclear@13 22 {
nuclear@13 23 if(io->read(hdr, sizeof *hdr, io->cls) < (ssize_t)sizeof *hdr) {
nuclear@13 24 return false;
nuclear@13 25 }
nuclear@13 26 return true;
nuclear@13 27 }
nuclear@13 28
nuclear@13 29 void skip_chunk(const ChunkHeader *hdr, goat3d_io *io)
nuclear@13 30 {
nuclear@13 31 io->seek(hdr->size - sizeof *hdr, SEEK_CUR, io->cls);
nuclear@13 32 }