radare2/libr/include/r_flist.h
pancake d6f95d33c3 * Lot of fixes in the vala/swig wing
- r_util is now bindable from swig !!
  - Added test cases for r_util
  - r_flist has been mirrored in C, to keep API consistent
* Rename RIO->seek into RIO->off
  - There's a method with the same name
  - Also rename list.h ->next and ->prev into ->n ->n
* Apply patch from whats fixing 'r_cmd_str' EOF for stdin (Thanks!!)
  - Added test program to ensure stdin food works
* Allow '-f -' to rasm2 (assemble file from stdin)
* Added test case in python using RBin, RAsm and RCC to compile
  and assemble a code to be injected in the given target program
2010-02-15 22:59:26 +01:00

70 lines
1.4 KiB
C

/* radare - LGPL - Copyright 2010 nibble <.ds@gmail.com> */
#ifndef _INCLUDE_R_FLIST_H_
#define _INCLUDE_R_FLIST_H_
#include <stdlib.h>
#include <string.h>
//#include <r_types.h>
#define r_flist_t void**
#define RFList void**
#ifdef R_API
#define r_flist_rewind(it) for (; it!=*it; it--); it++;
#define r_flist_next(it) *it!=0
#define r_flist_get(it) *(it++)
#define r_flist_unref(x) x
#define r_flist_iterator(x) x
/*
static inline void **r_flist_iterator(void **it) {
r_flist_iterator(it);
return it;
}
*/
static inline void **r_flist_init(void **it, int n) {
*it = it;
memset (++it, 0, (n+1) * sizeof (void*));
return it;
}
static inline void **r_flist_new(int n) {
void **it;
if (!(it = (void **)malloc ((n+2) * sizeof (void*))))
return NULL;
return r_flist_init (it, n);
}
static inline void **r_flist_prev(void **it) {
void **p = it--;
return (it==*it)?p:it;
}
static inline void r_flist_set(void **it, int idx, void *data) {
r_flist_rewind (it);
it[idx] = data;
}
static inline void r_flist_delete(void **it, int idx) {
r_flist_rewind (it);
free (it[idx]);
for(it += idx; *it; it++) *it = *(it+1);
}
#define r_flist_foreach(it, pos) \
r_flist_rewind(it); \
while (r_flist_next (it) && (pos = r_flist_get (it)))
static inline void r_flist_free(void **it) {
void *pos;
r_flist_foreach (it, pos)
free (pos);
r_flist_rewind (it);
free (--it);
}
#endif
#endif