Ignore:
Timestamp:
Jan 23, 2017 4:32:34 AM (7 years ago)
Author:
nanang
Message:

Re #1900: Reintegrated works in UWP branch to trunk.

Location:
pjproject/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk

  • pjproject/trunk/pjlib/src/pj/file_io_win32.c

    r4537 r5539  
    2222#include <pj/errno.h> 
    2323#include <pj/assert.h> 
     24#include <pj/string.h> 
    2425 
    2526#include <windows.h> 
     
    2829#   define INVALID_SET_FILE_POINTER     ((DWORD)-1) 
    2930#endif 
     31 
     32static pj_status_t set_file_pointer(pj_oshandle_t fd, 
     33    pj_off_t offset, 
     34    pj_off_t* newPos, 
     35    DWORD dwMoveMethod) 
     36{ 
     37#if defined(PJ_WIN32_WINPHONE8) && PJ_WIN32_WINPHONE8 
     38    LARGE_INTEGER liDistance, liNewPos; 
     39 
     40    liDistance.QuadPart = offset; 
     41    if (!SetFilePointerEx(fd, liDistance, &liNewPos, dwMoveMethod)) { 
     42        return PJ_RETURN_OS_ERROR(GetLastError()); 
     43    } 
     44    *newPos = liNewPos.QuadPart; 
     45#else 
     46    DWORD dwNewPos; 
     47    LONG  hi32; 
     48 
     49    hi32 = (LONG)(offset >> 32); 
     50 
     51    dwNewPos = SetFilePointer(fd, (long)offset, &hi32, dwMoveMethod); 
     52    if (dwNewPos == (DWORD)INVALID_SET_FILE_POINTER) { 
     53        DWORD dwStatus = GetLastError(); 
     54        if (dwStatus != 0) 
     55            return PJ_RETURN_OS_ERROR(dwStatus); 
     56        /* dwNewPos actually is not an error. */ 
     57    } 
     58    *newPos = hi32; 
     59    *newPos = (*newPos << 32) + dwNewPos; 
     60#endif 
     61 
     62    return PJ_SUCCESS; 
     63} 
    3064 
    3165/** 
     
    4680                                  pj_oshandle_t *fd) 
    4781{ 
    48     PJ_DECL_UNICODE_TEMP_BUF(wpathname,256) 
     82    PJ_DECL_UNICODE_TEMP_BUF(wpathname, 256) 
    4983    HANDLE hFile; 
    5084    DWORD dwDesiredAccess = 0; 
     
    87121 
    88122    dwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE; 
     123     
    89124    dwFlagsAndAttributes = FILE_ATTRIBUTE_NORMAL; 
    90125 
    91     hFile = CreateFile(PJ_STRING_TO_NATIVE(pathname,wpathname,sizeof(wpathname)),  
     126#if defined(PJ_WIN32_WINPHONE8) && PJ_WIN32_WINPHONE8   
     127    hFile = CreateFile2(PJ_STRING_TO_NATIVE(pathname, 
     128                        wpathname, sizeof(wpathname)), 
     129                        dwDesiredAccess, dwShareMode, dwCreationDisposition, 
     130                        NULL); 
     131#else 
     132    hFile = CreateFile(PJ_STRING_TO_NATIVE(pathname, 
     133                       wpathname, sizeof(wpathname)), 
    92134                       dwDesiredAccess, dwShareMode, NULL, 
    93                        dwCreationDisposition, dwFlagsAndAttributes, NULL); 
     135                       dwCreationDisposition, dwFlagsAndAttributes, NULL); 
     136#endif 
     137 
    94138    if (hFile == INVALID_HANDLE_VALUE) { 
     139        DWORD lastErr = GetLastError();  
    95140        *fd = 0; 
    96         return PJ_RETURN_OS_ERROR(GetLastError()); 
     141        return PJ_RETURN_OS_ERROR(lastErr); 
    97142    } 
    98143 
     
    181226{ 
    182227    DWORD dwMoveMethod; 
    183     DWORD dwNewPos; 
    184     LONG  hi32; 
     228    pj_off_t newPos; 
    185229 
    186230    if (whence == PJ_SEEK_SET) 
     
    195239    } 
    196240 
    197     hi32 = (LONG)(offset >> 32); 
    198     dwNewPos = SetFilePointer(fd, (long)offset, &hi32, dwMoveMethod); 
    199     if (dwNewPos == (DWORD)INVALID_SET_FILE_POINTER) { 
    200         DWORD dwStatus = GetLastError(); 
    201         if (dwStatus != 0) 
    202             return PJ_RETURN_OS_ERROR(dwStatus); 
    203         /* dwNewPos actually is not an error. */ 
     241    if (set_file_pointer(fd, offset, &newPos, dwMoveMethod) != PJ_SUCCESS) { 
     242        return PJ_RETURN_OS_ERROR(GetLastError()); 
    204243    } 
    205244 
     
    210249                                    pj_off_t *pos) 
    211250{ 
    212     LONG hi32 = 0; 
    213     DWORD lo32; 
    214  
    215     lo32 = SetFilePointer(fd, 0, &hi32, FILE_CURRENT); 
    216     if (lo32 == (DWORD)INVALID_SET_FILE_POINTER) { 
    217         DWORD dwStatus = GetLastError(); 
    218         if (dwStatus != 0) 
    219             return PJ_RETURN_OS_ERROR(dwStatus); 
    220     } 
    221  
    222     *pos = hi32; 
    223     *pos = (*pos << 32) + lo32; 
     251    if (set_file_pointer(fd, 0, pos, FILE_CURRENT) != PJ_SUCCESS) { 
     252        return PJ_RETURN_OS_ERROR(GetLastError()); 
     253    } 
     254 
    224255    return PJ_SUCCESS; 
    225256} 
Note: See TracChangeset for help on using the changeset viewer.