OpenIndiana and Solaris port
[oweals/cde.git] / cde / lib / tt / mini_isam / iscntl.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: iscntl.c /main/3 1995/10/23 11:36:59 rswiston $                                                      */
28 #ifndef lint
29 static char sccsid[] = "@(#)iscntl.c    1.8 94/11/17";
30 #endif
31 /*
32  * Copyright (c) 1988 by Sun Microsystems, Inc.
33  */
34
35 /*
36  * iscntl.c
37  *
38  * Description:
39  *      Generic control function
40  */
41
42 #if defined(linux) || defined(CSRG_BASED) || defined(sun)
43 #include <stdarg.h>
44 #else
45 #include <varargs.h>
46 #endif
47 #include "isam_impl.h"
48
49
50 /*
51  * err =  iscntl(isfd, args)
52  *
53  * Functions:
54  *
55  * iscntl(isfd, ISCNTL_RPCS_TO_SET, tout) - Set timeout for short operations
56  * iscntl(isfd, ISCNTL_RPCL_TO_SET, tout) - Set timeout for long operations
57  * iscntl(isfd, ISCNTL_RPCS_TO_GET) - Get timeout for short operations
58  * iscntl(isfd, ISCNTL_RPCL_TO_GET) - Get timeout for long operations
59  * iscntl(isfd, ISCNTL_TCP_TO_SET) - Set TCP reconnect timeout
60  * iscntl(isfd, ISCNTL_TCP_TO_GET) - Get TCP reconnect timeout
61  *
62  * iscntl(isfd, ISCNTL_APPLMAGIC_WRITE, string) - Write application magic
63  * iscntl(isfd, ISCNTL_APPLMAGIC_READ, buf) - Read application magic
64  *
65  * iscntl(ALLISFD, ISCNTL_FDLIMIT_SET, n) - Set limit on UNIX fd use
66  * iscntl(ALLISFD, ISCNTL_FDLIMIT_GET) - Set limit on UNIX fd use
67  *
68  * oldfunc = iscntl(ALLISFD, ISCNTL_FATAL, func) - Set fatal error handler
69  *     int func(msg) - Apllication handler
70  *     if 0 is returned, NetISAM will use openlog("NetISAM") and
71  *     syslog(ERR_LOG, msg) to log the error.
72  *
73  * iscntl(ALLISFD, ISCNTL_MASKSIGNALS, bool) 1 mask, 0 don't mask
74  *
75  * iscntl(isfd, ISCNTL_FSYNC) -  synchronize a file's in-core state
76  *                               with that on disk
77  *
78  */
79
80 typedef int (* intfunc)();
81
82 #if defined(linux) || defined(CSRG_BASED) || defined(sun)
83 int 
84 iscntl(int isfd, int func, ...)
85 #else
86 int 
87 iscntl(isfd, func, va_alist)
88     int                 isfd;
89     int                 func;
90     va_dcl
91 #endif
92 {
93     extern int          (*_isfatal_error_set_func())();
94     va_list             pvar;
95     int                 ret;
96
97 #if defined(linux) || defined(CSRG_BASED) || defined(sun)
98     va_start(pvar, func);
99 #else
100     va_start(pvar);
101 #endif
102     switch (func) {
103
104           case ISCNTL_MASKSIGNALS:
105             ret =  _issignals_cntl(va_arg(pvar, int));
106             break;
107
108           case ISCNTL_FATAL:
109             ret =  (int)_isfatal_error_set_func(va_arg(pvar,  intfunc));
110             break;
111
112           case ISCNTL_FDLIMIT_SET:
113             ret =  _watchfd_max_set(va_arg(pvar, int));
114             break;
115
116           case ISCNTL_FDLIMIT_GET:
117             ret =  _watchfd_max_get();
118             break;
119
120           case ISCNTL_APPLMAGIC_WRITE:
121             ret =  _isapplmw(isfd, (va_arg(pvar, char *)));
122             break;
123
124           case ISCNTL_APPLMAGIC_READ:
125             ret =  _isapplmr(isfd, (va_arg(pvar, char *)));
126             break;
127
128           case ISCNTL_FSYNC:
129             ret = _isfsync(isfd);
130             break;
131
132           default:
133             _setiserrno2(EBADARG, '9', '0');
134             ret =  ISERROR;
135     }
136
137     va_end(pvar);
138     return (ret);
139 }