]> git.ipfire.org Git - thirdparty/dhcp.git/commitdiff
Add support for omapi_addr_list_t.
authorTed Lemon <source@isc.org>
Mon, 1 May 2000 23:47:08 +0000 (23:47 +0000)
committerTed Lemon <source@isc.org>
Mon, 1 May 2000 23:47:08 +0000 (23:47 +0000)
omapip/alloc.c

index 40d9b003fb7bea822bf4dc8606a94ab4d56abea4..05f4a196b9209c492e28153c89241a39f39ac37f 100644 (file)
@@ -806,3 +806,80 @@ isc_result_t omapi_value_dereference (omapi_value_t **h,
        return ISC_R_SUCCESS;
 }
 
+isc_result_t omapi_addr_list_new (omapi_addr_list_t **d, unsigned count,
+                                 const char *file, int line)
+{
+       omapi_addr_list_t *new;
+
+       new = dmalloc ((count * sizeof (omapi_addr_t)) +
+                      sizeof (omapi_addr_list_t), file, line);
+       if (!new)
+               return ISC_R_NOMEMORY;
+       memset (new, 0, ((count * sizeof (omapi_addr_t)) +
+                        sizeof (omapi_addr_list_t)));
+       new -> count = count;
+       new -> addresses = (omapi_addr_t *)(new + 1);
+       return omapi_addr_list_reference (d, new, file, line);
+}
+
+isc_result_t omapi_addr_list_reference (omapi_addr_list_t **r,
+                                         omapi_addr_list_t *h,
+                                         const char *file, int line)
+{
+       if (!h || !r)
+               return ISC_R_INVALIDARG;
+
+       if (*r) {
+#if defined (POINTER_DEBUG)
+               log_error ("%s(%d): reference store into non-null pointer!",
+                          file, line);
+               abort ();
+#else
+               return ISC_R_INVALIDARG;
+#endif
+       }
+       *r = h;
+       h -> refcnt++;
+       rc_register (file, line, r, h, h -> refcnt);
+       dmalloc_reuse (h, file, line, 1);
+       return ISC_R_SUCCESS;
+}
+
+isc_result_t omapi_addr_list_dereference (omapi_addr_list_t **h,
+                                           const char *file, int line)
+{
+       if (!h)
+               return ISC_R_INVALIDARG;
+
+       if (!*h) {
+#if defined (POINTER_DEBUG)
+               log_error ("%s(%d): dereference of null pointer!", file, line);
+               abort ();
+#else
+               return ISC_R_INVALIDARG;
+#endif
+       }
+       
+       if ((*h) -> refcnt <= 0) {
+#if defined (POINTER_DEBUG)
+               log_error ("%s(%d): dereference of pointer with zero refcnt!",
+                          file, line);
+#if defined (DEBUG_RC_HISTORY)
+               dump_rc_history ();
+#endif
+               abort ();
+#else
+               *h = 0;
+               return ISC_R_INVALIDARG;
+#endif
+       }
+
+       --((*h) -> refcnt);
+       rc_register (file, line, h, *h, (*h) -> refcnt);
+       if ((*h) -> refcnt <= 0 ) {
+               dfree (*h, file, line);
+       }
+       *h = 0;
+       return ISC_R_SUCCESS;
+}
+