Skip to content

Commit

Permalink
Use ferror(f) instead of errno
Browse files Browse the repository at this point in the history
On some ROMs, errno is non-zero even when fread was successful, leading to
"Invalid argument" errors during startup.

Fixes rovo89#25
  • Loading branch information
rovo89 committed Mar 8, 2015
1 parent 676e738 commit 5d02d5d
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions xposed_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,12 +190,13 @@ void* looper(void* unused __attribute__((unused))) {
break;
}

if (data->offset > 0)
fseek(f, data->offset, SEEK_SET);
if (data->offset > 0 && fseek(f, data->offset, SEEK_SET) != 0) {
shared->error = ferror(f);
break;
}

errno = 0;
data->bytesRead = fread(data->content, 1, sizeof(data->content), f);
shared->error = errno;
shared->error = ferror(f);
data->eof = feof(f);

fclose(f);
Expand Down Expand Up @@ -732,17 +733,15 @@ status_t XposedService::readFile(const String16& filename16, int32_t offset, int
}

// Seek to correct offset
if (offset > 0) {
fseek(f, offset, SEEK_SET);
if (offset > 0 && fseek(f, offset, SEEK_SET) != 0) {
free(*buffer);
*buffer = NULL;
return ferror(f);
}

// Read the file
errno = 0;
*bytesRead = fread(*buffer, 1, length, f);
status_t err = errno;
if (*bytesRead < length) {
err = EIO;
}
status_t err = ferror(f);
if (err != 0) {
free(*buffer);
*buffer = NULL;
Expand Down

0 comments on commit 5d02d5d

Please sign in to comment.