Merge branch 'master' into cde-next
[oweals/cde.git] / cde / lib / tt / mini_isam / isapplmr.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: isapplmr.c /main/3 1995/10/23 11:35:25 rswiston $                                                    */
28 /*
29  * Copyright (c) 1988 by Sun Microsystems, Inc.
30  */
31
32 /*
33  * isapplmr.c
34  *
35  * Description:
36  *      Read Application magic string
37  */
38
39
40 #include "isam_impl.h"
41 #include <unistd.h>
42 #include <sys/file.h>
43 #include <sys/time.h>
44 #include "isam_impl.h"
45
46 /*
47  * string = isapplmr(isfd)
48  *
49  * Isapplmr() returns the aplication magic string written to the ISAM file
50  * by isapplmw() function. No magic string is returned as "". The value
51  * of -1 returned indicates an error (iserrno is set).
52  *
53  */
54
55 int 
56 _isapplmr(int isfd, char *buffer)
57 {
58     Fab *fab;
59     Fcb                 *fcb = NULL;
60     char                cntl_page[CP_NKEYS_OFF];
61
62     /*
63      * Get File Access Block.
64      */
65     if ((fab = _isfd_find(isfd)) == NULL) {
66         _setiserrno2(ENOTOPEN, '9', '0');
67         return (ISERROR);
68     }
69
70     /*
71      * Check that the open mode was ISINPUT, or ISINOUT.
72      */
73     if (fab->openmode != OM_INPUT && fab->openmode != OM_INOUT) {
74         _setiserrno2(ENOTOPEN, '9', '0');
75         return (ISERROR);
76     }
77
78     _isam_entryhook();
79
80     /*
81      * Get FCB corresponding to the isfhandle handle.
82      */
83     if ((fcb = _openfcb(&fab->isfhandle, &fab->errcode)) == NULL) {
84         _isam_exithook();
85         return (ISERROR);
86     }
87
88     _isseekpg(fcb->datfd, ISCNTLPGOFF);
89     (void)read(fcb->datfd, cntl_page, sizeof(cntl_page));
90     strncpy(buffer, cntl_page + CP_APPLMAGIC_OFF, CP_APPLMAGIC_LEN);
91
92     _amseterrcode(&fab->errcode, ISOK);
93     _isam_exithook();
94
95     _seterr_errcode(&fab->errcode);
96
97     return (ISOK);                           /* Successful write */
98 }