goat3d

changeset 13:798df5111b56

moving slowly onwards
author John Tsiombikas <nuclear@member.fsf.org>
date Tue, 10 Sep 2013 15:29:45 +0300
parents be15ba7c5483
children 188c697b3b49
files src/chunk.cc src/chunk.h src/goat3d.h
diffstat 3 files changed, 38 insertions(+), 1 deletions(-) [+]
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 +}
     2.1 --- a/src/chunk.h	Mon Aug 26 06:08:40 2013 +0300
     2.2 +++ b/src/chunk.h	Tue Sep 10 15:29:45 2013 +0300
     2.3 @@ -115,5 +115,10 @@
     2.4  };
     2.5  
     2.6  
     2.7 +ChunkHeader chunk_header(int id);
     2.8 +bool write_chunk_header(const ChunkHeader *hdr, goat3d_io *io);
     2.9 +bool read_chunk_header(ChunkHeader *hdr, goat3d_io *io);
    2.10 +void skip_chunk(const ChunkHeader *hdr, goat3d_io *io);
    2.11 +
    2.12  
    2.13  #endif	// CHUNK_H_
     3.1 --- a/src/goat3d.h	Mon Aug 26 06:08:40 2013 +0300
     3.2 +++ b/src/goat3d.h	Tue Sep 10 15:29:45 2013 +0300
     3.3 @@ -10,7 +10,7 @@
     3.4  	void *cls;	/* closure data */
     3.5  
     3.6  	long (*read)(void *buf, size_t bytes, void *uptr);
     3.7 -	long (*write)(void *buf, size_t bytes, void *uptr);
     3.8 +	long (*write)(const void *buf, size_t bytes, void *uptr);
     3.9  	long (*seek)(long offs, int whence, void *uptr);
    3.10  };
    3.11