Rizin
unix-like reverse engineering framework and cli tools
transport.c
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2014-2017 LemonBoy <thatlemon@gmail.com>
2 // SPDX-License-Identifier: LGPL-3.0-only
3 
4 #include <rz_th.h>
5 #include "transport.h"
6 
7 io_desc_t *io_desc_new(io_backend_t *iob, void *fp) {
9  if (desc) {
10  desc->iob = iob;
11  desc->fp = fp;
12  }
13  return desc;
14 }
15 
17  uint32_t done;
18  static RzThreadLock *lock = NULL;
19  if (!lock) {
20  lock = rz_th_lock_new(true);
21  }
22  if (!desc || !desc->iob || !desc->fp) {
23  return E_NOIF;
24  }
26  for (done = 0; done < buf_len;) {
27  int ret = desc->iob->write(desc->fp, buf + done, buf_len - done, 100);
28  if (ret < 1) {
29  break;
30  }
31  done += ret;
32  }
34  return done;
35 }
36 
38  uint32_t done;
39  static RzThreadLock *lock = NULL;
40  if (!lock) {
41  lock = rz_th_lock_new(true);
42  }
43  if (!desc || !desc->iob || !desc->fp) {
44  return E_NOIF;
45  }
47  for (done = 0; done < buf_len;) {
48  int ret = desc->iob->read(desc->fp, buf + done, buf_len - done, 100);
49  if (ret < 0) {
50  break;
51  }
52  done += ret;
53  }
55  return done;
56 }
static int buf_len
Definition: asm_arc.c:22
const char * desc
Definition: bin_vsf.c:19
#define NULL
Definition: cris-opc.c:27
struct tab * done
Definition: enough.c:233
voidpf void * buf
Definition: ioapi.h:138
#define RZ_NEW0(x)
Definition: rz_types.h:284
unsigned int uint32_t
Definition: sftypes.h:29
unsigned char uint8_t
Definition: sftypes.h:31
RZ_API void rz_th_lock_leave(RZ_NONNULL RzThreadLock *thl)
Releases a RzThreadLock structure.
Definition: thread_lock.c:75
RZ_API RZ_OWN RzThreadLock * rz_th_lock_new(bool recursive)
Allocates and initialize a RzThreadLock structure.
Definition: thread_lock.c:14
RZ_API void rz_th_lock_enter(RZ_NONNULL RzThreadLock *thl)
Acquires a RzThreadLock structure.
Definition: thread_lock.c:45
int iob_read(io_desc_t *desc, uint8_t *buf, const uint32_t buf_len)
Definition: transport.c:37
int iob_write(io_desc_t *desc, const uint8_t *buf, const uint32_t buf_len)
Definition: transport.c:16
io_desc_t * io_desc_new(io_backend_t *iob, void *fp)
Definition: transport.c:7
@ E_NOIF
Definition: transport.h:24
static void lock(volatile int *lk)
Definition: malloc.c:61