Exetools

Exetools (https://forum.exetools.com/index.php)
-   General Discussion (https://forum.exetools.com/forumdisplay.php?f=2)
-   -   porting GNU tdestroy() function to SPARC Solaris (https://forum.exetools.com/showthread.php?t=6289)

WhoCares 01-07-2005 10:31

porting GNU tdestroy() function to SPARC Solaris
 
The GNU tdestroy() function only exists in Linux. Currently I have to port it to SPARC Solaris 9. It seems that tdestroy() can't be implemented with tsearch/tfind/tdelete/twalk combinations. I will be shocked if this is true because it will be ridiculous for the API function designers if there is no way to free all the resources of a tree in Solaris OS. Do I have to re-write the whole bunch of tree manipulation functions from scratch? :(
http://www.planetpenguin.de/manpage-3-tdestroy.3.html

SiNTAX 01-07-2005 16:43

I don't know anything about slowaris, but you could look in the glibc sources (but don't forget, this is GPL code)
ie.. glibc-2.3.2/misc/tsearch.c :
Code:

/* The standardized functions miss an important functionality: the
tree cannot be removed easily.  We provide a function to do this.  */
static void
internal_function
tdestroy_recurse (node root, __free_fn_t freefct)
{
if (root->left != NULL)
tdestroy_recurse (root->left, freefct);
if (root->right != NULL)
tdestroy_recurse (root->right, freefct);
(*freefct) ((void *) root->key);
/* Free the node itself.  */
free (root);
}
void
__tdestroy (void *vroot, __free_fn_t freefct)
{
node root = (node) vroot;
CHECK_TREE (root);
if (root != NULL)
tdestroy_recurse (root, freefct);
}
weak_alias (__tdestroy, tdestroy)


WhoCares 01-07-2005 18:41

Thanks. That's the quick solution.

SiNTAX 01-07-2005 23:53

Well.. if rather fancy a challenge, you could always do this:
Code:

objdump -d /lib/tls/libc.so.6 |sed -n -e '/<tdestroy>:/,/^$/ p'
:D


All times are GMT +8. The time now is 19:06.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2026, vBulletin Solutions, Inc.
Always Your Best Friend: Aaron, JMI, ahmadmansoor, ZeNiX