Rizin
unix-like reverse engineering framework and cli tools
main.c File Reference
#include <assert.h>
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <uv.h>

Go to the source code of this file.

Functions

void on_read (uv_fs_t *req)
 
void on_write (uv_fs_t *req)
 
void on_open (uv_fs_t *req)
 
int main (int argc, char **argv)
 

Variables

uv_fs_t open_req
 
uv_fs_t read_req
 
uv_fs_t write_req
 
static char buffer [1024]
 
static uv_buf_t iov
 

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 55 of file main.c.

55  {
58 
62  return 0;
63 }
static static fork const void static count static fd const char const char static newpath char char argv
Definition: sflib.h:40
#define O_RDONLY
Definition: sftypes.h:486
uv_write_t write_req
Definition: main.c:9
uv_fs_t open_req
Definition: main.c:9
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 void uv_fs_req_cleanup(uv_fs_t *req)
Definition: fs.c:2070
UV_EXTERN int uv_run(uv_loop_t *, uv_run_mode mode)
Definition: core.c:365
UV_EXTERN uv_loop_t * uv_default_loop(void)
Definition: uv-common.c:763

References argv, O_RDONLY, on_open(), open_req, read_req, uv_default_loop(), uv_fs_open(), uv_fs_req_cleanup(), uv_run(), UV_RUN_DEFAULT, and write_req.

◆ on_open()

void on_open ( uv_fs_t req)

Definition at line 41 of file main.c.

41  {
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 }
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
assert(limit<=UINT32_MAX/2)
Definition: buffer.h:15
void on_read(uv_stream_t *client, ssize_t nread, const uv_buf_t *buf)
Definition: main.c:13
static uv_buf_t iov
Definition: main.c:15
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 uv_buf_t uv_buf_init(char *base, unsigned int len)
Definition: uv-common.c:157
UV_EXTERN const char * uv_strerror(int err)
Definition: uv-common.c:212

References assert(), iov, on_read(), open_req, read_req, req, uv_buf_init(), uv_default_loop(), uv_fs_read(), and uv_strerror().

Referenced by main().

◆ on_read()

void on_read ( uv_fs_t req)

Definition at line 26 of file main.c.

26  {
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 }
#define NULL
Definition: cris-opc.c:27
size_t len
Definition: unix.h:125
Definition: uv.h:1306
ssize_t result
Definition: uv.h:1311
void on_write(uv_fs_t *req)
Definition: main.c:17
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 int uv_fs_close(uv_loop_t *loop, uv_fs_t *req, uv_file file, uv_fs_cb cb)
Definition: fs.c:1697

References iov, uv_buf_t::len, NULL, on_write(), open_req, req, uv_fs_s::result, uv_default_loop(), uv_fs_close(), uv_fs_write(), uv_strerror(), and write_req.

◆ on_write()

void on_write ( uv_fs_t req)

Definition at line 17 of file main.c.

17  {
18  if (req->result < 0) {
19  fprintf(stderr, "Write error: %s\n", uv_strerror((int)req->result));
20  }
21  else {
23  }
24 }

References iov, on_read(), open_req, read_req, req, uv_fs_s::result, uv_default_loop(), uv_fs_read(), and uv_strerror().

Referenced by on_read().

Variable Documentation

◆ buffer

char buffer[1024]
static

Definition at line 13 of file main.c.

◆ iov

uv_buf_t iov
static

Definition at line 15 of file main.c.

Referenced by linux_reg_read(), on_open(), on_read(), on_write(), uv__preadv(), uv__pwritev(), and uv__write().

◆ open_req

uv_fs_t open_req

Definition at line 9 of file main.c.

Referenced by main(), on_open(), on_read(), and on_write().

◆ read_req

uv_fs_t read_req

Definition at line 10 of file main.c.

Referenced by main(), on_open(), and on_write().

◆ write_req

uv_fs_t write_req

Definition at line 11 of file main.c.