Skip to content

Commit

Permalink
Enable detecting error status
Browse files Browse the repository at this point in the history
  • Loading branch information
emboss committed Nov 25, 2012
1 parent 0f95909 commit 4398c67
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
28 changes: 26 additions & 2 deletions ext/krypt/core/krypt_error.c
Expand Up @@ -30,7 +30,7 @@ static krypt_err_stack err_stack = { 0 };

#define int_err_stack_empty() (err_stack.count == 0)

void
static void
int_err_stack_push(char *message, size_t len)
{
krypt_err_stack_elem *elem;
Expand All @@ -43,7 +43,7 @@ int_err_stack_push(char *message, size_t len)
err_stack.count++;
}

char *
static char *
int_err_stack_pop()
{
char *message;
Expand All @@ -58,6 +58,30 @@ int_err_stack_pop()
return message;
}

int
krypt_has_errors(void)
{
return !int_err_stack_empty();
}

int
krypt_error_message(char *buf, int buf_len)
{
krypt_err_stack_elem *head = err_stack.head;
int len = 0;

while (head) {
int cur_len;
char *message = head->message;
cur_len = snprintf(buf + len, buf_len, "%s%s", (len ? ": " : ""), message);
if (cur_len > 0)
len += cur_len;
head = head->prev;
}

return len;
}

void
krypt_error_add(const char *format, ...)
{
Expand Down
2 changes: 2 additions & 0 deletions ext/krypt/core/krypt_error.h
Expand Up @@ -15,6 +15,8 @@

void krypt_error_add(const char *format, ...);

int krypt_has_errors(void);
int krypt_error_message(char *buf, int buf_len);
VALUE krypt_error_create(VALUE exception_class, const char *format, ...);
void krypt_error_raise(VALUE exception_class, const char *format, ...);
void krypt_error_clear(void);
Expand Down

0 comments on commit 4398c67

Please sign in to comment.