Rizin
unix-like reverse engineering framework and cli tools
main.c
Go to the documentation of this file.
1 #include <assert.h>
2 #include <stdio.h>
3 #include <fcntl.h>
4 #include <unistd.h>
5 #include <uv.h>
6 
7 void on_read(uv_fs_t *req);
8 
12 
13 static char buffer[1024];
14 
15 static uv_buf_t iov;
16 
18  if (req->result < 0) {
19  fprintf(stderr, "Write error: %s\n", uv_strerror((int)req->result));
20  }
21  else {
23  }
24 }
25 
27  if (req->result < 0) {
28  fprintf(stderr, "Read error: %s\n", uv_strerror(req->result));
29  }
30  else if (req->result == 0) {
31  uv_fs_t close_req;
32  // synchronous
34  }
35  else if (req->result > 0) {
36  iov.len = req->result;
38  }
39 }
40 
42  // The request passed to the callback is the same as the one the call setup
43  // function was passed.
44  assert(req == &open_req);
45  if (req->result >= 0) {
46  iov = uv_buf_init(buffer, sizeof(buffer));
48  &iov, 1, -1, on_read);
49  }
50  else {
51  fprintf(stderr, "error opening file: %s\n", uv_strerror((int)req->result));
52  }
53 }
54 
55 int main(int argc, char **argv) {
58 
62  return 0;
63 }
#define NULL
Definition: cris-opc.c:27
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void static offset struct stat static buf void long static basep static whence static length const void static len static semflg const void static shmflg const struct timespec req
Definition: sflib.h:128
int main(int argc, const char **argv)
Definition: main.c:340
static static fork const void static count static fd const char const char static newpath char char argv
Definition: sflib.h:40
assert(limit<=UINT32_MAX/2)
#define O_RDONLY
Definition: sftypes.h:486
Definition: buffer.h:15
Definition: unix.h:123
size_t len
Definition: unix.h:125
Definition: uv.h:1306
ssize_t result
Definition: uv.h:1311
void on_read(uv_stream_t *client, ssize_t nread, const uv_buf_t *buf)
Definition: main.c:13
uv_write_t write_req
Definition: main.c:9
static uv_buf_t iov
Definition: main.c:15
uv_fs_t open_req
Definition: main.c:9
void on_write(uv_fs_t *req)
Definition: main.c:17
void on_open(uv_fs_t *req)
Definition: main.c:41
uv_fs_t read_req
Definition: main.c:10
UV_EXTERN int uv_fs_open(uv_loop_t *loop, uv_fs_t *req, const char *path, int flags, int mode, uv_fs_cb cb)
Definition: fs.c:1858
@ UV_RUN_DEFAULT
Definition: uv.h:255
UV_EXTERN int uv_fs_read(uv_loop_t *loop, uv_fs_t *req, uv_file file, const uv_buf_t bufs[], unsigned int nbufs, int64_t offset, uv_fs_cb cb)
Definition: fs.c:1872
UV_EXTERN void uv_fs_req_cleanup(uv_fs_t *req)
Definition: fs.c:2070
UV_EXTERN uv_buf_t uv_buf_init(char *base, unsigned int len)
Definition: uv-common.c:157
UV_EXTERN int uv_run(uv_loop_t *, uv_run_mode mode)
Definition: core.c:365
UV_EXTERN int uv_fs_write(uv_loop_t *loop, uv_fs_t *req, uv_file file, const uv_buf_t bufs[], unsigned int nbufs, int64_t offset, uv_fs_cb cb)
Definition: fs.c:2041
UV_EXTERN const char * uv_strerror(int err)
Definition: uv-common.c:212
UV_EXTERN int uv_fs_close(uv_loop_t *loop, uv_fs_t *req, uv_file file, uv_fs_cb cb)
Definition: fs.c:1697
UV_EXTERN uv_loop_t * uv_default_loop(void)
Definition: uv-common.c:763