Add GNU LGPL headers to all .c .C and .h files
[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 librararies 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 #ifndef lint
29 static char sccsid[] = "@(#)iserror.c 1.10 89/07/17 Copyr 1988 Sun Micro";
30 #endif
31 /*
32  * Copyright (c) 1988 by Sun Microsystems, Inc.
33  */
34
35 /*
36  * iserror.c
37  *
38  * Description:
39  *      NetISAM error handling functions.
40  *
41  */
42
43 #include "isam_impl.h"
44 #include <errno.h>
45 #include <syslog.h>
46 #ifdef __ultrix__
47 #define LOG_USER LOG_INFO
48 #endif
49 /*
50  * _isfatal_error(msg)
51  *
52  * Fatal error. Display message and terminate program.
53  */
54
55 static int (*fatal_error_user_handler)();    /* set by iscntl(..,ISCNTL_FATAL,..) */
56
57 void 
58 _isfatal_error(msg)
59     char        *msg;
60 {
61   int           logerr;
62
63   if (fatal_error_user_handler) {
64     logerr = fatal_error_user_handler(msg); /* User returns 1 in order
65                                              * to use syslog() 
66                                              */
67   }
68   else
69     logerr = 1;
70
71   if (logerr) {
72     openlog("NetISAM", LOG_PID, LOG_USER);
73
74     /* Free one UNIX for syslog */
75     (void)close(0);                         
76                                             
77     syslog(LOG_ERR, "Fatal error: %s - UNIX errno %d", msg, errno);
78
79     closelog();
80   }
81   exit (1);
82 }
83
84 void 
85 _isfatal_error1(msg)
86     char        *msg;
87 {
88   extern int    _is_rpcnetisamd; /* is 1 if this is rpc.netisamd */
89   extern int    _is_netisamlockd; /* is 1 if this is netisamlockd */
90   int           logerr;
91
92   if (fatal_error_user_handler) {
93     logerr = fatal_error_user_handler(msg); /* User returns 1 in order
94                                              * to use syslog() 
95                                              */
96   }
97   else
98     logerr = 1;
99
100   if (logerr) {
101       openlog("NetISAM", LOG_PID, LOG_USER);
102
103     /* Free one UNIX for syslog */
104     (void)close(0);                         
105                                             
106     syslog(LOG_ERR, "Fatal error: %s - UNIX errno %d", msg, errno);
107
108     closelog();
109   }
110 }
111
112 _isam_warning(msg)
113     char        *msg;
114 {
115     openlog("NetISAM", LOG_PID, LOG_USER);
116     syslog(LOG_ERR, msg);
117 }
118
119 /* Set user specified fatal_error handler */
120 int  (*_isfatal_error_set_func(func))()
121     int         (*func)();
122 {
123     int         (*oldfunc)();
124
125     oldfunc = fatal_error_user_handler;
126     fatal_error_user_handler = func;
127
128     return (oldfunc);
129 }
130
131 /*
132  * _setiserrno2(error, isstat1, isstat2)
133  *
134  * Set iserrno variable.
135  */
136
137 void
138 _setiserrno2(error, is1, is2)
139     int         error;
140     int         is1, is2;
141 {
142     iserrno = error;
143     isstat1 = is1;
144     isstat2 = is2;
145 }
146
147 /*
148  * _seterr_errcode(errcode)
149  *
150  * Set all error and status variable from errcode structure.
151  */
152
153 void
154 _seterr_errcode(errcode)
155     register struct errcode     *errcode;
156 {
157     iserrno = errcode->iserrno;
158     isstat1 = errcode->isstat[0];
159     isstat2 = errcode->isstat[1];
160     isstat3 = errcode->isstat[2];
161     isstat4 = errcode->isstat[3];
162 }