mirror of https://github.com/ARMmbed/mbed-os.git
fs: Fixed fstat retarget for regular files
GCC's newlib library depends on fstat to get in-flight information about a file's type an size. A working fstat for regular files is needed for seek and related functions to work correctly.pull/5203/head
parent
c6f655c02e
commit
01326910c0
|
|
@ -446,6 +446,7 @@ int _lseek(FILEHANDLE fh, int offset, int whence)
|
|||
#if defined(__ARMCC_VERSION)
|
||||
int whence = SEEK_SET;
|
||||
#endif
|
||||
|
||||
if (fh < 3) {
|
||||
errno = ESPIPE;
|
||||
return -1;
|
||||
|
|
@ -536,13 +537,21 @@ extern "C" __value_in_regs struct __initial_stackheap __user_setup_stackheap(uin
|
|||
|
||||
|
||||
#if !defined(__ARMCC_VERSION) && !defined(__ICCARM__)
|
||||
extern "C" int _fstat(int fd, struct stat *st) {
|
||||
if (fd < 3) {
|
||||
extern "C" int _fstat(int fh, struct stat *st) {
|
||||
if (fh < 3) {
|
||||
st->st_mode = S_IFCHR;
|
||||
return 0;
|
||||
}
|
||||
errno = EBADF;
|
||||
return -1;
|
||||
|
||||
FileHandle* fhc = filehandles[fh-3];
|
||||
if (fhc == NULL) {
|
||||
errno = EBADF;
|
||||
return -1;
|
||||
}
|
||||
|
||||
st->st_mode = fhc->isatty() ? S_IFCHR : S_IFREG;
|
||||
st->st_size = fhc->size();
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue