1 /* SPDX-License-Identifier: MIT */
5 * Copyright (c) 2018 Red Hat, Inc.
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
28 bool slirp_istream_read(SlirpIStream *f, void *buf, size_t size)
30 return f->read_cb(buf, size, f->opaque) == size;
33 bool slirp_ostream_write(SlirpOStream *f, const void *buf, size_t size)
35 return f->write_cb(buf, size, f->opaque) == size;
38 uint8_t slirp_istream_read_u8(SlirpIStream *f)
42 if (slirp_istream_read(f, &b, sizeof(b))) {
49 bool slirp_ostream_write_u8(SlirpOStream *f, uint8_t b)
51 return slirp_ostream_write(f, &b, sizeof(b));
54 uint16_t slirp_istream_read_u16(SlirpIStream *f)
58 if (slirp_istream_read(f, &b, sizeof(b))) {
59 return GUINT16_FROM_BE(b);
65 bool slirp_ostream_write_u16(SlirpOStream *f, uint16_t b)
68 return slirp_ostream_write(f, &b, sizeof(b));
71 uint32_t slirp_istream_read_u32(SlirpIStream *f)
75 if (slirp_istream_read(f, &b, sizeof(b))) {
76 return GUINT32_FROM_BE(b);
82 bool slirp_ostream_write_u32(SlirpOStream *f, uint32_t b)
85 return slirp_ostream_write(f, &b, sizeof(b));
88 int16_t slirp_istream_read_i16(SlirpIStream *f)
92 if (slirp_istream_read(f, &b, sizeof(b))) {
93 return GINT16_FROM_BE(b);
99 bool slirp_ostream_write_i16(SlirpOStream *f, int16_t b)
102 return slirp_ostream_write(f, &b, sizeof(b));
105 int32_t slirp_istream_read_i32(SlirpIStream *f)
109 if (slirp_istream_read(f, &b, sizeof(b))) {
110 return GINT32_FROM_BE(b);
116 bool slirp_ostream_write_i32(SlirpOStream *f, int32_t b)
119 return slirp_ostream_write(f, &b, sizeof(b));