1 /* Converted to D from C:/devLibs/gdal21/include/cpl_vsi.h by htod */
2 module gdal.cpl.vsi;
3 /******************************************************************************
4  * $Id: cpl_vsi.h 33758 2016-03-21 09:06:22Z rouault $
5  *
6  * Project:  CPL - Common Portability Library
7  * Author:   Frank Warmerdam, warmerdam@pobox.com
8  * Purpose:  Include file defining Virtual File System (VSI) functions, a
9  *           layer over POSIX file and other system services.
10  *
11  ******************************************************************************
12  * Copyright (c) 1998, Frank Warmerdam
13  * Copyright (c) 2008-2014, Even Rouault <even dot rouault at mines-paris dot org>
14  *
15  * Permission is hereby granted, free of charge, to any person obtaining a
16  * copy of this software and associated documentation files (the "Software"),
17  * to deal in the Software without restriction, including without limitation
18  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
19  * and/or sell copies of the Software, and to permit persons to whom the
20  * Software is furnished to do so, subject to the following conditions:
21  *
22  * The above copyright notice and this permission notice shall be included
23  * in all copies or substantial portions of the Software.
24  *
25  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
26  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
27  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
28  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
29  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
30  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
31  * DEALINGS IN THE SOFTWARE.
32  ****************************************************************************/
33 
34 import gdal.cpl.port;
35 
36 import core.stdc.stdio : FILE;
37 
38 /**
39 * I did not provide bindings for all the functions in this header, I only
40 * wanted the memory management functions. The rest are not needed to use
41 * GDAL in an application.
42 */
43 /**
44  * \file cpl_vsi.h
45  *
46  * Standard C Covers
47  *
48  * The VSI functions are intended to be hookable aliases for Standard C
49  * I/O, memory allocation and other system functions. They are intended
50  * to allow virtualization of disk I/O so that non file data sources
51  * can be made to appear as files, and so that additional error trapping
52  * and reporting can be interested.  The memory access API is aliased
53  * so that special application memory management services can be used.
54  *
55  * It is intended that each of these functions retains exactly the same
56  * calling pattern as the original Standard C functions they relate to.
57  * This means we don't have to provide custom documentation, and also means
58  * that the default implementation is very simple.
59  */
60 
61 extern (C):
62 FILE * VSIFOpen(const(char) *, const(char) *);
63 int  VSIFClose(FILE *);
64 int  VSIFSeek(FILE *, int , int );
65 int  VSIFTell(FILE *);
66 void  VSIRewind(FILE *);
67 void  VSIFFlush(FILE *);
68 
69 size_t  VSIFRead(void *, size_t , size_t , FILE *);
70 size_t  VSIFWrite(void *, size_t , size_t , FILE *);
71 char * VSIFGets(char *, int , FILE *);
72 int  VSIFPuts(const(char) *, FILE *);
73 int  VSIFPrintf(FILE *, const(char) *,...);
74 
75 int  VSIFGetc(FILE *);
76 int  VSIFPutc(int , FILE *);
77 int  VSIUngetc(int , FILE *);
78 int  VSIFEof(FILE *);
79 
80 /* ==================================================================== */
81 /*      64bit stdio file access functions.  If we have a big size       */
82 /*      defined, then provide prototypes for the large file API,        */
83 /*      otherwise redefine to use the regular api.                      */
84 /* ==================================================================== */
85 alias GUIntBig vsi_l_offset;
86 
87 alias GUINTBIG_MAX VSI_L_OFFSET_MAX;
88 alias FILE VSILFILE;
89 
90 VSILFILE * VSIFOpenL(const(char) *, const(char) *);
91 VSILFILE * VSIFOpenExL(const(char) *, const(char) *, int );
92 int  VSIFCloseL(VSILFILE *);
93 int  VSIFSeekL(VSILFILE *, vsi_l_offset , int );
94 vsi_l_offset  VSIFTellL(VSILFILE *);
95 void  VSIRewindL(VSILFILE *);
96 size_t  VSIFReadL(void *, size_t , size_t , VSILFILE *);
97 int  VSIFReadMultiRangeL(int nRanges, void **ppData, vsi_l_offset *panOffsets, size_t *panSizes, VSILFILE *);
98 size_t  VSIFWriteL(void *, size_t , size_t , VSILFILE *);
99 int  VSIFEofL(VSILFILE *);
100 int  VSIFTruncateL(VSILFILE *, vsi_l_offset );
101 int  VSIFFlushL(VSILFILE *);
102 int  VSIFPrintfL(VSILFILE *, const(char) *,...);
103 int  VSIFPutcL(int , VSILFILE *);
104 
105 int  VSIIngestFile(VSILFILE *fp, const(char) *pszFilename, GByte **ppabyRet, vsi_l_offset *pnSize, GIntBig nMaxSize);
106 
107 /* ==================================================================== */
108 /*      Memory allocation                                               */
109 /* ==================================================================== */
110 
111 void * VSICalloc(size_t , size_t );
112 void * VSIMalloc(size_t );
113 void  VSIFree(void *);
114 void * VSIRealloc(void *, size_t );
115 char * VSIStrdup(const(char) *);
116 
117 /**
118  VSIMalloc2 allocates (nSize1 * nSize2) bytes.
119  In case of overflow of the multiplication, or if memory allocation fails, a
120  NULL pointer is returned and a CE_Failure error is raised with CPLError().
121  If nSize1 == 0 || nSize2 == 0, a NULL pointer will also be returned.
122  CPLFree() or VSIFree() can be used to free memory allocated by this function.
123 */
124 void * VSIMalloc2(size_t nSize1, size_t nSize2);
125 
126 /**
127  VSIMalloc3 allocates (nSize1 * nSize2 * nSize3) bytes.
128  In case of overflow of the multiplication, or if memory allocation fails, a
129  NULL pointer is returned and a CE_Failure error is raised with CPLError().
130  If nSize1 == 0 || nSize2 == 0 || nSize3 == 0, a NULL pointer will also be returned.
131  CPLFree() or VSIFree() can be used to free memory allocated by this function.
132 */
133 void * VSIMalloc3(size_t nSize1, size_t nSize2, size_t nSize3);
134 
135 void * VSIMallocVerbose(size_t nSize, const(char) *pszFile, int nLine);
136 void * VSIMalloc2Verbose(size_t nSize1, size_t nSize2, const(char) *pszFile, int nLine);
137 
138 void * VSIMalloc3Verbose(size_t nSize1, size_t nSize2, size_t nSize3, const(char) *pszFile, int nLine);
139 
140 void * VSICallocVerbose(size_t nCount, size_t nSize, const(char) *pszFile, int nLine);
141 
142 void * VSIReallocVerbose(void *pOldPtr, size_t nNewSize, const(char) *pszFile, int nLine);
143 
144 char * VSIStrdupVerbose(const(char) *pszStr, const(char) *pszFile, int nLine);
145 
146 
147 GIntBig  CPLGetPhysicalRAM();
148 GIntBig  CPLGetUsablePhysicalRAM();
149 
150 /* ==================================================================== */
151 /*      Other...                                                        */
152 /* ==================================================================== */
153 
154 alias VSIReadDir CPLReadDir;
155 char ** VSIReadDir(const(char) *);
156 char ** VSIReadDirRecursive(const(char) *pszPath);
157 char ** VSIReadDirEx(const(char) *pszPath, int nMaxFiles);
158 int  VSIMkdir(const(char) *pathname, int mode);
159 int  VSIRmdir(const(char) *pathname);
160 int  VSIUnlink(const(char) *pathname);
161 int  VSIRename(const(char) *oldpath, const(char) *newpath);
162 char * VSIStrerror(int );
163 GIntBig  VSIGetDiskFreeSpace(const(char) *pszDirname);
164 
165 /* ==================================================================== */
166 /*      Install special file access handlers.                           */
167 /* ==================================================================== */
168 void  VSIInstallMemFileHandler();
169 void  VSIInstallLargeFileHandler();
170 void  VSIInstallSubFileHandler();
171 void  VSIInstallCurlFileHandler();
172 void  VSIInstallCurlStreamingFileHandler();
173 void  VSIInstallS3FileHandler();
174 void  VSIInstallS3StreamingFileHandler();
175 void  VSIInstallGZipFileHandler();
176 void  VSIInstallZipFileHandler();
177 void  VSIInstallStdinHandler();
178 void  VSIInstallStdoutHandler();
179 void  VSIInstallSparseFileHandler();
180 void  VSIInstallTarFileHandler();
181 void  VSIInstallCryptFileHandler();
182 void  VSISetCryptKey(GByte *pabyKey, int nKeySize);
183 void  VSICleanupFileManager();
184 
185 VSILFILE * VSIFileFromMemBuffer(const(char *)pszFilename, GByte *pabyData, vsi_l_offset nDataLength, int bTakeOwnership);
186 GByte * VSIGetMemFileBuffer(const(char) *pszFilename, vsi_l_offset *pnDataLength, int bUnlinkAndSeize);
187 
188 alias size_t  function(void *ptr, size_t size, size_t nmemb, FILE *stream)VSIWriteFunction;
189 void  VSIStdoutSetRedirection(VSIWriteFunction pFct, FILE *stream);