/* **************************************************************************** * mcsfile/mcsfile.h -- MCS file internals. * Copyright (C) 2017 Thomas "Cakeisalie5" Touhey * * This file is part of libcasio. * libcasio 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.0 of the License, * or (at your option) any later version. * * libcasio 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 libcasio; if not, see . * ************************************************************************* */ #ifndef LOCAL_MCSFILE_H # define LOCAL_MCSFILE_H 1 # include "../internals.h" /* --- * Macros for interacting with the buffer. * --- */ /* Read from a stream. */ # define READ(CASIO__TO, CASIO__SZ) /* normal read */ { \ int READ_err = tio_read(buffer, (CASIO__TO), (CASIO__SZ)); \ if (READ_err) return (READ_err); } # define FREAD(CASIO__TO, CASIO__SZ) /* fail-less read */ \ err = tio_read(buffer, (CASIO__TO), (CASIO__SZ)); # define GREAD(CASIO__TO, CASIO__SZ) /* read with goto fail */ \ if ((err = tio_read(buffer, (CASIO__TO), (CASIO__SZ)))) \ goto fail; /* Read using size of the object. */ # define DREAD(CASIO__TO) \ READ(&CASIO__TO, sizeof(CASIO__TO)) # define GDREAD(CASIO__TO) \ GREAD(&CASIO__TO, sizeof(CASIO__TO)) /* Skip. */ # define SKIP(CASIO__SZ) { \ int SKIP_err = tio_skip(buffer, (CASIO__SZ)); \ if (SKIP_err) \ return (SKIP_err); } # define GSKIP(CASIO__SZ) { \ err = tio_skip(buffer, (CASIO__SZ)); \ if (err) \ goto fail; } /* Write. */ # define WRITE(CASIO__BUF, CASIO__SZ) { \ int WRITE_err = tio_write(buffer, (CASIO__BUF), (CASIO__SZ), 0); \ if (WRITE_err) \ return (WRITE_err); } # define DWRITE(CASIO__OBJECT) \ WRITE(&(CASIO__OBJECT), sizeof(CASIO__OBJECT)) #endif