cake
/
libcasio
Archived
1
1
Fork 0
This repository has been archived on 2024-03-16. You can view files and clone it, but cannot push or open issues or pull requests.
libcasio/lib/mcsfile/mcsfile.h

66 lines
2.1 KiB
C
Raw Normal View History

2017-06-12 01:06:23 +02:00
/* ****************************************************************************
* mcsfile/mcsfile.h -- MCS file internals.
* Copyright (C) 2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
*
* 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 <http://www.gnu.org/licenses/>.
* ************************************************************************* */
#ifndef LOCAL_MCSFILE_H
# define LOCAL_MCSFILE_H 1
# include "../internals.h"
/* ---
* Macros for interacting with the buffer.
* --- */
2017-06-12 01:06:23 +02:00
/* Read from a stream. */
2017-06-12 01:06:23 +02:00
# define READ(CASIO__TO, CASIO__SZ) /* normal read */ { \
2019-04-10 08:08:38 +02:00
int READ_err = tio_read(buffer, (CASIO__TO), (CASIO__SZ)); \
2017-06-12 01:06:23 +02:00
if (READ_err) return (READ_err); }
# define FREAD(CASIO__TO, CASIO__SZ) /* fail-less read */ \
2019-04-10 08:08:38 +02:00
err = tio_read(buffer, (CASIO__TO), (CASIO__SZ));
2017-06-12 01:06:23 +02:00
# define GREAD(CASIO__TO, CASIO__SZ) /* read with goto fail */ \
2019-04-10 08:08:38 +02:00
if ((err = tio_read(buffer, (CASIO__TO), (CASIO__SZ)))) \
2017-06-12 01:06:23 +02:00
goto fail;
/* Read using size of the object. */
2017-06-12 01:06:23 +02:00
# define DREAD(CASIO__TO) \
READ(&CASIO__TO, sizeof(CASIO__TO))
# define GDREAD(CASIO__TO) \
GREAD(&CASIO__TO, sizeof(CASIO__TO))
/* Skip. */
2017-06-12 01:06:23 +02:00
# define SKIP(CASIO__SZ) { \
2019-04-10 08:08:38 +02:00
int SKIP_err = tio_skip(buffer, (CASIO__SZ)); \
if (SKIP_err) \
return (SKIP_err); }
2017-06-12 01:06:23 +02:00
# define GSKIP(CASIO__SZ) { \
2019-04-10 08:08:38 +02:00
err = tio_skip(buffer, (CASIO__SZ)); \
if (err) \
goto fail; }
2017-06-12 01:06:23 +02:00
/* Write. */
2017-06-12 01:06:23 +02:00
# define WRITE(CASIO__BUF, CASIO__SZ) { \
2019-04-10 08:08:38 +02:00
int WRITE_err = tio_write(buffer, (CASIO__BUF), (CASIO__SZ), 0); \
if (WRITE_err) \
return (WRITE_err); }
2017-06-12 01:06:23 +02:00
# define DWRITE(CASIO__OBJECT) \
WRITE(&(CASIO__OBJECT), sizeof(CASIO__OBJECT))
2017-06-12 01:06:23 +02:00
#endif