FrontISTR  5.9.0
Large-scale structural analysis program with finit element method
hecmw_error.c
Go to the documentation of this file.
1 /*****************************************************************************
2  * Copyright (c) 2019 FrontISTR Commons
3  * This software is released under the MIT License, see LICENSE.txt
4  *****************************************************************************/
5 
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <stdarg.h>
9 #include <string.h>
10 #include "hecmw_util.h"
11 #include "hecmw_error.h"
12 
13 static int hecmw_errno;
14 
15 static char hecmw_errmsg[HECMW_MSG_LEN + 1];
16 
17 int HECMW_set_verror(int errorno, const char *fmt, va_list ap) {
18  char errmsg[HECMW_MSG_LEN + 1];
19 
20  hecmw_errno = errorno;
21 
22  size_t len = snprintf(hecmw_errmsg, sizeof(hecmw_errmsg), "%s", HECMW_strmsg(errorno));
23  HECMW_vsnprintf(errmsg, sizeof(errmsg), fmt, ap);
24 
25  if (strlen(errmsg) > 0)
26  snprintf(hecmw_errmsg + len, sizeof(hecmw_errmsg) - len, " (%s)", errmsg);
27 
29 
30  return 0;
31 }
32 
33 int HECMW_set_error(int errorno, const char *fmt, ...) {
34  int rc;
35  va_list ap;
36 
37  rc = 0;
38  va_start(ap, fmt);
39  rc = HECMW_set_verror(errorno, fmt, ap);
40  va_end(ap);
41 
42  return rc;
43 }
44 
45 int HECMW_get_error(char **errmsg) {
46  if (errmsg) {
47  *errmsg = hecmw_errmsg;
48  }
49  return hecmw_errno;
50 }
51 
52 int HECMW_get_errno(void) { return hecmw_errno; }
53 
54 char *HECMW_get_errmsg(void) { return hecmw_errmsg; }
#define HECMW_MSG_LEN
Definition: hecmw_config.h:76
int HECMW_set_verror(int errorno, const char *fmt, va_list ap)
Definition: hecmw_error.c:17
int HECMW_set_error(int errorno, const char *fmt,...)
Definition: hecmw_error.c:33
int HECMW_get_error(char **errmsg)
Definition: hecmw_error.c:45
char * HECMW_get_errmsg(void)
Definition: hecmw_error.c:54
int HECMW_get_errno(void)
Definition: hecmw_error.c:52
char * HECMW_strmsg(int msgno)
Definition: hecmw_msg.c:31
void HECMW_print_error(void)
Definition: hecmw_util.c:124
int HECMW_vsnprintf(char *str, size_t size, const char *format, va_list ap)
Definition: hecmw_util.c:145