Changeset 5539 for pjproject/trunk/pjlib/src/pj/file_access_win32.c
- Timestamp:
- Jan 23, 2017 4:32:34 AM (8 years ago)
- Location:
- pjproject/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk
- Property svn:mergeinfo changed
/pjproject/branches/projects/uwp (added) merged: 5208,5210-5211,5254,5256,5298,5439,5470,5497,5511-5515,5526,5528-5529,5532,5538 -
Property
svn:global-ignores
set to
bin
obj
lib
Bin
output
Debug
Generated[^A-Ba-b0-9]Files
Service[^A-Ba-b0-9]References
*.opendb
*.db
*.user
- Property svn:mergeinfo changed
-
pjproject/trunk/pjlib/src/pj/file_access_win32.c
r3553 r5539 34 34 #endif 35 35 36 static pj_status_t get_file_size(HANDLE hFile, pj_off_t *size) 37 { 38 #if defined(PJ_WIN32_WINPHONE8) && PJ_WIN32_WINPHONE8 39 FILE_COMPRESSION_INFO fileInfo; 40 41 if (GetFileInformationByHandleEx(hFile, FileCompressionInfo, &fileInfo, 42 sizeof(FILE_COMPRESSION_INFO))) 43 { 44 *size = fileInfo.CompressedFileSize.QuadPart; 45 } 46 else { 47 *size = -1; 48 return PJ_RETURN_OS_ERROR(GetLastError()); 49 } 50 #else 51 DWORD sizeLo, sizeHi; 52 53 sizeLo = GetFileSize(hFile, &sizeHi); 54 if (sizeLo == INVALID_FILE_SIZE) { 55 DWORD dwStatus = GetLastError(); 56 if (dwStatus != NO_ERROR) { 57 *size = -1; 58 return PJ_RETURN_OS_ERROR(dwStatus); 59 } 60 } 61 *size = sizeHi; 62 *size = ((*size) << 32) + sizeLo; 63 #endif 64 return PJ_SUCCESS; 65 } 66 67 static HANDLE WINAPI create_file(LPCTSTR filename, DWORD desired_access, 68 DWORD share_mode, 69 LPSECURITY_ATTRIBUTES security_attributes, 70 DWORD creation_disposition, 71 DWORD flags_and_attributes, 72 HANDLE template_file) 73 { 74 #if defined(PJ_WIN32_WINPHONE8) && PJ_WIN32_WINPHONE8 75 PJ_UNUSED_ARG(security_attributes); 76 PJ_UNUSED_ARG(flags_and_attributes); 77 PJ_UNUSED_ARG(template_file); 78 79 return CreateFile2(filename, desired_access, share_mode, 80 creation_disposition, NULL); 81 #else 82 return CreateFile(filename, desired_access, share_mode, 83 security_attributes, creation_disposition, 84 flags_and_attributes, template_file); 85 #endif 86 } 36 87 37 88 /* … … 45 96 PJ_ASSERT_RETURN(filename != NULL, 0); 46 97 47 hFile = CreateFile(PJ_STRING_TO_NATIVE(filename,wfilename,sizeof(wfilename)), 48 CONTROL_ACCESS, 49 FILE_SHARE_READ, NULL, 50 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); 98 hFile = create_file(PJ_STRING_TO_NATIVE(filename, 99 wfilename, sizeof(wfilename)), 100 CONTROL_ACCESS, 101 FILE_SHARE_READ, NULL, 102 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); 51 103 if (hFile == INVALID_HANDLE_VALUE) 52 104 return 0; … … 63 115 { 64 116 PJ_DECL_UNICODE_TEMP_BUF(wfilename,256) 65 HANDLE hFile; 66 DWORD sizeLo, sizeHi; 117 HANDLE hFile; 67 118 pj_off_t size; 68 119 69 120 PJ_ASSERT_RETURN(filename != NULL, -1); 70 121 71 hFile = CreateFile(PJ_STRING_TO_NATIVE(filename, wfilename,sizeof(wfilename)), 72 CONTROL_ACCESS, 73 FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, 74 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); 122 hFile = create_file(PJ_STRING_TO_NATIVE(filename, 123 wfilename, sizeof(wfilename)), 124 CONTROL_ACCESS, 125 FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, 126 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); 75 127 if (hFile == INVALID_HANDLE_VALUE) 76 128 return -1; 77 129 78 sizeLo = GetFileSize(hFile, &sizeHi); 79 if (sizeLo == INVALID_FILE_SIZE) { 80 DWORD dwStatus = GetLastError(); 81 if (dwStatus != NO_ERROR) { 82 CloseHandle(hFile); 83 return -1; 84 } 85 } 86 87 size = sizeHi; 88 size = (size << 32) + sizeLo; 130 get_file_size(hFile, &size); 89 131 90 132 CloseHandle(hFile); … … 139 181 pj_time_val *time_val) 140 182 { 183 #if !defined(PJ_WIN32_WINPHONE8) || !PJ_WIN32_WINPHONE8 141 184 FILETIME local_file_time; 185 #endif 186 142 187 SYSTEMTIME localTime; 143 188 pj_parsed_time pt; 144 189 190 #if !defined(PJ_WIN32_WINPHONE8) || !PJ_WIN32_WINPHONE8 145 191 if (!FileTimeToLocalFileTime(file_time, &local_file_time)) 146 192 return PJ_RETURN_OS_ERROR(GetLastError()); 193 #endif 147 194 148 195 if (!FileTimeToSystemTime(file_time, &localTime)) … … 173 220 PJ_DECL_UNICODE_TEMP_BUF(wfilename,256) 174 221 HANDLE hFile; 175 DWORD sizeLo, sizeHi;176 222 FILETIME creationTime, accessTime, writeTime; 223 #if defined(PJ_WIN32_WINPHONE8) && PJ_WIN32_WINPHONE8 224 FILE_BASIC_INFO fileInfo; 225 #endif 177 226 178 227 PJ_ASSERT_RETURN(filename!=NULL && stat!=NULL, PJ_EINVAL); 179 228 180 hFile = CreateFile(PJ_STRING_TO_NATIVE(filename,wfilename,sizeof(wfilename)), 181 CONTROL_ACCESS, 182 FILE_SHARE_READ, NULL, 183 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); 229 hFile = create_file(PJ_STRING_TO_NATIVE(filename, 230 wfilename, sizeof(wfilename)), 231 CONTROL_ACCESS, 232 FILE_SHARE_READ, NULL, 233 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); 184 234 if (hFile == INVALID_HANDLE_VALUE) 185 235 return PJ_RETURN_OS_ERROR(GetLastError()); 186 236 187 sizeLo = GetFileSize(hFile, &sizeHi); 188 if (sizeLo == INVALID_FILE_SIZE) { 189 DWORD dwStatus = GetLastError(); 190 if (dwStatus != NO_ERROR) { 191 CloseHandle(hFile); 192 return PJ_RETURN_OS_ERROR(dwStatus); 193 } 194 } 195 196 stat->size = sizeHi; 197 stat->size = (stat->size << 32) + sizeLo; 198 199 if (GetFileTime(hFile, &creationTime, &accessTime, &writeTime)==FALSE) { 200 DWORD dwStatus = GetLastError(); 201 CloseHandle(hFile); 202 return PJ_RETURN_OS_ERROR(dwStatus); 203 } 237 if (get_file_size(hFile, &stat->size) != PJ_SUCCESS) { 238 CloseHandle(hFile); 239 return PJ_RETURN_OS_ERROR(GetLastError()); 240 } 241 242 #if defined(PJ_WIN32_WINPHONE8) && PJ_WIN32_WINPHONE8 243 if (GetFileInformationByHandleEx(hFile, FileBasicInfo, &fileInfo, 244 sizeof(FILE_BASIC_INFO))) 245 { 246 creationTime.dwLowDateTime = fileInfo.CreationTime.LowPart; 247 creationTime.dwHighDateTime = fileInfo.CreationTime.HighPart; 248 accessTime.dwLowDateTime = fileInfo.LastAccessTime.LowPart; 249 accessTime.dwHighDateTime = fileInfo.LastAccessTime.HighPart; 250 writeTime.dwLowDateTime = fileInfo.LastWriteTime.LowPart; 251 writeTime.dwHighDateTime = fileInfo.LastWriteTime.HighPart; 252 } 253 else { 254 CloseHandle(hFile); 255 return PJ_RETURN_OS_ERROR(GetLastError()); 256 } 257 #else 258 if (GetFileTime(hFile, &creationTime, &accessTime, &writeTime) == FALSE) { 259 DWORD dwStatus = GetLastError(); 260 CloseHandle(hFile); 261 return PJ_RETURN_OS_ERROR(dwStatus); 262 } 263 #endif 204 264 205 265 CloseHandle(hFile);
Note: See TracChangeset
for help on using the changeset viewer.