-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patherror_handling.c
More file actions
51 lines (44 loc) · 996 Bytes
/
Copy patherror_handling.c
File metadata and controls
51 lines (44 loc) · 996 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include "include/lval.h"
lval *lval_err(char *fmt, ...)
{
lval *v = malloc(sizeof(lval));
v->type = LVAL_ERR;
// Create a va list and initialize it
va_list va;
va_start(va, fmt);
// Allocate 512 bytes
v->data.err = malloc(512);
// printf the error string with max 511 chars
vsnprintf(v->data.err, 511, fmt, va);
v->data.err = realloc(v->data.err, strlen(v->data.err) + 1);
va_end(va);
return v;
}
char *ltype_name(int t)
{
switch (t)
{
case LVAL_FUN:
return "Function";
case LVAL_LONG:
return "Long";
case LVAL_DOUBLE:
return "Double";
case LVAL_ERR:
return "Error";
case LVAL_SYM:
return "Symbol";
case LVAL_STR:
return "String";
case LVAL_SEXPR:
return "S-Expression";
case LVAL_QEXPR:
return "Q-Expression";
default:
return "Unknown";
}
}