Argx 1.0.2-build
Simple argument parser made in C
 
Loading...
Searching...
No Matches
ARGXAddError.c
Go to the documentation of this file.
1#include <stdlib.h>
2#include <string.h>
3
5#include "../inc/types.h"
6
7static char *stringDuplicate(const char *str)
8{
9 if (!str) return NULL;
10 size_t len = strlen(str) + 1;
11 char *dup = malloc(len);
12 if (dup)
13 {
14 memcpy(dup, str, len);
15 }
16 return dup;
17}
18
19ArgxcError argxcCreateErrorSimple(const char *msg, const char *help)
20{
21 ArgxcError error = {0};
22
23 error.type = stringDuplicate("error");
24 error.error = stringDuplicate(msg);
25 error.help = stringDuplicate(help);
26 error.code = 1; // Default error code
27
28 return error;
29}
30
31const char *argxcGetErrorMessage(const ArgxcError *error)
32{
33 return error ? error->error : NULL;
34}
35
36const char *argxcGetErrorHelp(const ArgxcError *error)
37{
38 return error ? error->help : NULL;
39}
40
42{
43 return error ? error->code : 0;
44}
45
47{
48 ArgxcErrorPair pair = {NULL, NULL};
49
50 if (error)
51 {
52 pair.error = error->error;
53 pair.help = error->help;
54 }
55
56 return pair;
57}
58
int argxcGetErrorCode(const ArgxcError *error)
static char * stringDuplicate(const char *str)
Definition ARGXAddError.c:7
const char * argxcGetErrorHelp(const ArgxcError *error)
ArgxcError argxcCreateErrorSimple(const char *msg, const char *help)
const char * argxcGetErrorMessage(const ArgxcError *error)
ArgxcErrorPair argxcGetErrorPair(const ArgxcError *error)
const char * error
const char * help
int code
Definition types.h:19
char * error
Definition types.h:17
char * help
Definition types.h:18
char * type
Definition types.h:16