Some simple information syncing
This commit is contained in:
@@ -51,9 +51,6 @@ class File:
|
||||
self.is_append = False
|
||||
self._share_mode = share
|
||||
|
||||
stdio.printf("[FILE] __init__ filename=%s mode=%d share=%d\n", filename, mode, share)
|
||||
stdio.fflush(0)
|
||||
|
||||
access: ULONG = 0
|
||||
disposition: ULONG = w32.win32file.OPEN_EXISTING
|
||||
|
||||
@@ -100,18 +97,12 @@ class File:
|
||||
disposition = w32.win32file.OPEN_EXISTING
|
||||
self.can_read = True
|
||||
|
||||
stdio.printf("[FILE] before CreateFileA access=%d disp=%d share=%d\n", access, disposition, self._share_mode)
|
||||
stdio.fflush(0)
|
||||
self.handle = w32.win32file.CreateFileA(
|
||||
filename, access, self._share_mode,
|
||||
None, disposition, w32.win32file.FILE_ATTRIBUTE_NORMAL, None
|
||||
)
|
||||
stdio.printf("[FILE] after CreateFileA handle=%p\n", self.handle)
|
||||
stdio.fflush(0)
|
||||
|
||||
if self.handle == w32.win32base.INVALID_HANDLE_VALUE:
|
||||
stdio.printf("[FILE] FAIL: handle == INVALID_HANDLE_VALUE\n")
|
||||
stdio.fflush(0)
|
||||
self.closed = True
|
||||
return
|
||||
|
||||
@@ -202,21 +193,16 @@ class File:
|
||||
if self.closed: return FRESULT.ERR_CLOSED
|
||||
if not self.can_read: return FRESULT.ERR_PERM
|
||||
if max_count < 2: return FRESULT.ERR
|
||||
# stdio.printf("[DBG read_all] before size()\n")
|
||||
file_size: LONGLONG = self.size()
|
||||
# stdio.printf("[DBG read_all] after size(), file_size=%lld\n", file_size)
|
||||
if file_size < 0: return FRESULT.ERR_IO
|
||||
to_read: ULONG = 0
|
||||
if file_size < max_count - 1:
|
||||
to_read = ULONG(file_size)
|
||||
else:
|
||||
to_read = max_count - 1
|
||||
# stdio.printf("[DBG read_all] to_read=%u, before seek\n", to_read)
|
||||
self.seek(0, SEEK_SET)
|
||||
# stdio.printf("[DBG read_all] after seek, before ReadFile\n")
|
||||
bytes_read: ULONG = 0
|
||||
result: BOOL = w32.win32file.ReadFile(self.handle, buf, to_read, t.CPtr(c.Addr(bytes_read)), None)
|
||||
# stdio.printf("[DBG read_all] after ReadFile, result=%d, bytes_read=%u\n", result, bytes_read)
|
||||
if result == 0: return FRESULT.ERR_IO
|
||||
if bytes_read < max_count:
|
||||
buf[bytes_read] = 0
|
||||
|
||||
@@ -5,7 +5,7 @@ HANDLE: t.CTypedef = VOIDPTR
|
||||
LPCSTR: t.CTypedef = t.CConst | t.CChar | t.CPtr
|
||||
LPCWSTR: t.CTypedef = t.CConst | t.CUnsignedShort | t.CPtr
|
||||
|
||||
INVALID_HANDLE_VALUE: t.CDefine = 0xFFFFFFFF
|
||||
INVALID_HANDLE_VALUE: t.CDefine = -1
|
||||
NULL: t.CDefine = 0
|
||||
TRUE: t.CDefine = 1
|
||||
FALSE: t.CDefine = 0
|
||||
|
||||
Reference in New Issue
Block a user