Skip to content

Commit 24d3dbe

Browse files
committed
fix _ftello_r by wrapping it
1 parent 74a3cbe commit 24d3dbe

File tree

2 files changed

+23
-23
lines changed

2 files changed

+23
-23
lines changed

src/filesystem/fat.c

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -415,29 +415,6 @@ static int file_stat(filesystem_t *fs, const char *path, struct stat *st) {
415415
return 0;
416416
}
417417

418-
static int file_utimes(filesystem_t *fs, const char *path, const struct timeval times[2]) {
419-
filesystem_fat_context_t *context = fs->context;
420-
char fpath[PATH_MAX];
421-
fat_path_prefix(fpath, context->id, path);
422-
423-
struct tm *mtime = localtime(&times[0].tv_sec);
424-
425-
FILINFO f = {
426-
.fdate = (WORD)(((mtime->tm_year - 80) * 512U) | mtime->tm_mon * 32U | mtime->tm_mday),
427-
.ftime = (WORD)(mtime->tm_hour * 2048U | mtime->tm_min * 32U | mtime->tm_sec / 2U)
428-
};
429-
430-
mutex_enter_blocking(&context->_mutex);
431-
FRESULT res = f_utime(fpath, &f);
432-
mutex_exit(&context->_mutex);
433-
434-
if (res != FR_OK) {
435-
return fat_error_remap(res);
436-
}
437-
438-
return 0;
439-
}
440-
441418
static int file_open(filesystem_t *fs, fs_file_t *file, const char *path, int flags) {
442419
BYTE open_mode;
443420
if (flags & O_RDWR)

src/filesystem/vfs.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,29 @@ off_t _lseek(int fildes, off_t offset, int whence) {
562562
return _error_remap(pos);
563563
}
564564

565+
off_t __wrap__ftello_r(struct _reent *ptr, register FILE *fp) {
566+
(void)ptr;
567+
int fildes = fp->_file;
568+
auto_init_recursive_mutex(_mutex);
569+
recursive_mutex_enter_blocking(&_mutex);
570+
571+
if (!is_valid_file_descriptor(fildes)) {
572+
recursive_mutex_exit(&_mutex);
573+
return _error_remap(-EBADF);
574+
}
575+
fs_file_t *file = file_descriptor[FILENO_INDEX(fildes)].file;
576+
filesystem_t *fs = file_descriptor[FILENO_INDEX(fildes)].filesystem;
577+
if (fs == NULL) {
578+
recursive_mutex_exit(&_mutex);
579+
return _error_remap(-EBADF);
580+
}
581+
582+
off_t pos = fs->file_tell(fs, file);
583+
recursive_mutex_exit(&_mutex);
584+
585+
return _error_remap(pos);
586+
}
587+
565588
int ftruncate(int fildes, off_t length) {
566589
auto_init_recursive_mutex(_mutex);
567590
recursive_mutex_enter_blocking(&_mutex);

0 commit comments

Comments
 (0)