public inbox for linux-cifs@vger.kernel.org
 help / color / mirror / Atom feed
From: David Disseldorp <ddiss@suse.de>
To: linux-cifs@vger.kernel.org
Cc: Steve French <smfrench@gmail.com>, David Disseldorp <ddiss@suse.de>
Subject: [PATCH 1/3] build_assert: add ccan build_assert.h header
Date: Tue, 31 Mar 2026 11:37:51 +1100	[thread overview]
Message-ID: <20260331012508.17410-2-ddiss@suse.de> (raw)
In-Reply-To: <20260331012508.17410-1-ddiss@suse.de>

Obtained from https://github.com/rustyrussell/ccan with HEAD
050dc66dc2de3d8b150817c6bba648f74b12cccf .
build_assert.h is licensed CC0 (Public domain).

Signed-off-by: David Disseldorp <ddiss@suse.de>
---
 build_assert.h | 40 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)
 create mode 100644 build_assert.h

diff --git a/build_assert.h b/build_assert.h
new file mode 100644
index 0000000..b9ecd84
--- /dev/null
+++ b/build_assert.h
@@ -0,0 +1,40 @@
+/* CC0 (Public domain) - see LICENSE file for details */
+#ifndef CCAN_BUILD_ASSERT_H
+#define CCAN_BUILD_ASSERT_H
+
+/**
+ * BUILD_ASSERT - assert a build-time dependency.
+ * @cond: the compile-time condition which must be true.
+ *
+ * Your compile will fail if the condition isn't true, or can't be evaluated
+ * by the compiler.  This can only be used within a function.
+ *
+ * Example:
+ *	#include <stddef.h>
+ *	...
+ *	static char *foo_to_char(struct foo *foo)
+ *	{
+ *		// This code needs string to be at start of foo.
+ *		BUILD_ASSERT(offsetof(struct foo, string) == 0);
+ *		return (char *)foo;
+ *	}
+ */
+#define BUILD_ASSERT(cond) \
+	do { (void) sizeof(char [1 - 2*!(cond)]); } while(0)
+
+/**
+ * BUILD_ASSERT_OR_ZERO - assert a build-time dependency, as an expression.
+ * @cond: the compile-time condition which must be true.
+ *
+ * Your compile will fail if the condition isn't true, or can't be evaluated
+ * by the compiler.  This can be used in an expression: its value is "0".
+ *
+ * Example:
+ *	#define foo_to_char(foo)					\
+ *		 ((char *)(foo)						\
+ *		  + BUILD_ASSERT_OR_ZERO(offsetof(struct foo, string) == 0))
+ */
+#define BUILD_ASSERT_OR_ZERO(cond) \
+	(sizeof(char [1 - 2*!(cond)]) - 1)
+
+#endif /* CCAN_BUILD_ASSERT_H */
-- 
2.51.0


  reply	other threads:[~2026-03-31  1:25 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-31  0:37 [PATCH 0/3] mount.cifs: minor buflen tracking cleanups David Disseldorp
2026-03-31  0:37 ` David Disseldorp [this message]
2026-03-31  0:37 ` [PATCH 2/3] mount.cifs: adjust get_password_from_file() buf size David Disseldorp
2026-03-31  0:37 ` [PATCH 3/3] mount.cifs: remove runtime pass_length calculation David Disseldorp
2026-03-31 18:06 ` [PATCH 0/3] mount.cifs: minor buflen tracking cleanups Henrique Carvalho
2026-04-01  2:14   ` Steve French

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260331012508.17410-2-ddiss@suse.de \
    --to=ddiss@suse.de \
    --cc=linux-cifs@vger.kernel.org \
    --cc=smfrench@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox