server 0.0.1
basicserverinfrastructure

src/interface.c

Go to the documentation of this file.
00001 #include <sys/types.h>
00002 #include <stdlib.h>
00003 
00004 #include "interface.h"
00005 
00006 #ifndef TRUE
00007 #define TRUE    1
00008 #endif // TRUE
00009 
00010 static
00011 inline
00012 int
00013 comp(const void * _a, const void * _b)
00014 {
00015         const struct interface * a = **(const struct interface ***)_a;
00016         const struct interface * b = **(const struct interface ***)_b;
00017     return ((a)<(b))? -1 : ((a)>(b))? 1 : 0;
00018 }
00019 
00024 struct interface *
00025 interfaceGet(iface_impl_ptr iface_impl, const iface_ptr _iface)
00026 {
00027         const iface_ptr * iface = &_iface;
00028         void *            dummy;
00029 
00030     if (! iface_impl->simpl) {
00031         qsort((void**)(iface_impl->impl), iface_impl->nimpl, sizeof(iface_ptr), comp);
00032         iface_impl->simpl=TRUE;
00033     }
00034 
00035     dummy = bsearch(
00036                         &iface,
00037                         iface_impl->impl,
00038                         iface_impl->nimpl,
00039                         sizeof(iface_ptr),
00040                         comp);
00041 
00042         return dummy? *(struct interface **)dummy : dummy;
00043 }
00044 
00045 // vim: set ts=4 sw=4:
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines