Rizin
unix-like reverse engineering framework and cli tools
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Friends Macros Modules Pages
procfs.h File Reference

Go to the source code of this file.

Functions

int procfs_pid_slurp (int pid, char *prop, char *out, size_t len)
 

Function Documentation

◆ procfs_pid_slurp()

int procfs_pid_slurp ( int  pid,
char *  prop,
char *  out,
size_t  len 
)

Definition at line 7 of file procfs.c.

7  {
8  int fd, ret = -1;
9  ssize_t nr;
10 
11  char *filename = rz_str_newf("/proc/%d/%s", pid, prop);
12  if (!filename) {
13  return -1;
14  }
16  if (fd == -1) {
17  free(filename);
18  return -1;
19  }
20  nr = read(fd, out, len);
21  out[len - 1] = 0;
22  if (nr > 0) {
23  out[nr - 1] = '\0'; /* terminate at newline */
24  ret = 0;
25  } else if (nr < 0) {
26  rz_sys_perror("read");
27  }
28  close(fd);
29  free(filename);
30  return ret;
31 }
size_t len
Definition: 6502dis.c:15
const lzma_allocator const uint8_t size_t uint8_t * out
Definition: block.h:528
static static fork const void static count close
Definition: sflib.h:33
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
const char * filename
Definition: ioapi.h:137
static static fork const void static count static fd const char const char static newpath char char char static envp time_t static t const char static mode static whence const char static dir time_t static t unsigned static seconds const char struct utimbuf static buf static inc pid
Definition: sflib.h:64
RZ_API char * rz_str_newf(const char *fmt,...) RZ_PRINTF_CHECK(1
RZ_API int rz_sys_open(const char *path, int perm, int mode)
Definition: sys.c:1740
#define rz_sys_perror(x)
Definition: rz_types.h:336
#define O_RDONLY
Definition: sftypes.h:486
int ssize_t
Definition: sftypes.h:39
static const z80_opcode fd[]
Definition: z80_tab.h:997
int read(izstream &zs, T *x, Items items)
Definition: zstream.h:115

References close, fd, free(), len, O_RDONLY, out, pid, read(), rz_str_newf(), rz_sys_open(), and rz_sys_perror.

Referenced by linux_add_new_thread(), linux_pid_list(), and linux_thread_list().