This is an automated email from the ASF dual-hosted git repository.

xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new adf172ab793 include/sys/param.h: Add setbit, clrbit, isset, and isclr.
adf172ab793 is described below

commit adf172ab7937cc6456ec5fea3832e820e409ebbf
Author: Swatantra Yadav <[email protected]>
AuthorDate: Thu Oct 29 17:17:00 2026 +0530

    include/sys/param.h: Add setbit, clrbit, isset, and isclr.
    
    The BSDs (FreeBSD, OpenBSD, NetBSD), glibc, and musl define standard
    bit-string manipulation macros in <sys/param.h>: setbit, clrbit,
    isset, and isclr.  These macros operate on byte arrays using NBBY.
    
    This patch implements these standard convenience macros in
    <sys/param.h> to improve BSD/POSIX compatibility.
    
    Assisted-by: Google Gemini
    Signed-off-by: Swatantra Yadav <[email protected]>
---
 include/sys/param.h | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/include/sys/param.h b/include/sys/param.h
index b3fe4f0050e..9f621000d26 100644
--- a/include/sys/param.h
+++ b/include/sys/param.h
@@ -106,6 +106,24 @@
 #  define powerof2(a)  (!(((a) - 1) & (a)))
 #endif /* powerof2 */
 
+/* Macros for bit-strings. */
+
+#ifndef setbit
+#  define setbit(a, i)       ((a)[(i) / NBBY] |= (1 << ((i) % NBBY)))
+#endif /* setbit */
+
+#ifndef clrbit
+#  define clrbit(a, i)       ((a)[(i) / NBBY] &= ~(1 << ((i) % NBBY)))
+#endif /* clrbit */
+
+#ifndef isset
+#  define isset(a, i)        ((a)[(i) / NBBY] & (1 << ((i) % NBBY)))
+#endif /* isset */
+
+#ifndef isclr
+#  define isclr(a, i)        (((a)[(i) / NBBY] & (1 << ((i) % NBBY))) == 0)
+#endif /* isclr */
+
 /****************************************************************************
  * Public Type Definitions
  ****************************************************************************/

Reply via email to