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