1 #ifndef _NCBIFILE_ 2 #define _NCBIFILE_ 3 4 /* ncbifile.h 5 * =========================================================================== 6 * 7 * PUBLIC DOMAIN NOTICE 8 * National Center for Biotechnology Information 9 * 10 * This software/database is a "United States Government Work" under the 11 * terms of the United States Copyright Act. It was written as part of 12 * the author's official duties as a United States Government employee and 13 * thus cannot be copyrighted. This software/database is freely available 14 * to the public for use. The National Library of Medicine and the U.S. 15 * Government have not placed any restriction on its use or reproduction. 16 * 17 * Although all reasonable efforts have been taken to ensure the accuracy 18 * and reliability of the software and data, the NLM and the U.S. 19 * Government do not and cannot warrant the performance or results that 20 * may be obtained by using this software or data. The NLM and the U.S. 21 * Government disclaim all warranties, express or implied, including 22 * warranties of performance, merchantability or fitness for any particular 23 * purpose. 24 * 25 * Please cite the author in any work or product based on this material. 26 * 27 * =========================================================================== 28 * 29 * File Name: ncbifile.h 30 * 31 * Author: Gish, Kans, Ostell, Schuler 32 * 33 * Version Creation Date: 1/1/91 34 * 35 * $Revision: 6.8 $ 36 * 37 * File Description: 38 * prototypes for portable file routines 39 * 40 * Modifications: 41 * -------------------------------------------------------------------------- 42 * 43 * ========================================================================== 44 */ 45 46 #undef NLM_EXTERN 47 #ifdef NLM_IMPORT 48 #define NLM_EXTERN NLM_IMPORT 49 #else 50 #define NLM_EXTERN extern 51 #endif 52 53 #ifdef __cplusplus 54 extern "C" { 55 #endif 56 57 58 typedef FILE* (LIBCALLBACK *Nlm_FileOpenHook) 59 (const char *filename, const char *mode); 60 61 NLM_EXTERN FILE* LIBCALL Nlm_FileOpen(const char *filename, const char *mode); 62 NLM_EXTERN void LIBCALL Nlm_FileClose(FILE *stream); 63 NLM_EXTERN size_t LIBCALL Nlm_FileRead(void *ptr, size_t size, size_t n, FILE *stream); 64 NLM_EXTERN size_t LIBCALL Nlm_FileWrite(const void *ptr, size_t size, size_t n, FILE *stream); 65 NLM_EXTERN int LIBCALL Nlm_FilePuts(const char *ptr, FILE * fp); 66 NLM_EXTERN char * LIBCALL Nlm_FileGets(char *ptr, size_t size, FILE * fp); 67 NLM_EXTERN Nlm_CharPtr LIBCALL Nlm_FileBuildPath(Nlm_CharPtr root, Nlm_CharPtr sub_path, Nlm_CharPtr filename); 68 NLM_EXTERN Nlm_CharPtr LIBCALL Nlm_FileNameFind(Nlm_CharPtr pathname); 69 NLM_EXTERN Nlm_CharPtr LIBCALL Nlm_FilePathFind(const Nlm_Char* fullname); 70 NLM_EXTERN Nlm_Int8 LIBCALL Nlm_FileLength(Nlm_CharPtr fileName); 71 /* Nlm_FileLengthEx() returns -1 if the file does not exist) */ 72 NLM_EXTERN Nlm_Int8 LIBCALL Nlm_FileLengthEx(const Nlm_Char* fileName); 73 NLM_EXTERN Nlm_Boolean LIBCALL Nlm_FileRemove(Nlm_CharPtr fileName); 74 NLM_EXTERN Nlm_Boolean LIBCALL Nlm_FileRename(Nlm_CharPtr oldFileName, Nlm_CharPtr newFileName); 75 NLM_EXTERN void LIBCALL Nlm_FileCreate(Nlm_CharPtr fileName, Nlm_CharPtr type, Nlm_CharPtr creator); 76 NLM_EXTERN Nlm_Boolean LIBCALL Nlm_CreateDir(Nlm_CharPtr pathname); 77 NLM_EXTERN ValNodePtr LIBCALL Nlm_DirCatalog (Nlm_CharPtr pathname); 78 NLM_EXTERN Nlm_CharPtr LIBCALL Nlm_TmpNam(Nlm_CharPtr s); 79 NLM_EXTERN void LIBCALL Nlm_SetFileOpenHook(Nlm_FileOpenHook hook); 80 81 /* FileCache provides buffered text read for handling Unix, Mac, and DOS line endings gracefully */ 82 83 typedef struct nlm_filecachedata { 84 FILE *fp; 85 Nlm_Char buf [516]; 86 Nlm_Int2 ctr; 87 Nlm_Int2 total; 88 Nlm_Int4 offset; 89 Nlm_Boolean failed; 90 } Nlm_FileCache, PNTR Nlm_FileCachePtr; 91 92 NLM_EXTERN Nlm_Boolean Nlm_FileCacheSetup (Nlm_FileCache PNTR fcp, FILE *fp); 93 NLM_EXTERN Nlm_CharPtr Nlm_FileCacheGetString (Nlm_FileCache PNTR fcp, Nlm_CharPtr str, size_t size); 94 NLM_EXTERN Nlm_CharPtr Nlm_FileCacheReadLine (Nlm_FileCache PNTR fcp, Nlm_CharPtr str, size_t size, Nlm_BoolPtr nonewline); 95 NLM_EXTERN void Nlm_FileCacheSeek (Nlm_FileCache PNTR fcp, Nlm_Int4 pos); 96 NLM_EXTERN Nlm_Int4 Nlm_FileCacheTell (Nlm_FileCache PNTR fcp); 97 NLM_EXTERN Nlm_Boolean Nlm_FileCacheFree (Nlm_FileCache PNTR fcp, Nlm_Boolean restoreFilePos); 98 99 /* general file recursion function - directory must not be empty, proc callback function must not be NULL */ 100 101 typedef void (*Nlm_DirExpProc) (Nlm_CharPtr filename, Nlm_VoidPtr userdata); 102 103 NLM_EXTERN Nlm_Int4 Nlm_DirExplore ( 104 Nlm_CharPtr directory, 105 Nlm_CharPtr filter, 106 Nlm_CharPtr suffix, 107 Nlm_Boolean recurse, 108 Nlm_DirExpProc proc, 109 Nlm_VoidPtr userdata 110 ); 111 112 #define FileOpen Nlm_FileOpen 113 #define FileClose Nlm_FileClose 114 #define FileRead Nlm_FileRead 115 #define FileWrite Nlm_FileWrite 116 #define FilePuts Nlm_FilePuts 117 #define FileGets Nlm_FileGets 118 #define FileBuildPath Nlm_FileBuildPath 119 #define FileNameFind Nlm_FileNameFind 120 #define FilePathFind Nlm_FilePathFind 121 #define FileLength Nlm_FileLength 122 #define FileLengthEx Nlm_FileLengthEx 123 #define FileRemove Nlm_FileRemove 124 #define FileRename Nlm_FileRename 125 #define FileCreate Nlm_FileCreate 126 #define CreateDir Nlm_CreateDir 127 #define DirCatalog Nlm_DirCatalog 128 #define TmpNam Nlm_TmpNam 129 130 #define FileCache Nlm_FileCache 131 #define FileCacheSetup Nlm_FileCacheSetup 132 #define FileCachePtr Nlm_FileCachePtr 133 134 #define FileCacheSetup Nlm_FileCacheSetup 135 #define FileCacheGetString Nlm_FileCacheGetString 136 #define FileCacheReadLine Nlm_FileCacheReadLine 137 #define FileCacheSeek Nlm_FileCacheSeek 138 #define FileCacheTell Nlm_FileCacheTell 139 #define FileCacheFree Nlm_FileCacheFree 140 141 #define DirExpProc Nlm_DirExpProc 142 #define DirExplore Nlm_DirExplore 143 144 #define EjectCd(sVolume, deviceName, rawDeviceName, mountPoint, mountCmd) FALSE 145 #define MountCd(sVolume, deviceName, mountPoint, mountCmd) FALSE 146 147 148 #ifdef __cplusplus 149 } /* extern "C" */ 150 #endif 151 152 #undef NLM_EXTERN 153 #ifdef NLM_EXPORT 154 #define NLM_EXTERN NLM_EXPORT 155 #else 156 #define NLM_EXTERN 157 #endif 158 159 #endif /* _NCBIFILE_ */ 160