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/5268/head
parent
1062a4cc00
commit
8fc6aed28c
|
@ -451,6 +451,7 @@ int _lseek(FILEHANDLE fh, int offset, int whence)
|
||||||
#if defined(__ARMCC_VERSION)
|
#if defined(__ARMCC_VERSION)
|
||||||
int whence = SEEK_SET;
|
int whence = SEEK_SET;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (fh < 3) {
|
if (fh < 3) {
|
||||||
errno = ESPIPE;
|
errno = ESPIPE;
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -541,14 +542,22 @@ extern "C" __value_in_regs struct __initial_stackheap __user_setup_stackheap(uin
|
||||||
|
|
||||||
|
|
||||||
#if !defined(__ARMCC_VERSION) && !defined(__ICCARM__)
|
#if !defined(__ARMCC_VERSION) && !defined(__ICCARM__)
|
||||||
extern "C" int _fstat(int fd, struct stat *st) {
|
extern "C" int _fstat(int fh, struct stat *st) {
|
||||||
if (fd < 3) {
|
if (fh < 3) {
|
||||||
st->st_mode = S_IFCHR;
|
st->st_mode = S_IFCHR;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FileHandle* fhc = filehandles[fh-3];
|
||||||
|
if (fhc == NULL) {
|
||||||
errno = EBADF;
|
errno = EBADF;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
st->st_mode = fhc->isatty() ? S_IFCHR : S_IFREG;
|
||||||
|
st->st_size = fhc->size();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace std {
|
namespace std {
|
||||||
|
|
Loading…
Reference in New Issue