Skip to content

Commit 59fcda2

Browse files
committed
fixed return values for ti_(Rewind/Tell/GetSize) and fixed ftell
1 parent 9e250a3 commit 59fcda2

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/fileioc/fileioc.asm

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -827,8 +827,8 @@ ti_Rewind:
827827
or a, a
828828
sbc hl, hl
829829
ret
830-
scf
831830
.ret_neg_one:
831+
scf
832832
sbc hl, hl
833833
ret
834834

@@ -850,6 +850,7 @@ ti_Tell:
850850
pop hl
851851
ret
852852
.ret_neg_one:
853+
scf
853854
sbc hl, hl
854855
ret
855856

@@ -871,6 +872,7 @@ ti_GetSize:
871872
pop hl
872873
ret
873874
.ret_neg_one:
875+
scf
874876
sbc hl, hl
875877
ret
876878

src/libc/ftell.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include <stdio.h>
22
#include <fileioc.h>
3+
#include <stdint.h>
34

45
long int __attribute__((weak)) ftell(FILE *stream)
56
{
@@ -11,5 +12,10 @@ long int __attribute__((weak)) ftell(FILE *stream)
1112
return -1L;
1213
}
1314

14-
return (long int)ti_Tell(stream->slot);
15+
// ti_Tell shouldn't return a value greater than OS_VAR_MAX_SIZE (65512) unless an error occurs
16+
uint16_t ret = ti_Tell(stream->slot);
17+
if (ret == UINT16_MAX) {
18+
return -1L;
19+
}
20+
return (long int)ret;
1521
}

0 commit comments

Comments
 (0)