X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=libs%2Fgoat3d%2Fsrc%2Fchunk.c;fp=libs%2Fgoat3d%2Fsrc%2Fchunk.c;h=9043357e4ce322e3c13146bdeaaf0dd0b485eaec;hb=487d801f62b3f7cea009b5e560cfd06e57170970;hp=0000000000000000000000000000000000000000;hpb=103b67f9f1e041dc5f6ffbb59004ebe846e3f3f9;p=deeprace diff --git a/libs/goat3d/src/chunk.c b/libs/goat3d/src/chunk.c new file mode 100644 index 0000000..9043357 --- /dev/null +++ b/libs/goat3d/src/chunk.c @@ -0,0 +1,47 @@ +/* +goat3d - 3D scene, and animation file format library. +Copyright (C) 2013-2018 John Tsiombikas + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with this program. If not, see . +*/ +#include "goat3d.h" +#include "chunk.h" + +void g3dimpl_chunk_header(struct chunk_header *hdr, int id) +{ + hdr->id = id; + hdr->size = sizeof *hdr; +} + +int g3dimpl_write_chunk_header(const struct chunk_header *hdr, struct goat3d_io *io) +{ + io->seek(-(long)hdr->size, SEEK_CUR, io->cls); + if(io->write(hdr, sizeof *hdr, io->cls) < (long)sizeof *hdr) { + return -1; + } + return 0; +} + +int g3dimpl_read_chunk_header(struct chunk_header *hdr, struct goat3d_io *io) +{ + if(io->read(hdr, sizeof *hdr, io->cls) < (long)sizeof *hdr) { + return -1; + } + return 0; +} + +void g3dimpl_skip_chunk(const struct chunk_header *hdr, struct goat3d_io *io) +{ + io->seek(hdr->size - sizeof *hdr, SEEK_CUR, io->cls); +}