<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html><head><meta name="robots" content="noindex"> <meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"> <title>cpl_vsil_win32.cpp Source File</title> <link href="doxygen.css" rel="stylesheet" type="text/css"> </head><body bgcolor="#ffffff"> <!-- Generated by Doxygen 1.2.3-20001105 on Thu Mar 28 09:47:28 2002 --> <center> <a class="qindex" href="index.html">Main Page</a> <a class="qindex" href="hierarchy.html">Class Hierarchy</a> <a class="qindex" href="annotated.html">Compound List</a> <a class="qindex" href="files.html">File List</a> <a class="qindex" href="functions.html">Compound Members</a> <a class="qindex" href="globals.html">File Members</a> <a class="qindex" href="pages.html">Related Pages</a> </center> <hr><h1>cpl_vsil_win32.cpp</h1><div class="fragment"><pre>00001 <font class="comment">/**********************************************************************</font> 00002 <font class="comment"> * $Id: cpl_vsil_win32_cpp-source.html,v 1.5 2002/04/16 13:11:48 warmerda Exp $</font> 00003 <font class="comment"> *</font> 00004 <font class="comment"> * Project: CPL - Common Portability Library</font> 00005 <font class="comment"> * Purpose: Implement VSI large file api for Win32.</font> 00006 <font class="comment"> * Author: Frank Warmerdam, warmerdam@pobox.com</font> 00007 <font class="comment"> *</font> 00008 <font class="comment"> **********************************************************************</font> 00009 <font class="comment"> * Copyright (c) 2000, Frank Warmerdam</font> 00010 <font class="comment"> *</font> 00011 <font class="comment"> * Permission is hereby granted, free of charge, to any person obtaining a</font> 00012 <font class="comment"> * copy of this software and associated documentation files (the "Software"),</font> 00013 <font class="comment"> * to deal in the Software without restriction, including without limitation</font> 00014 <font class="comment"> * the rights to use, copy, modify, merge, publish, distribute, sublicense,</font> 00015 <font class="comment"> * and/or sell copies of the Software, and to permit persons to whom the</font> 00016 <font class="comment"> * Software is furnished to do so, subject to the following conditions:</font> 00017 <font class="comment"> * </font> 00018 <font class="comment"> * The above copyright notice and this permission notice shall be included</font> 00019 <font class="comment"> * in all copies or substantial portions of the Software.</font> 00020 <font class="comment"> * </font> 00021 <font class="comment"> * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR</font> 00022 <font class="comment"> * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,</font> 00023 <font class="comment"> * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL</font> 00024 <font class="comment"> * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER</font> 00025 <font class="comment"> * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING</font> 00026 <font class="comment"> * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER </font> 00027 <font class="comment"> * DEALINGS IN THE SOFTWARE.</font> 00028 <font class="comment"> **********************************************************************</font> 00029 <font class="comment"> *</font> 00030 <font class="comment"> * $Log: cpl_vsil_win32_cpp-source.html,v $ 00030 <font class="comment"> * Revision 1.5 2002/04/16 13:11:48 warmerda 00030 <font class="comment"> * updated 00030 <font class="comment"> *</font> 00031 <font class="comment"> * Revision 1.5 2001/07/18 04:00:49 warmerda</font> 00032 <font class="comment"> * added CPL_CVSID</font> 00033 <font class="comment"> *</font> 00034 <font class="comment"> * Revision 1.4 2001/06/21 20:40:31 warmerda</font> 00035 <font class="comment"> * *** empty log message ***</font> 00036 <font class="comment"> *</font> 00037 <font class="comment"> * Revision 1.3 2001/06/11 13:47:07 warmerda</font> 00038 <font class="comment"> * initialize HighPart in VSIFTellL()</font> 00039 <font class="comment"> *</font> 00040 <font class="comment"> * Revision 1.2 2001/01/19 21:16:41 warmerda</font> 00041 <font class="comment"> * expanded tabs</font> 00042 <font class="comment"> *</font> 00043 <font class="comment"> * Revision 1.1 2001/01/03 16:16:59 warmerda</font> 00044 <font class="comment"> * New</font> 00045 <font class="comment"> *</font> 00046 <font class="comment"> */</font> 00047 00048 <font class="preprocessor">#include "<a class="code" href="cpl_vsi_h.html">cpl_vsi.h</a>"</font> 00049 00050 <font class="preprocessor">#if defined(WIN32)</font> 00051 <font class="preprocessor"></font> 00052 CPL_CVSID(<font class="stringliteral">"$Id: cpl_vsil_win32_cpp-source.html,v 1.5 2002/04/16 13:11:48 warmerda Exp $"</font>); 00053 00054 <font class="preprocessor">#include <windows.h></font> 00055 00056 <font class="comment">/************************************************************************/</font> 00057 <font class="comment">/* VSIFOpen() */</font> 00058 <font class="comment">/************************************************************************/</font> 00059 00060 FILE *VSIFOpenL( <font class="keyword">const</font> <font class="keywordtype">char</font> * pszFilename, <font class="keyword">const</font> <font class="keywordtype">char</font> * pszAccess )<font class="keyword"></font> 00061 <font class="keyword"></font> 00062 <font class="keyword"></font>{ 00063 DWORD dwDesiredAccess, dwCreationDisposition; 00064 HANDLE hFile; 00065 00066 <font class="keywordflow">if</font>( strchr(pszAccess, <font class="charliteral">'+'</font>) != NULL || strchr(pszAccess, <font class="charliteral">'w'</font>) != 0 ) 00067 dwDesiredAccess = GENERIC_READ | GENERIC_WRITE; 00068 <font class="keywordflow">else</font> 00069 dwDesiredAccess = GENERIC_READ; 00070 00071 <font class="keywordflow">if</font>( strstr(pszAccess, <font class="stringliteral">"w"</font>) != NULL ) 00072 dwCreationDisposition = CREATE_ALWAYS; 00073 <font class="keywordflow">else</font> 00074 dwCreationDisposition = OPEN_EXISTING; 00075 00076 hFile = CreateFile( pszFilename, dwDesiredAccess, 00077 FILE_SHARE_READ | FILE_SHARE_WRITE, 00078 NULL, dwCreationDisposition, 00079 (dwDesiredAccess == GENERIC_READ) ? 00080 FILE_ATTRIBUTE_READONLY : FILE_ATTRIBUTE_NORMAL, 00081 NULL ); 00082 00083 <font class="keywordflow">if</font>( hFile == INVALID_HANDLE_VALUE ) 00084 { 00085 <font class="keywordflow">return</font> NULL; 00086 } 00087 <font class="keywordflow">else</font> 00088 { 00089 <font class="keywordflow">return</font> (FILE *) hFile; 00090 } 00091 } 00092 00093 <font class="comment">/************************************************************************/</font> 00094 <font class="comment">/* VSIFCloseL() */</font> 00095 <font class="comment">/************************************************************************/</font> 00096 00097 <font class="keywordtype">int</font> VSIFCloseL( FILE * fp )<font class="keyword"></font> 00098 <font class="keyword"></font> 00099 <font class="keyword"></font>{ 00100 HANDLE hFile = (HANDLE) fp; 00101 00102 <font class="keywordflow">return</font> CloseHandle( hFile ) ? 0 : -1; 00103 } 00104 00105 <font class="comment">/************************************************************************/</font> 00106 <font class="comment">/* VSIFSeekL() */</font> 00107 <font class="comment">/************************************************************************/</font> 00108 00109 <font class="keywordtype">int</font> VSIFSeekL( FILE * fp, vsi_l_offset nOffset, <font class="keywordtype">int</font> nWhence )<font class="keyword"></font> 00110 <font class="keyword"></font> 00111 <font class="keyword"></font>{ 00112 HANDLE hFile = (HANDLE) fp; 00113 GUInt32 dwMoveMethod, dwMoveHigh; 00114 GUInt32 nMoveLow; 00115 LARGE_INTEGER li; 00116 00117 <font class="keywordflow">switch</font>(nWhence) 00118 { 00119 <font class="keywordflow">case</font> SEEK_CUR: 00120 dwMoveMethod = FILE_CURRENT; 00121 <font class="keywordflow">break</font>; 00122 <font class="keywordflow">case</font> SEEK_END: 00123 dwMoveMethod = FILE_END; 00124 <font class="keywordflow">break</font>; 00125 <font class="keywordflow">case</font> SEEK_SET: 00126 <font class="keywordflow">default</font>: 00127 dwMoveMethod = FILE_BEGIN; 00128 <font class="keywordflow">break</font>; 00129 } 00130 00131 li.QuadPart = nOffset; 00132 nMoveLow = li.LowPart; 00133 dwMoveHigh = li.HighPart; 00134 00135 SetLastError( 0 ); 00136 SetFilePointer(hFile, (LONG) nMoveLow, (PLONG)&dwMoveHigh, 00137 dwMoveMethod); 00138 00139 <font class="keywordflow">if</font>( GetLastError() != NO_ERROR ) 00140 { 00141 <font class="preprocessor">#ifdef notdef</font> 00142 <font class="preprocessor"></font> LPVOID lpMsgBuf = NULL; 00143 00144 FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER 00145 | FORMAT_MESSAGE_FROM_SYSTEM 00146 | FORMAT_MESSAGE_IGNORE_INSERTS, 00147 NULL, GetLastError(), 00148 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), 00149 (LPTSTR) &lpMsgBuf, 0, NULL ); 00150 00151 printf( <font class="stringliteral">"[ERROR %d]\n %s\n"</font>, GetLastError(), (<font class="keywordtype">char</font> *) lpMsgBuf ); 00152 printf( <font class="stringliteral">"nOffset=%u, nMoveLow=%u, dwMoveHigh=%u\n"</font>, 00153 (GUInt32) nOffset, nMoveLow, dwMoveHigh ); 00154 <font class="preprocessor">#endif</font> 00155 <font class="preprocessor"></font> 00156 <font class="keywordflow">return</font> -1; 00157 } 00158 <font class="keywordflow">else</font> 00159 <font class="keywordflow">return</font> 0; 00160 } 00161 00162 <font class="comment">/************************************************************************/</font> 00163 <font class="comment">/* VSIFTellL() */</font> 00164 <font class="comment">/************************************************************************/</font> 00165 00166 vsi_l_offset VSIFTellL( FILE * fp )<font class="keyword"></font> 00167 <font class="keyword"></font> 00168 <font class="keyword"></font>{ 00169 HANDLE hFile = (HANDLE) fp; 00170 DWORD dwMoveHigh=0, dwMoveLow; 00171 LARGE_INTEGER li; 00172 00173 li.HighPart = 0; 00174 li.LowPart = SetFilePointer( hFile, 0, (PLONG) &(li.HighPart), 00175 FILE_CURRENT ); 00176 00177 <font class="keywordflow">return</font> li.QuadPart; 00178 } 00179 00180 <font class="comment">/************************************************************************/</font> 00181 <font class="comment">/* VSIRewindL() */</font> 00182 <font class="comment">/************************************************************************/</font> 00183 00184 <font class="keywordtype">void</font> VSIRewindL( FILE * fp )<font class="keyword"></font> 00185 <font class="keyword"></font> 00186 <font class="keyword"></font>{ 00187 VSIFSeekL( fp, 0, SEEK_SET ); 00188 } 00189 00190 <font class="comment">/************************************************************************/</font> 00191 <font class="comment">/* VSIFFlushL() */</font> 00192 <font class="comment">/************************************************************************/</font> 00193 00194 <font class="keywordtype">void</font> VSIFFlushL( FILE * fp )<font class="keyword"></font> 00195 <font class="keyword"></font> 00196 <font class="keyword"></font>{ 00197 HANDLE hFile = (HANDLE) fp; 00198 00199 FlushFileBuffers( hFile ); 00200 } 00201 00202 <font class="comment">/************************************************************************/</font> 00203 <font class="comment">/* VSIFReadL() */</font> 00204 <font class="comment">/************************************************************************/</font> 00205 00206 size_t VSIFReadL( <font class="keywordtype">void</font> * pBuffer, size_t nSize, size_t nCount, FILE * fp )<font class="keyword"></font> 00207 <font class="keyword"></font> 00208 <font class="keyword"></font>{ 00209 HANDLE hFile = (HANDLE) fp; 00210 DWORD dwSizeRead; 00211 00212 <font class="keywordflow">if</font>( !ReadFile( hFile, pBuffer, nSize * nCount, &dwSizeRead, NULL ) ) 00213 <font class="keywordflow">return</font> 0; 00214 <font class="keywordflow">else</font> 00215 <font class="keywordflow">return</font> dwSizeRead / nSize; 00216 } 00217 00218 <font class="comment">/************************************************************************/</font> 00219 <font class="comment">/* VSIFWriteL() */</font> 00220 <font class="comment">/************************************************************************/</font> 00221 00222 size_t VSIFWriteL( <font class="keywordtype">void</font> * pBuffer, size_t nSize, size_t nCount, FILE * fp )<font class="keyword"></font> 00223 <font class="keyword"></font> 00224 <font class="keyword"></font>{ 00225 HANDLE hFile = (HANDLE) fp; 00226 DWORD dwSizeWritten; 00227 00228 <font class="keywordflow">if</font>( !WriteFile( hFile, pBuffer, nSize * nCount, &dwSizeWritten, NULL ) ) 00229 <font class="keywordflow">return</font> 0; 00230 <font class="keywordflow">else</font> 00231 <font class="keywordflow">return</font> dwSizeWritten / nSize; 00232 } 00233 00234 <font class="comment">/************************************************************************/</font> 00235 <font class="comment">/* VSIFEofL() */</font> 00236 <font class="comment">/************************************************************************/</font> 00237 00238 <font class="keywordtype">int</font> VSIFEofL( FILE * fp )<font class="keyword"></font> 00239 <font class="keyword"></font> 00240 <font class="keyword"></font>{ 00241 vsi_l_offset nCur, nEnd; 00242 00243 nCur = VSIFTell( fp ); 00244 VSIFSeekL( fp, 0, SEEK_END ); 00245 nEnd = VSIFTell( fp ); 00246 VSIFSeekL( fp, nCur, SEEK_SET ); 00247 00248 <font class="keywordflow">return</font> (nCur == nEnd); 00249 } 00250 00251 <font class="preprocessor">#endif </font><font class="comment">/* defined WIN32 */</font> 00252 </div></pre><hr><address><small>Generated at Thu Mar 28 09:47:28 2002 for GDAL by <a href="http://www.stack.nl/~dimitri/doxygen/index.html"> <img src="doxygen.gif" alt="doxygen" align="middle" border=0 width=110 height=53></a>1.2.3-20001105 written by <a href="mailto:dimitri@stack.nl">Dimitri van Heesch</a>, © 1997-2000</small></address> </body> </html>