FrontISTR  5.7.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  HECMW_snprintf(hecmw_errmsg, sizeof(hecmw_errmsg), "%s",
23  HECMW_strmsg(errorno));
24  HECMW_vsnprintf(errmsg, sizeof(errmsg), fmt, ap);
25 
26  if (strlen(errmsg) > 0) {
27  HECMW_snprintf(hecmw_errmsg + strlen(hecmw_errmsg),
28  sizeof(hecmw_errmsg) - strlen(hecmw_errmsg), " (%s)",
29  errmsg);
30  }
31 
33 
34  return 0;
35 }
36 
37 int HECMW_set_error(int errorno, const char *fmt, ...) {
38  int rc;
39  va_list ap;
40 
41  rc = 0;
42  va_start(ap, fmt);
43  rc = HECMW_set_verror(errorno, fmt, ap);
44  va_end(ap);
45 
46  return rc;
47 }
48 
49 int HECMW_get_error(char **errmsg) {
50  if (errmsg) {
51  *errmsg = hecmw_errmsg;
52  }
53  return hecmw_errno;
54 }
55 
56 int HECMW_get_errno(void) { return hecmw_errno; }
57 
58 char *HECMW_get_errmsg(void) { return hecmw_errmsg; }
HECMW_snprintf
int HECMW_snprintf(char *str, size_t size, const char *format,...)
Definition: hecmw_util.c:153
HECMW_get_errno
int HECMW_get_errno(void)
Definition: hecmw_error.c:56
HECMW_print_error
void HECMW_print_error(void)
Definition: hecmw_util.c:124
hecmw_error.h
HECMW_vsnprintf
int HECMW_vsnprintf(char *str, size_t size, const char *format, va_list ap)
Definition: hecmw_util.c:145
HECMW_get_error
int HECMW_get_error(char **errmsg)
Definition: hecmw_error.c:49
HECMW_set_verror
int HECMW_set_verror(int errorno, const char *fmt, va_list ap)
Definition: hecmw_error.c:17
HECMW_strmsg
char * HECMW_strmsg(int msgno)
Definition: hecmw_msg.c:31
HECMW_set_error
int HECMW_set_error(int errorno, const char *fmt,...)
Definition: hecmw_error.c:37
HECMW_get_errmsg
char * HECMW_get_errmsg(void)
Definition: hecmw_error.c:58
hecmw_util.h
HECMW_MSG_LEN
#define HECMW_MSG_LEN
Definition: hecmw_config.h:74