Ignore:
Timestamp:
04/05/11 15:01:41 (13 years ago)
Author:
tim
Message:

several fixes for pyregfi Windows portability
better error handling within pyregfi

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/python/pyregfi/structures.py

    r225 r226  
    1313from ctypes import *
    1414
     15is_win32 = hasattr(ctypes, 'windll')
    1516
    1617# XXX: can we always be sure enums are this size?
     
    6162        except Exception:
    6263            traceback.print_exc()
    63             # XXX: os.EX_IOERR may not be available on Windoze
    64             set_errno(os.EX_IOERR)
     64            set_errno(74) # os.EX_IOERR
    6565            return -1
    6666
     
    7676        except Exception:
    7777            traceback.print_exc()
    78             # XXX: os.EX_IOERR may not be available on Windoze
    79             set_errno(os.EX_IOERR)
     78            set_errno(74) # os.EX_IOERR
    8079            return -1
    8180        return len(tmp)
     
    8483# Load libregfi according to platform
    8584regfi = None
    86 if hasattr(ctypes, 'windll'):
     85if is_win32:
     86    # XXX: Using C calling conventions on cross-compiled DLLs seems to work fine
     87    #      on Windows, but I'm not sure if stdcall symbols are supported
     88    #      correctly for native Windows binaries...
    8789    #regfi = ctypes.windll.libregfi
    88     regfi = ctypes.WinDLL('libregfi.dll', use_errno=True)
    89     CB_FACTORY = ctypes.WINFUNCTYPE
     90    #CB_FACTORY = ctypes.WINFUNCTYPE
     91    regfi = ctypes.CDLL('libregfi.dll', use_errno=True)
     92    CB_FACTORY = ctypes.CFUNCTYPE
    9093else:
    9194    regfi = ctypes.CDLL(ctypes.util.find_library('regfi'), use_errno=True)
    9295    CB_FACTORY = ctypes.CFUNCTYPE
    9396
    94 # XXX: how can we know for sure the size of off_t? 
    95 #      -D_FILE_OFFSET_BITS=64 might help, need to research this
    96 #      Also, may need to use something like ctypes_configure
    97 #seek_cb_type = CB_FACTORY(c_int64, POINTER(REGFI_RAW_FILE), c_uint64, c_int, use_errno=True)
    98 seek_cb_type = CB_FACTORY(c_int64, POINTER(REGFI_RAW_FILE), c_uint64, c_int)
    99 #read_cb_type = CB_FACTORY(c_int64, POINTER(REGFI_RAW_FILE), POINTER(c_char), c_size_t, use_errno=True)
    100 read_cb_type = CB_FACTORY(c_int64, POINTER(REGFI_RAW_FILE), POINTER(c_char), c_size_t)
     97seek_cb_type = CB_FACTORY(c_int64, POINTER(REGFI_RAW_FILE), c_uint64, c_int, use_errno=True)
     98read_cb_type = CB_FACTORY(c_int64, POINTER(REGFI_RAW_FILE), POINTER(c_char), c_size_t, use_errno=True)
    10199
    102100
Note: See TracChangeset for help on using the changeset viewer.