Merge branch 'master' into cde-next
[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 #ifdef __ultrix__
46 #define LOG_USER LOG_INFO
47 #endif
48 /*
49  * _isfatal_error(msg)
50  *
51  * Fatal error. Display message and terminate program.
52  */
53
54 static int (*fatal_error_user_handler)();    /* set by iscntl(..,ISCNTL_FATAL,..) */
55
56 void 
57 _isfatal_error(char *msg)
58 {
59   int           logerr;
60
61   if (fatal_error_user_handler) {
62     logerr = fatal_error_user_handler(msg); /* User returns 1 in order
63                                              * to use syslog() 
64                                              */
65   }
66   else
67     logerr = 1;
68
69   if (logerr) {
70     openlog("NetISAM", LOG_PID, LOG_USER);
71
72     /* Free one UNIX for syslog */
73     (void)close(0);                         
74                                             
75     syslog(LOG_ERR, "Fatal error: %s - UNIX errno %d", msg, errno);
76
77     closelog();
78   }
79   exit (1);
80 }
81
82 void 
83 _isfatal_error1(char *msg)
84 {
85   int           logerr;
86
87   if (fatal_error_user_handler) {
88     logerr = fatal_error_user_handler(msg); /* User returns 1 in order
89                                              * to use syslog() 
90                                              */
91   }
92   else
93     logerr = 1;
94
95   if (logerr) {
96       openlog("NetISAM", LOG_PID, LOG_USER);
97
98     /* Free one UNIX for syslog */
99     (void)close(0);                         
100                                             
101     syslog(LOG_ERR, "Fatal error: %s - UNIX errno %d", msg, errno);
102
103     closelog();
104   }
105 }
106
107 void
108 _isam_warning(char *msg)
109 {
110     openlog("NetISAM", LOG_PID, LOG_USER);
111     syslog(LOG_ERR, "%s", msg);
112 }
113
114 /* Set user specified fatal_error handler */
115 int  _isfatal_error_set_func(int(*func)())
116 {
117 #if 0
118     int         (*oldfunc)();
119
120     oldfunc = fatal_error_user_handler;
121 #endif
122
123     fatal_error_user_handler = func;
124
125     return (0);
126 }
127
128 /*
129  * _setiserrno2(error, isstat1, isstat2)
130  *
131  * Set iserrno variable.
132  */
133
134 void
135 _setiserrno2(int error, int is1, int is2)
136 {
137     iserrno = error;
138     isstat1 = is1;
139     isstat2 = is2;
140 }
141
142 /*
143  * _seterr_errcode(errcode)
144  *
145  * Set all error and status variable from errcode structure.
146  */
147
148 void
149 _seterr_errcode(struct errcode *errcode)
150 {
151     iserrno = errcode->iserrno;
152     isstat1 = errcode->isstat[0];
153     isstat2 = errcode->isstat[1];
154     isstat3 = errcode->isstat[2];
155     isstat4 = errcode->isstat[3];
156 }