2 * file - file I/O routines callable by users
4 * Copyright (C) 1999-2007 David I. Bell and Landon Curt Noll
6 * Primary author: David I. Bell
8 * Calc is open software; you can redistribute it and/or modify it under
9 * the terms of the version 2.1 of the GNU Lesser General Public License
10 * as published by the Free Software Foundation.
12 * Calc is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
15 * Public License for more details.
17 * A copy of version 2.1 of the GNU Lesser General Public License is
18 * distributed with calc under the filename COPYING-LGPL. You should have
19 * received a copy with calc; if not, write to Free Software Foundation, Inc.
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 * @(#) $Revision: 30.2 $
23 * @(#) $Id: file.h,v 30.2 2013/08/11 08:41:38 chongo Exp $
24 * @(#) $Source: /usr/local/src/bin/calc/RCS/file.h,v $
26 * Under source code control: 1996/05/24 05:55:58
27 * File existed as early as: 1996
29 * chongo <was here> /\oo/\ http://www.isthe.com/chongo/
30 * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
34 #if !defined(__FILE_H__)
38 #if defined(CALC_SRC) /* if we are building from the calc source tree */
39 # include "have_fpos.h"
41 # include <calc/have_fpos.h>
46 * Definition of opened files.
49 FILEID id
; /* id to identify this file */
50 FILE *fp
; /* real file structure for I/O */
51 dev_t dev
; /* file device */
52 ino_t inode
; /* file inode */
53 char *name
; /* file name */
54 BOOL reading
; /* TRUE if opened for reading */
55 BOOL writing
; /* TRUE if opened for writing */
56 BOOL appending
; /* TRUE if also opened for appending */
57 BOOL binary
; /* TRUE if binary mode - mode ignored/unused */
58 char action
; /* most recent use for 'r', 'w' or 0 */
59 char mode
[sizeof("rb+")+1];/* open mode */
64 * fgetpos/fsetpos vs fseek/ftell interface
66 * f_seek_set(FILE *stream, FILEPOS *loc)
67 * Seek loc bytes from the beginning of the open file, stream.
69 * f_tell(FILE *stream, FILEPOS *loc)
70 * Set loc to bytes from the beinning of the open file, stream.
72 * We assume that if your system does not have fgetpos/fsetpos,
73 * then it will have a FILEPOS that is a scalar type (e.g., long).
74 * Some obscure systems without fgetpos/fsetpos may not have a simple
75 * scalar type. In these cases the f_tell macro below will fail.
77 #if defined(HAVE_FPOS)
79 #define f_seek_set(stream, loc) fsetpos((FILE*)(stream), (FILEPOS*)(loc))
80 #define f_tell(stream, loc) fgetpos((FILE*)(stream), (FILEPOS*)(loc))
84 #define f_seek_set(stream, loc) \
85 fseek((FILE*)(stream), *(FILEPOS*)(loc), SEEK_SET)
86 #define f_tell(stream, loc) (*((FILEPOS*)(loc)) = ftell((FILE*)(stream)))
94 E_FUNC FILEIO
* findid(FILEID id
, int writable
);
95 E_FUNC
int fgetposid(FILEID id
, FILEPOS
*ptr
);
96 E_FUNC
int fsetposid(FILEID id
, FILEPOS
*ptr
);
97 E_FUNC
int get_open_siz(FILE *fp
, ZVALUE
*res
);
98 E_FUNC
char* findfname(FILEID
);
99 E_FUNC
FILE *f_pathopen(char *name
, char *mode
, char *pathlist
,
103 #endif /* !__FILE_H__ */