[io] removed IO_OP_POS, wrap IO_OP_SEEK with offset 0 and flag FILE_SEEK_CURRENT instead

This commit is contained in:
Martin Fouilleul 2023-05-31 11:38:17 +02:00
parent a1b3195ddf
commit c041b212ab
4 changed files with 5 additions and 49 deletions

View File

@ -43,7 +43,6 @@ enum
IO_OP_FSTAT, IO_OP_FSTAT,
IO_OP_POS,
IO_OP_SEEK, IO_OP_SEEK,
IO_OP_READ, IO_OP_READ,
IO_OP_WRITE, IO_OP_WRITE,

View File

@ -33,15 +33,6 @@ void file_close(file_handle file)
io_wait_single_req(&req); io_wait_single_req(&req);
} }
i64 file_pos(file_handle file)
{
io_req req = {.op = IO_OP_POS,
.handle = file};
io_cmp cmp = io_wait_single_req(&req);
return(cmp.offset);
}
i64 file_seek(file_handle file, i64 offset, file_whence whence) i64 file_seek(file_handle file, i64 offset, file_whence whence)
{ {
io_req req = {.op = IO_OP_SEEK, io_req req = {.op = IO_OP_SEEK,
@ -53,6 +44,11 @@ i64 file_seek(file_handle file, i64 offset, file_whence whence)
return(cmp.offset); return(cmp.offset);
} }
i64 file_pos(file_handle file)
{
return(file_seek(file, 0, FILE_SEEK_CURRENT));
}
u64 file_write(file_handle file, u64 size, char* buffer) u64 file_write(file_handle file, u64 size, char* buffer)
{ {
io_req req = {.op = IO_OP_WRITE, io_req req = {.op = IO_OP_WRITE,

View File

@ -364,19 +364,6 @@ io_cmp io_fstat(file_slot* slot, io_req* req)
return(cmp); return(cmp);
} }
io_cmp io_pos(file_slot* slot, io_req* req)
{
io_cmp cmp = {0};
cmp.result = lseek(slot->fd, 0, SEEK_CUR);
if(cmp.result < 0)
{
slot->error = io_convert_errno(errno);
cmp.error = slot->error;
}
return(cmp);
}
io_cmp io_seek(file_slot* slot, io_req* req) io_cmp io_seek(file_slot* slot, io_req* req)
{ {
io_cmp cmp = {0}; io_cmp cmp = {0};
@ -484,10 +471,6 @@ io_cmp io_wait_single_req(io_req* req)
cmp = io_write(slot, req); cmp = io_write(slot, req);
break; break;
case IO_OP_POS:
cmp = io_pos(slot, req);
break;
case IO_OP_SEEK: case IO_OP_SEEK:
cmp = io_seek(slot, req); cmp = io_seek(slot, req);
break; break;

View File

@ -320,24 +320,6 @@ io_cmp io_fstat(file_slot* slot, io_req* req)
return(cmp); return(cmp);
} }
io_cmp io_pos(file_slot* slot, io_req* req)
{
io_cmp cmp = {0};
LARGE_INTEGER off = {.QuadPart = req->offset};
LARGE_INTEGER newPos = {0};
if(!SetFilePointerEx(slot->h, off, &newPos, FILE_CURRENT))
{
slot->error = io_convert_win32_error(GetLastError());
cmp.error = slot->error;
}
else
{
cmp.result = newPos.QuadPart;
}
return(cmp);
}
io_cmp io_seek(file_slot* slot, io_req* req) io_cmp io_seek(file_slot* slot, io_req* req)
{ {
io_cmp cmp = {0}; io_cmp cmp = {0};
@ -460,10 +442,6 @@ io_cmp io_wait_single_req(io_req* req)
cmp = io_write(slot, req); cmp = io_write(slot, req);
break; break;
case IO_OP_POS:
cmp = io_pos(slot, req);
break;
case IO_OP_SEEK: case IO_OP_SEEK:
cmp = io_seek(slot, req); cmp = io_seek(slot, req);
break; break;