flinklib
flinklib: flink C library for Linux
error.c
Go to the documentation of this file.
1 /*******************************************************************
2  * _________ _____ _____ ____ _____ ___ ____ *
3  * |_ ___ | |_ _| |_ _| |_ \|_ _| |_ ||_ _| *
4  * | |_ \_| | | | | | \ | | | |_/ / *
5  * | _| | | _ | | | |\ \| | | __'. *
6  * _| |_ _| |__/ | _| |_ _| |_\ |_ _| | \ \_ *
7  * |_____| |________| |_____| |_____|\____| |____||____| *
8  * *
9  *******************************************************************
10  * *
11  * fLink userspace library, error handling *
12  * *
13  *******************************************************************/
14 
21 #include "error.h"
22 #include <errno.h>
23 #include "log.h"
24 #include <string.h>
25 
26 __thread int flink_errno = 0;
27 
28 const char* flinklib_error_strings[] = {
29  "No error",
30  "Unknown error",
31  "Not supported",
32  "Invalid device",
33  "Invalid subdevice",
34  "Invalid channel",
35  "Null ptr as argument",
36  "Unknown ioctl command",
37  "Wrong subdevice type",
38 };
39 #define NOF_ERRORS (sizeof(flinklib_error_strings) / sizeof(char*))
40 
41 
42 const char* flink_strerror(int e) {
43  if(e < FLINK_NOERROR || e >= FLINK_NOERROR + NOF_ERRORS) { // not a flink error
44  return strerror(e);
45  }
47 }
48 
49 
50 void flink_perror(const char* p) {
51  if(!p) p = "flinklib";
52  fprintf(stderr, "%s: %s\n", p, flink_strerror(flink_errno));
53 }
54 
55 
56 void libc_error(void) {
57  flink_errno = errno;
59  flink_perror("libc error");
60  }
61 }
62 
63 
64 void flink_error(int e) {
65  flink_errno = e;
67  flink_perror("flink error");
68  }
69 }
const char * flinklib_error_strings[]
Definition: error.c:28
__thread int flink_errno
Definition: error.c:26
Error handling.
#define NOF_ERRORS
Definition: error.c:39
void flink_perror(const char *p)
Definition: error.c:50
#define PRINT_ERRORS_TO_STDERR
Definition: log.h:26
#define FLINK_NOERROR
Definition: error.h:26
void flink_error(int e)
Definition: error.c:64
void libc_error(void)
Definition: error.c:56
const char * flink_strerror(int e)
Definition: error.c:42
Debug utilities.