]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
Add os_remove_in_array()
authorEmanuel Taube <emanuel.taube@gmail.com>
Tue, 25 Feb 2014 09:59:44 +0000 (10:59 +0100)
committerJouni Malinen <j@w1.fi>
Tue, 25 Feb 2014 14:10:29 +0000 (16:10 +0200)
This can be used to remove members from an array.

Signed-off-by: Emanuel Taube <emanuel.taube@gmail.com>
src/utils/os.h

index 2e2350a783a68db49fe4f87755317ea5a92d14d4..d63ac294b2bc9cec6b8ddefcd59dd234a0261a9e 100644 (file)
@@ -549,6 +549,21 @@ static inline void * os_realloc_array(void *ptr, size_t nmemb, size_t size)
        return os_realloc(ptr, nmemb * size);
 }
 
+/**
+ * os_remove_in_array - Remove a member from an array by index
+ * @ptr: Pointer to the array
+ * @nmemb: Current member count of the array
+ * @size: The size per member of the array
+ * @idx: Index of the member to be removed
+ */
+static inline void os_remove_in_array(void *ptr, size_t nmemb, size_t size,
+                                     size_t idx)
+{
+       if (idx < nmemb - 1)
+               os_memmove(((unsigned char *) ptr) + idx * size,
+                          ((unsigned char *) ptr) + (idx + 1) * size,
+                          (nmemb - idx - 1) * size);
+}
 
 /**
  * os_strlcpy - Copy a string with size bound and NUL-termination