Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / lib / tt / mini_isam / issync.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: issync.c /main/3 1995/10/23 11:45:20 rswiston $                                                      */
28 #ifndef lint
29 static char sccsid[] = "@(#)issync.c 1.7 89/07/17 Copyr 1988 Sun Micro";
30 #endif
31 /*
32  * Copyright (c) 1988 by Sun Microsystems, Inc.
33  */
34
35 /*
36  * issync.c
37  *
38  * Description:
39  *      Sync all kernel buffers to the disk.
40  *
41  * Note: issync() flushes changed kernel buffers that are local to
42  *      the application that issued the call.
43  * 
44  * See sync(2) UNIX manual for what actually happens if sync() is called.
45  */
46
47 #include "isam_impl.h"
48 #include <sys/file.h>
49 #include <sys/time.h>
50
51 /*
52  * int  issync()
53  */
54
55 int 
56 issync()
57 {
58     return iscntl(ALLISFD, ISCNTL_FSYNC);
59 }
60
61 /*
62  * int  isfsync(fd)
63  */
64
65 int 
66 isfsync(isfd)
67     int         isfd;
68 {
69     return iscntl(isfd, ISCNTL_FSYNC);
70 }
71
72
73 _issync()
74 {
75     int         i;
76
77     for (i = 0; i < MAXISFD; i++)
78         (void)_isfsync(i);
79
80     return (ISOK);
81 }
82
83 _isfsync(isfd)
84     int         isfd;
85 {
86     register Fab        *fab;
87     Fcb                 *fcb;
88     int                 ret;
89
90     /*
91      * Get File Access Block.
92      */
93     if ((fab = _isfd_find(isfd)) == NULL) {
94         _setiserrno2(ENOTOPEN, '9', '0');
95         return (ISERROR);
96     }
97
98     /*
99      * Check that the open mode was ISINPUT, or ISINOUT.
100      */
101     if (fab->openmode != OM_INPUT && fab->openmode != OM_INOUT) {
102         _setiserrno2(ENOTOPEN, '9', '0');
103         return (ISERROR);
104     }
105
106     _isam_entryhook();
107
108     /*
109      * Get FCB corresponding to the isfhandle handle.
110      */
111     if ((fcb = _openfcb(&fab->isfhandle, &fab->errcode)) == NULL) {
112         _isam_exithook();
113         ret = ISERROR;
114     }
115     else {
116
117         if (fcb->datfd != -1)
118             (void)fsync(fcb->datfd);
119
120         if (fcb->indfd != -1)
121             (void)fsync(fcb->indfd);
122
123         if (fcb->varfd != -1)
124             (void)fsync(fcb->varfd);
125
126         _amseterrcode(&fab->errcode, ISOK);
127         _isam_exithook();
128         ret = ISOK;
129     }
130
131     _seterr_errcode(&fab->errcode);
132
133     return (ret);                            /* Successful write */
134 }