# HG changeset patch # User John Tsiombikas # Date 1378816185 -10800 # Node ID 798df5111b560846b8c1213ef52bc5b686cfa3d8 # Parent be15ba7c5483fd0cc41a867e47bfe367c3d41799 moving slowly onwards diff -r be15ba7c5483 -r 798df5111b56 src/chunk.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/chunk.cc Tue Sep 10 15:29:45 2013 +0300 @@ -0,0 +1,32 @@ +#include "goat3d.h" +#include "chunk.h" + +ChunkHeader chunk_header(int id) +{ + ChunkHeader hdr; + hdr.id = id; + hdr.size = sizeof hdr; + return hdr; +} + +bool write_chunk_header(const ChunkHeader *hdr, goat3d_io *io) +{ + io->seek(-hdr->size, SEEK_CUR, io->cls); + if(io->write(hdr, sizeof *hdr, io->cls) < (ssize_t)sizeof *hdr) { + return false; + } + return true; +} + +bool read_chunk_header(ChunkHeader *hdr, goat3d_io *io) +{ + if(io->read(hdr, sizeof *hdr, io->cls) < (ssize_t)sizeof *hdr) { + return false; + } + return true; +} + +void skip_chunk(const ChunkHeader *hdr, goat3d_io *io) +{ + io->seek(hdr->size - sizeof *hdr, SEEK_CUR, io->cls); +} diff -r be15ba7c5483 -r 798df5111b56 src/chunk.h --- a/src/chunk.h Mon Aug 26 06:08:40 2013 +0300 +++ b/src/chunk.h Tue Sep 10 15:29:45 2013 +0300 @@ -115,5 +115,10 @@ }; +ChunkHeader chunk_header(int id); +bool write_chunk_header(const ChunkHeader *hdr, goat3d_io *io); +bool read_chunk_header(ChunkHeader *hdr, goat3d_io *io); +void skip_chunk(const ChunkHeader *hdr, goat3d_io *io); + #endif // CHUNK_H_ diff -r be15ba7c5483 -r 798df5111b56 src/goat3d.h --- a/src/goat3d.h Mon Aug 26 06:08:40 2013 +0300 +++ b/src/goat3d.h Tue Sep 10 15:29:45 2013 +0300 @@ -10,7 +10,7 @@ void *cls; /* closure data */ long (*read)(void *buf, size_t bytes, void *uptr); - long (*write)(void *buf, size_t bytes, void *uptr); + long (*write)(const void *buf, size_t bytes, void *uptr); long (*seek)(long offs, int whence, void *uptr); };