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

Go to the source code of this file.

Classes

struct  write_req_t
 

Functions

void alloc_buffer (uv_handle_t *handle, size_t suggested_size, uv_buf_t *buf)
 
void free_write_req (uv_write_t *req)
 
void on_stdout_write (uv_write_t *req, int status)
 
void on_file_write (uv_write_t *req, int status)
 
void write_data (uv_stream_t *dest, size_t size, uv_buf_t buf, uv_write_cb cb)
 
void read_stdin (uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf)
 
int main (int argc, char **argv)
 

Variables

uv_loop_tloop
 
uv_pipe_t stdin_pipe
 
uv_pipe_t stdout_pipe
 
uv_pipe_t file_pipe
 

Function Documentation

◆ alloc_buffer()

void alloc_buffer ( uv_handle_t handle,
size_t  suggested_size,
uv_buf_t buf 
)

Definition at line 19 of file main.c.

19  {
20  *buf = uv_buf_init((char*) malloc(suggested_size), suggested_size);
21 }
voidpf void * buf
Definition: ioapi.h:138
void * malloc(size_t size)
Definition: malloc.c:123
UV_EXTERN uv_buf_t uv_buf_init(char *base, unsigned int len)
Definition: uv-common.c:157

References malloc(), and uv_buf_init().

◆ free_write_req()

void free_write_req ( uv_write_t req)

Definition at line 23 of file main.c.

23  {
24  write_req_t *wr = (write_req_t*) req;
25  free(wr->buf.base);
26  free(wr);
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
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
char * base
Definition: unix.h:124
uv_buf_t buf
Definition: worker.c:13

References uv_buf_t::base, write_req_t::buf, free(), and req.

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 62 of file main.c.

62  {
64 
67 
70 
71  uv_fs_t file_req;
72  int fd = uv_fs_open(loop, &file_req, argv[1], O_CREAT | O_RDWR, 0644, NULL);
75 
77 
79  return 0;
80 }
#define NULL
Definition: cris-opc.c:27
static static fork const void static count static fd const char const char static newpath char char argv
Definition: sflib.h:40
#define O_CREAT
Definition: sftypes.h:489
#define O_RDWR
Definition: sftypes.h:488
Definition: uv.h:1306
uv_loop_t * loop
Definition: main.c:7
void alloc_buffer(uv_handle_t *handle, size_t suggested_size, uv_buf_t *buf)
Definition: main.c:8
uv_pipe_t stdin_pipe
Definition: main.c:15
uv_pipe_t file_pipe
Definition: main.c:17
void read_stdin(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf)
Definition: main.c:44
uv_pipe_t stdout_pipe
Definition: main.c:16
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_read_start(uv_stream_t *, uv_alloc_cb alloc_cb, uv_read_cb read_cb)
Definition: stream.c:1555
UV_EXTERN int uv_pipe_init(uv_loop_t *, uv_pipe_t *handle, int ipc)
Definition: pipe.c:33
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
UV_EXTERN int uv_pipe_open(uv_pipe_t *, uv_file file)
Definition: pipe.c:137
static const z80_opcode fd[]
Definition: z80_tab.h:997

References alloc_buffer(), argv, fd, file_pipe, loop, NULL, O_CREAT, O_RDWR, read_stdin(), stdin_pipe, stdout_pipe, uv_default_loop(), uv_fs_open(), uv_pipe_init(), uv_pipe_open(), uv_read_start(), uv_run(), and UV_RUN_DEFAULT.

◆ on_file_write()

void on_file_write ( uv_write_t req,
int  status 
)

Definition at line 33 of file main.c.

33  {
35 }
void free_write_req(uv_write_t *req)
Definition: main.c:19

References free_write_req(), and req.

Referenced by read_stdin().

◆ on_stdout_write()

void on_stdout_write ( uv_write_t req,
int  status 
)

Definition at line 29 of file main.c.

29  {
31 }

References free_write_req(), and req.

Referenced by read_stdin().

◆ read_stdin()

void read_stdin ( uv_stream_t stream,
ssize_t  nread,
const uv_buf_t buf 
)

Definition at line 44 of file main.c.

44  {
45  if (nread < 0){
46  if (nread == UV_EOF){
47  // end of file
51  }
52  } else if (nread > 0) {
55  }
56 
57  // OK to free buffer as write_data copies it.
58  if (buf->base)
59  free(buf->base);
60 }
void on_stdout_write(uv_write_t *req, int status)
Definition: main.c:29
void write_data(uv_stream_t *dest, size_t size, uv_buf_t buf, uv_write_cb cb)
Definition: main.c:37
void on_file_write(uv_write_t *req, int status)
Definition: main.c:33
UV_EXTERN void uv_close(uv_handle_t *handle, uv_close_cb close_cb)
Definition: core.c:108

References file_pipe, free(), NULL, on_file_write(), on_stdout_write(), stdin_pipe, stdout_pipe, uv_close(), and write_data().

Referenced by main().

◆ write_data()

void write_data ( uv_stream_t dest,
size_t  size,
uv_buf_t  buf,
uv_write_cb  cb 
)

Definition at line 37 of file main.c.

37  {
39  req->buf = uv_buf_init((char*) malloc(size), size);
40  memcpy(req->buf.base, buf.base, size);
41  uv_write((uv_write_t*) req, (uv_stream_t*)dest, &req->buf, 1, cb);
42 }
voidpf void uLong size
Definition: ioapi.h:138
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
char * dest
Definition: lz4.h:697
Definition: uv.h:525
UV_EXTERN int uv_write(uv_write_t *req, uv_stream_t *handle, const uv_buf_t bufs[], unsigned int nbufs, uv_write_cb cb)
Definition: stream.c:1492
static const char * cb[]
Definition: z80_tab.h:176

References cb, dest, malloc(), memcpy(), req, uv_buf_init(), and uv_write().

Referenced by read_stdin().

Variable Documentation

◆ file_pipe

uv_pipe_t file_pipe

Definition at line 17 of file main.c.

Referenced by main(), and read_stdin().

◆ loop

uv_loop_t* loop

Definition at line 14 of file main.c.

◆ stdin_pipe

uv_pipe_t stdin_pipe

◆ stdout_pipe

uv_pipe_t stdout_pipe