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/stream/open_serial.c

66 lines
2.0 KiB
C

/* ****************************************************************************
* stream/open_serial.c -- open a serial stream.
* Copyright (C) 2017-2018 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/>.
* ************************************************************************* */
#include "stream.h"
#if !defined(LIBCASIO_DISABLED_STREAMS)
# define OSF &casio_open_streams_serial
#elif !defined(LIBCASIO_DISABLED_WINDOWS)
# define OSF &casio_open_windows_serial
#else
# define OSF NULL
#endif
CASIO_LOCAL casio_open_serial_stream_t *open_serial_stream_func = OSF;
/**
* casio_set_open_serial_stream_func:
* Set the serial streams opener.
*
* NULL resets the function to its default.
*
* @arg function the function pointer to set.
* @return the error code (0 if ok).
*/
int CASIO_EXPORT casio_set_open_serial_stream_func(
casio_open_serial_stream_t *func)
{
open_serial_stream_func = func ? func : OSF;
return (0);
}
/**
* casio_open_serial_stream:
* Open the serial stream.
*
* @arg streamp the stream to make.
* @arg path the serial device path.
* @arg attrs the serial attributes.
* @return the error code (0 if ok).
*/
int CASIO_EXPORT casio_open_serial_stream(casio_stream_t **streamp,
char const *path, casio_streamattrs_t const *attrs)
{
if (!open_serial_stream_func)
return (casio_error_op);
return ((*open_serial_stream_func)(streamp, path, attrs));
}