Memotech-Bill / pico-filesystem

Add support for STDIO on Files for the Raspberry Pi Pico using NEWLIB hooks
Other
16 stars 2 forks source link

fat_lseek does not use pos argument #11

Closed chrisgjohnson closed 2 months ago

chrisgjohnson commented 2 months ago

I think there's a bug in the implementation of fat_lseek in pfs_fat.c:171, where the pos argument is not used, but the integer values of the flags SEEK_CUR and SEEK_END are added to the offset instead:

STATIC long fat_lseek (struct pfs_file *pfs_fd, long pos, int whence)
{
    struct fat_file *fd = (struct fat_file *) pfs_fd;
    switch (whence)
    {
        case SEEK_CUR: whence += f_tell (&fd->fil); break;
        case SEEK_END: whence += f_size (&fd->fil); break;
    }
    FRESULT r = f_lseek (&fd->fil, whence);
    return ( r == FR_OK ) ? f_tell (&fd->fil) : fat_error (r);
}
chrisgjohnson commented 2 months ago

Added pull request #12 with a proposed fix.

Memotech-Bill commented 2 months ago

Thank you. I have merged your pull request.