summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeng Fan <van.freenix@gmail.com>2014-07-14 20:58:32 +0800
committerChris Johns <chrisj@rtems.org>2014-07-15 20:14:29 +1000
commit97a3d78f92fa29d18647d8d3f5f0a4f0a21cb393 (patch)
treea5e1b3384577a9978b008a757422b36748ff2a4f
parent5a3239d6e9fdb2f9d62d43cf65ab6706cf69338a (diff)
Fix rap/elf archive file load
When loading an object file in an archive file for the first time, RTL complains that loader can not be found. It is because offset is bigger that cache->file_size the first time when file_size is still -1, while offset is positive because reading the archive file. This patch fixes ths problem. Flush the file_size to 0 but not -1, because file_size is unsigned type.
-rw-r--r--rtl-obj-cache.c19
1 files changed, 11 insertions, 8 deletions
diff --git a/rtl-obj-cache.c b/rtl-obj-cache.c
index e71bbcb..9179b6a 100644
--- a/rtl-obj-cache.c
+++ b/rtl-obj-cache.c
@@ -56,7 +56,7 @@ void
rtems_rtl_obj_cache_flush (rtems_rtl_obj_cache_t* cache)
{
cache->fd = -1;
- cache->file_size = -1;
+ cache->file_size = 0;
cache->level = 0;
}
@@ -75,15 +75,18 @@ rtems_rtl_obj_cache_read (rtems_rtl_obj_cache_t* cache,
return false;
}
- if (offset > cache->file_size)
+ if (cache->fd == fd)
{
- rtems_rtl_set_error (EINVAL, "offset past end of file: offset=%i size=%i",
- (int) offset, (int) cache->file_size);
- return false;
- }
+ if (offset > cache->file_size)
+ {
+ rtems_rtl_set_error (EINVAL, "offset past end of file: offset=%i size=%i",
+ (int) offset, (int) cache->file_size);
+ return false;
+ }
- if ((offset + *length) > cache->file_size)
- *length = cache->file_size - offset;
+ if ((offset + *length) > cache->file_size)
+ *length = cache->file_size - offset;
+ }
while (true)
{