Argx 1.0.2-build
Simple argument parser made in C
 
Loading...
Searching...
No Matches
ARGXAddError.c File Reference
#include <stdlib.h>
#include <string.h>
#include "../inc/ARGXAddError.h"
#include "../inc/types.h"

Go to the source code of this file.

Functions

ArgxcError argxcCreateErrorSimple (const char *msg, const char *help)
 
int argxcGetErrorCode (const ArgxcError *error)
 
const char * argxcGetErrorHelp (const ArgxcError *error)
 
const char * argxcGetErrorMessage (const ArgxcError *error)
 
ArgxcErrorPair argxcGetErrorPair (const ArgxcError *error)
 
static char * stringDuplicate (const char *str)
 

Function Documentation

◆ argxcCreateErrorSimple()

ArgxcError argxcCreateErrorSimple ( const char * msg,
const char * help )

Definition at line 19 of file ARGXAddError.c.

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}
static char * stringDuplicate(const char *str)
Definition ARGXAddError.c:7
int code
Definition types.h:19
char * error
Definition types.h:17
char * help
Definition types.h:18
char * type
Definition types.h:16

References ArgxcError::code, ArgxcError::error, ArgxcError::help, stringDuplicate(), and ArgxcError::type.

◆ argxcGetErrorCode()

int argxcGetErrorCode ( const ArgxcError * error)

Definition at line 41 of file ARGXAddError.c.

42{
43 return error ? error->code : 0;
44}

References ArgxcError::code.

◆ argxcGetErrorHelp()

const char * argxcGetErrorHelp ( const ArgxcError * error)

Definition at line 36 of file ARGXAddError.c.

37{
38 return error ? error->help : NULL;
39}

References ArgxcError::help.

◆ argxcGetErrorMessage()

const char * argxcGetErrorMessage ( const ArgxcError * error)

Definition at line 31 of file ARGXAddError.c.

32{
33 return error ? error->error : NULL;
34}

References ArgxcError::error.

◆ argxcGetErrorPair()

ArgxcErrorPair argxcGetErrorPair ( const ArgxcError * error)

Definition at line 46 of file ARGXAddError.c.

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}
const char * error
const char * help

References ArgxcError::error, ArgxcErrorPair::error, ArgxcError::help, and ArgxcErrorPair::help.

◆ stringDuplicate()

static char * stringDuplicate ( const char * str)
static

Definition at line 7 of file ARGXAddError.c.

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}

Referenced by argxcCreateErrorSimple().