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/builtin/streams/settm.c

61 lines
1.8 KiB
C

/* ****************************************************************************
* stream/builtin/streams/settm.c -- set timeouts for a STREAMS stream.
* Copyright (C) 2016-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/>.
* ************************************************************************* */
#include "streams.h"
#ifndef LIBCASIO_DISABLED_STREAMS
/**
* casio_streams_settm:
* Set timeouts.
*
* @arg cookie the cookie.
* @arg timeouts the timeouts.
* @return the error code (0 if ok).
*/
int CASIO_EXPORT casio_streams_settm(streams_cookie_t *cookie,
const casio_timeouts_t *timeouts)
{
struct termios term;
/* Set on the read thing. */
if (!tcgetattr(cookie->_readfd, &term)) {
/* Set the timeout and update. */
term.c_cc[VTIME] = timeouts->casio_timeouts_read / 100;
if (tcsetattr(cookie->_readfd, TCSANOW, &term))
return (0);
}
/* Set on the write thing. */
if (cookie->_readfd != cookie->_writefd
&& !tcgetattr(cookie->_writefd, &term)) {
/* Set the timeout and update. */
term.c_cc[VTIME] = timeouts->casio_timeouts_write / 100;
if (tcsetattr(cookie->_writefd, TCSANOW, &term))
return (0);
}
return (0);
}
#endif