Add missing unlocks to _FAT_fread_r, thanks to dhewg

This commit is contained in:
Michael Chisholm 2008-12-23 12:58:17 +00:00
parent 4e6b2672c7
commit 18e980f050

View File

@ -346,6 +346,11 @@ ssize_t _FAT_read_r (struct _reent *r, int fd, char *ptr, size_t len) {
size_t remain; size_t remain;
bool flagNoError = true; bool flagNoError = true;
// Short circuit cases where len is 0 (or less)
if (len <= 0) {
return 0;
}
// Make sure we can actually read from the file // Make sure we can actually read from the file
if ((file == NULL) || !file->inUse || !file->read) { if ((file == NULL) || !file->inUse || !file->read) {
r->_errno = EBADF; r->_errno = EBADF;
@ -358,6 +363,7 @@ ssize_t _FAT_read_r (struct _reent *r, int fd, char *ptr, size_t len) {
// Don't try to read if the read pointer is past the end of file // Don't try to read if the read pointer is past the end of file
if (file->currentPosition >= file->filesize || file->startCluster == CLUSTER_FREE) { if (file->currentPosition >= file->filesize || file->startCluster == CLUSTER_FREE) {
r->_errno = EOVERFLOW; r->_errno = EOVERFLOW;
_FAT_unlock(&partition->lock);
return 0; return 0;
} }
@ -367,11 +373,6 @@ ssize_t _FAT_read_r (struct _reent *r, int fd, char *ptr, size_t len) {
len = file->filesize - file->currentPosition; len = file->filesize - file->currentPosition;
} }
// Short circuit cases where len is 0 (or less)
if (len <= 0) {
return 0;
}
remain = len; remain = len;
position = file->rwPosition; position = file->rwPosition;
cache = file->partition->cache; cache = file->partition->cache;