configure: create some convenience AC_SUBST's for the global includes
[oweals/cde.git] / cde / lib / tt / mini_isam / iserror.c
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these libraries and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /*%%  (c) Copyright 1993, 1994 Hewlett-Packard Company                   */
24 /*%%  (c) Copyright 1993, 1994 International Business Machines Corp.     */
25 /*%%  (c) Copyright 1993, 1994 Sun Microsystems, Inc.                    */
26 /*%%  (c) Copyright 1993, 1994 Novell, Inc.                              */
27 /*%%  $XConsortium: iserror.c /main/3 1995/10/23 11:38:16 rswiston $                                                     */
28 /*
29  * Copyright (c) 1988 by Sun Microsystems, Inc.
30  */
31
32 /*
33  * iserror.c
34  *
35  * Description:
36  *      NetISAM error handling functions.
37  *
38  */
39
40 #include "isam_impl.h"
41 #include <unistd.h>
42 #include <errno.h>
43 #include <stdlib.h>
44 #include <syslog.h>
45 /*
46  * _isfatal_error(msg)
47  *
48  * Fatal error. Display message and terminate program.
49  */
50
51 static int (*fatal_error_user_handler)();    /* set by iscntl(..,ISCNTL_FATAL,..) */
52
53 void 
54 _isfatal_error(char *msg)
55 {
56   int           logerr;
57
58   if (fatal_error_user_handler) {
59     logerr = fatal_error_user_handler(msg); /* User returns 1 in order
60                                              * to use syslog() 
61                                              */
62   }
63   else
64     logerr = 1;
65
66   if (logerr) {
67     openlog("NetISAM", LOG_PID, LOG_USER);
68
69     /* Free one UNIX for syslog */
70     (void)close(0);                         
71                                             
72     syslog(LOG_ERR, "Fatal error: %s - UNIX errno %d", msg, errno);
73
74     closelog();
75   }
76   exit (1);
77 }
78
79 void 
80 _isfatal_error1(char *msg)
81 {
82   int           logerr;
83
84   if (fatal_error_user_handler) {
85     logerr = fatal_error_user_handler(msg); /* User returns 1 in order
86                                              * to use syslog() 
87                                              */
88   }
89   else
90     logerr = 1;
91
92   if (logerr) {
93       openlog("NetISAM", LOG_PID, LOG_USER);
94
95     /* Free one UNIX for syslog */
96     (void)close(0);                         
97                                             
98     syslog(LOG_ERR, "Fatal error: %s - UNIX errno %d", msg, errno);
99
100     closelog();
101   }
102 }
103
104 void
105 _isam_warning(char *msg)
106 {
107     openlog("NetISAM", LOG_PID, LOG_USER);
108     syslog(LOG_ERR, "%s", msg);
109 }
110
111 /* Set user specified fatal_error handler */
112 int  _isfatal_error_set_func(int(*func)())
113 {
114 #if 0
115     int         (*oldfunc)();
116
117     oldfunc = fatal_error_user_handler;
118 #endif
119
120     fatal_error_user_handler = func;
121
122     return (0);
123 }
124
125 /*
126  * _setiserrno2(error, isstat1, isstat2)
127  *
128  * Set iserrno variable.
129  */
130
131 void
132 _setiserrno2(int error, int is1, int is2)
133 {
134     iserrno = error;
135     isstat1 = is1;
136     isstat2 = is2;
137 }
138
139 /*
140  * _seterr_errcode(errcode)
141  *
142  * Set all error and status variable from errcode structure.
143  */
144
145 void
146 _seterr_errcode(struct errcode *errcode)
147 {
148     iserrno = errcode->iserrno;
149     isstat1 = errcode->isstat[0];
150     isstat2 = errcode->isstat[1];
151     isstat3 = errcode->isstat[2];
152     isstat4 = errcode->isstat[3];
153 }