diff options
author | Mohammed Khoory <mkhoory@eiast.ae> | 2013-11-04 10:49:44 +0900 |
---|---|---|
committer | Chris Johns <chrisj@rtems.org> | 2014-09-01 09:32:37 +1000 |
commit | d7aca117e2aaa7dca6db40f182f64fd66644a198 (patch) | |
tree | 2328ea34464afe9141c1d26d33050efab537c681 | |
parent | 0b81accba708e028d3e9828522907ca4fda77125 (diff) |
Fixed comparison of ELF object names
-rw-r--r-- | rtl-obj.c | 38 | ||||
-rw-r--r-- | rtl-obj.h | 16 | ||||
-rw-r--r-- | rtl.c | 7 |
3 files changed, 46 insertions, 15 deletions
@@ -115,11 +115,14 @@ rtems_rtl_obj_unresolved (rtems_rtl_obj_t* obj) return (obj->flags & RTEMS_RTL_OBJ_UNRESOLVED) != 0 ? true : false; } -static bool -rtems_rtl_obj_parse_name (rtems_rtl_obj_t* obj, const char* name) +bool +rtems_rtl_parse_name (const char* name, + const char** aname, + const char** oname, + int* ooffset) { - const char* aname = NULL; - const char* oname = NULL; + const char* laname = NULL; + const char* loname = NULL; const char* colon; const char* end; @@ -133,14 +136,14 @@ rtems_rtl_obj_parse_name (rtems_rtl_obj_t* obj, const char* name) if (colon == NULL || colon < strrchr(name, '/')) colon = end; - oname = rtems_rtl_alloc_new (RTEMS_RTL_ALLOC_OBJECT, colon - name + 1, true); + loname = rtems_rtl_alloc_new (RTEMS_RTL_ALLOC_OBJECT, colon - name + 1, true); if (!oname) { rtems_rtl_set_error (ENOMEM, "no memory for object file name"); return false; } - memcpy ((void*) oname, name, colon - name); + memcpy ((void*) loname, name, colon - name); /* * If the pointers match there is no ':' delimiter. @@ -153,7 +156,7 @@ rtems_rtl_obj_parse_name (rtems_rtl_obj_t* obj, const char* name) * The file name is an archive and the object file name is next after the * delimiter. Move the pointer to the archive name. */ - aname = oname; + laname = loname; ++colon; /* @@ -166,15 +169,15 @@ rtems_rtl_obj_parse_name (rtems_rtl_obj_t* obj, const char* name) at = end; - oname = rtems_rtl_alloc_new (RTEMS_RTL_ALLOC_OBJECT, at - colon + 1, true); - if (!oname) + loname = rtems_rtl_alloc_new (RTEMS_RTL_ALLOC_OBJECT, at - colon + 1, true); + if (!loname) { - rtems_rtl_alloc_del (RTEMS_RTL_ALLOC_OBJECT, (void*) aname); + rtems_rtl_alloc_del (RTEMS_RTL_ALLOC_OBJECT, (void*) laname); rtems_rtl_set_error (ENOMEM, "no memory for object file name"); return false; } - memcpy ((void*) oname, colon, at - colon); + memcpy ((void*) loname, colon, at - colon); if (at != end) { @@ -183,17 +186,22 @@ rtems_rtl_obj_parse_name (rtems_rtl_obj_t* obj, const char* name) * does not parse 0 will be returned and the archive will be * searched. */ - obj->ooffset = strtoul (at + 1, 0, 0); + *ooffset = strtoul (at + 1, 0, 0); } } - obj->oname = oname; - obj->aname = aname; - + *oname = loname; + *aname = laname; return true; } static bool +rtems_rtl_obj_parse_name (rtems_rtl_obj_t* obj, const char* name) +{ + return rtems_rtl_parse_name (name, &(obj->aname), &(obj->oname), &(obj->ooffset)); +} + +static bool rtems_rtl_seek_read (int fd, off_t off, size_t len, uint8_t* buffer) { if (lseek (fd, off, SEEK_SET) < 0) @@ -281,6 +281,22 @@ bool rtems_rtl_obj_free (rtems_rtl_obj_t* obj); bool rtems_rtl_obj_unresolved (rtems_rtl_obj_t* obj); /** + * Parses a filename and returns newly allocated strings with the archive name, + * object name, and the object's offset + * + * @param name The filename of the object + * @param aname Address of a string pointer that holds the archive name + * @param oname Address of a string pointer that holds the object name + * @param ooffset Address of an int that holds the object offset + * @retval true The parsing was successful + * @retval false The parsing was unsuccessful + */ +bool rtems_rtl_parse_name (const char* name, + const char** aname, + const char** oname, + int* ooffset); + +/** * Load the object file. * * @param obj The object file's descriptor. @@ -375,6 +375,13 @@ rtems_rtl_obj_t* rtems_rtl_find_obj (const char* name) { rtems_chain_node* node; + rtems_rtl_obj_t* found = NULL; + const char* aname = NULL; + const char* oname = NULL; + int ooffset; + + if (!rtems_rtl_parse_name (name, &aname, &oname, &ooffset)) + return NULL; node = rtems_chain_first (&rtl->objects); |