ossp-pkg/xds/unregister.c 1.1 -> 1.2
--- unregister.c 2001/07/04 15:58:51 1.1
+++ unregister.c 2001/07/08 15:58:13 1.2
@@ -25,9 +25,45 @@
SUCH DAMAGE.
*/
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
#include "internal.h"
int xds_unregister(xds_t* xds, const char* name)
{
- return XDS_ERR_UNKNOWN_ENGINE;
+ size_t pos;
+
+ /* Sanity checks. */
+
+ assert(xds != NULL);
+ assert(name != NULL);
+ if (xds == NULL || name == NULL)
+ return XDS_ERR_INVALID_ARG;
+
+ /* Find the entry we're supposed to delete. */
+
+ if (!xds_find_engine(xds->engines, xds->engines_len, name, &pos))
+ return XDS_ERR_UNKNOWN_ENGINE;
+
+ /* Free the memory allocated for this entry and move the entries
+ behind it back if necessary. */
+
+ assert(xds->engines[pos].name != NULL);
+ free(xds->engines[pos].name);
+ memmove(&xds->engines[pos], &xds->engines[pos+1], (xds->engines_len - (pos + 1)) * sizeof(engine_map_t));
+ --xds->engines_len;
+
+ /* Lower capacity if necessary. */
+
+ int rc = xds_set_capacity((void**)&xds->engines,
+ &xds->engines_capacity,
+ xds->engines_len,
+ sizeof(engine_map_t),
+ XDS_INITIAL_ENGINES_CAPACITY);
+ assert(rc == XDS_OK || rc == XDS_ERR_NO_MEM);
+ if (rc != XDS_OK)
+ return rc;
+
+ return XDS_OK;
}
|
|