Skip to content

fs: Fix fstat retarget for regular files #5203

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 5, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions platform/mbed_retarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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

Expand Down