diff --git a/libr/include/r_util/r_stack.h b/libr/include/r_util/r_stack.h index 4f64ffab7a..8f67f295b2 100644 --- a/libr/include/r_util/r_stack.h +++ b/libr/include/r_util/r_stack.h @@ -17,4 +17,5 @@ R_API RStack *r_stack_newf(ut32 n, RStackFree f); R_API int r_stack_push(RStack *s, void *el); R_API void *r_stack_pop(RStack *s); R_API unsigned int r_stack_size(RStack *s); +R_API void *r_stack_peek(RStack *s); #endif // R_STACK_H diff --git a/libr/util/stack.c b/libr/util/stack.c index a39bc89cd5..62766cea8c 100644 --- a/libr/util/stack.c +++ b/libr/util/stack.c @@ -71,3 +71,12 @@ R_API bool r_stack_is_empty(RStack *s) { R_API unsigned int r_stack_size(RStack *s) { return (unsigned int)(s->top + 1); } + +R_API void *r_stack_peek(RStack *s) { + void *res; + if (s->top != -1) { + res = s->elems[s->top]; + return res; + } + return NULL; +}