get_next_loaded_module_name() now uses the same (inefficient) mechanism read_next_module_name() is using thanks to Siarzhuk - the previous mechanism was completely unsafe.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21316 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2007-06-03 23:09:59 +00:00
parent 65c61fbf2d
commit 8d1317e1b6
+16 -19
View File
@@ -1245,30 +1245,27 @@ get_next_loaded_module_name(uint32 *_cookie, char *buffer, size_t *_bufferSize)
if (_cookie == NULL || buffer == NULL || _bufferSize == NULL)
return B_BAD_VALUE;
hash_iterator *iterator = (hash_iterator *)*_cookie;
status_t status;
if (iterator == NULL) {
iterator = hash_open(sModulesHash, NULL);
if (iterator == NULL)
return B_NO_MEMORY;
*(hash_iterator **)_cookie = iterator;
}
status_t status = B_ENTRY_NOT_FOUND;
uint32 offset = *_cookie;
recursive_lock_lock(&sModulesLock);
// TODO: this is completely unsafe!!!
struct module *module = (struct module *)hash_next(sModulesHash, iterator);
if (module != NULL) {
*_bufferSize = strlcpy(buffer, module->name, *_bufferSize);
status = B_OK;
} else {
hash_close(sModulesHash, iterator, true);
status = B_ENTRY_NOT_FOUND;
hash_iterator iterator;
hash_open(sModulesHash, &iterator);
struct module *module = (struct module *)hash_next(sModulesHash,
&iterator);
for (uint32 i = 0; module != NULL; i++) {
if (i >= offset) {
*_bufferSize = strlcpy(buffer, module->name, *_bufferSize);
*_cookie = i + 1;
status = B_OK;
break;
}
module = (struct module *)hash_next(sModulesHash, &iterator);
}
hash_close(sModulesHash, &iterator, false);
recursive_lock_unlock(&sModulesLock);
return status;