From: Gary Lin via Grub-devel <grub-devel@gnu.org>
To: The development of GNU GRUB <grub-devel@gnu.org>
Cc: Gary Lin <glin@suse.com>,
Hernan Gatta <hegatta@linux.microsoft.com>,
Daniel Axtens <dja@axtens.net>,
Daniel Kiper <daniel.kiper@oracle.com>,
shkhisti@microsoft.com, jaskaran.khurana@microsoft.com,
christopher.co@microsoft.com, daniel.mihai@microsoft.com,
jaredz@redhat.com, development@efficientek.com,
jejb@linux.ibm.com, mchang@suse.com,
Vladimir Serbinenko <phcoder@gmail.com>
Subject: [PATCH v9 01/22] posix_wrap: tweaks in preparation for libtasn1
Date: Mon, 5 Feb 2024 15:39:34 +0800 [thread overview]
Message-ID: <20240205073955.1171-2-glin@suse.com> (raw)
In-Reply-To: <20240205073955.1171-1-glin@suse.com>
From: Daniel Axtens <dja@axtens.net>
- Define SIZEOF_UNSIGNED_LONG_INT, it's the same as
SIZEOF_UNSIGNED_LONG.
- Define WORD_BIT, the size in bits of an int. This is a defined
in the Single Unix Specification and in gnulib's limits.h. gnulib
assumes it's 32 bits on all our platforms, including 64 bit
platforms, so we also use that value.
- Provide strto[u]l[l] preprocessor macros that resolve to
grub_strto[u]l[l]. To avoid gcrypt redefining strtoul, we
also define HAVE_STRTOUL here.
- Implement c-ctype.h and the functions defined in the header.
- Implement strncat in string.h.
Cc: Vladimir Serbinenko <phcoder@gmail.com>
Signed-off-by: Daniel Axtens <dja@axtens.net>
Signed-off-by: Gary Lin <glin@suse.com>
---
grub-core/lib/posix_wrap/c-ctype.h | 114 +++++++++++++++++++++++++++
grub-core/lib/posix_wrap/limits.h | 1 +
grub-core/lib/posix_wrap/stdlib.h | 8 ++
grub-core/lib/posix_wrap/string.h | 21 +++++
grub-core/lib/posix_wrap/sys/types.h | 1 +
5 files changed, 145 insertions(+)
create mode 100644 grub-core/lib/posix_wrap/c-ctype.h
diff --git a/grub-core/lib/posix_wrap/c-ctype.h b/grub-core/lib/posix_wrap/c-ctype.h
new file mode 100644
index 000000000..5f8fc8ce3
--- /dev/null
+++ b/grub-core/lib/posix_wrap/c-ctype.h
@@ -0,0 +1,114 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2024 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_POSIX_C_CTYPE_H
+#define GRUB_POSIX_C_CTYPE_H 1
+
+#include <grub/misc.h>
+
+static inline bool
+c_isspace (int c)
+{
+ return !!grub_isspace (c);
+}
+
+static inline bool
+c_isdigit (int c)
+{
+ return !!grub_isdigit (c);
+}
+
+static inline bool
+c_islower (int c)
+{
+ return !!grub_islower (c);
+}
+
+static inline bool
+c_isascii (int c)
+{
+ return !(c & ~0x7f);
+}
+
+static inline bool
+c_isupper (int c)
+{
+ return !!grub_isupper (c);
+}
+
+static inline bool
+c_isxdigit (int c)
+{
+ return !!grub_isxdigit (c);
+}
+
+static inline bool
+c_isprint (int c)
+{
+ return !!grub_isprint (c);
+}
+
+static inline bool
+c_iscntrl (int c)
+{
+ return !grub_isprint (c);
+}
+
+static inline bool
+c_isgraph (int c)
+{
+ return grub_isprint (c) && !grub_isspace (c);
+}
+
+static inline bool
+c_isalnum (int c)
+{
+ return grub_isalpha (c) || grub_isdigit (c);
+}
+
+static inline bool
+c_ispunct (int c)
+{
+ return grub_isprint (c) && !grub_isspace (c) && !c_isalnum (c);
+}
+
+static inline bool
+c_isalpha (int c)
+{
+ return !!grub_isalpha (c);
+}
+
+static inline bool
+c_isblank (int c)
+{
+ return c == ' ' || c == '\t';
+}
+
+static inline int
+c_tolower (int c)
+{
+ return grub_tolower (c);
+}
+
+static inline int
+c_toupper (int c)
+{
+ return grub_toupper (c);
+}
+
+#endif
diff --git a/grub-core/lib/posix_wrap/limits.h b/grub-core/lib/posix_wrap/limits.h
index 26918c8a0..4be7b4080 100644
--- a/grub-core/lib/posix_wrap/limits.h
+++ b/grub-core/lib/posix_wrap/limits.h
@@ -41,5 +41,6 @@
#define LONG_MAX GRUB_LONG_MAX
#define CHAR_BIT 8
+#define WORD_BIT 32
#endif
diff --git a/grub-core/lib/posix_wrap/stdlib.h b/grub-core/lib/posix_wrap/stdlib.h
index f5279756a..14e4efdd0 100644
--- a/grub-core/lib/posix_wrap/stdlib.h
+++ b/grub-core/lib/posix_wrap/stdlib.h
@@ -64,4 +64,12 @@ abort (void)
grub_abort ();
}
+#define strtol grub_strtol
+
+/* for libgcrypt */
+#define HAVE_STRTOUL
+#define strtoul grub_strtoul
+
+#define strtoull grub_strtoull
+
#endif
diff --git a/grub-core/lib/posix_wrap/string.h b/grub-core/lib/posix_wrap/string.h
index 1adb450b5..b0c5928d2 100644
--- a/grub-core/lib/posix_wrap/string.h
+++ b/grub-core/lib/posix_wrap/string.h
@@ -84,6 +84,27 @@ memchr (const void *s, int c, grub_size_t n)
return grub_memchr (s, c, n);
}
+static inline char *
+strncat(char *dest, const char *src, grub_size_t n)
+{
+ const char *end;
+ char *str = dest;
+ grub_size_t src_len;
+
+ dest += grub_strlen (dest);
+
+ end = grub_memchr (src, '\0', n);
+ if (end != NULL)
+ src_len = (grub_size_t) (end - src);
+ else
+ src_len = n;
+
+ dest[src_len] = '\0';
+ grub_memcpy (dest, src, src_len);
+
+ return str;
+}
+
#define memcmp grub_memcmp
#define memcpy grub_memcpy
#define memmove grub_memmove
diff --git a/grub-core/lib/posix_wrap/sys/types.h b/grub-core/lib/posix_wrap/sys/types.h
index eeda543c4..2f3e86549 100644
--- a/grub-core/lib/posix_wrap/sys/types.h
+++ b/grub-core/lib/posix_wrap/sys/types.h
@@ -50,6 +50,7 @@ typedef grub_uint8_t byte;
typedef grub_addr_t uintptr_t;
#define SIZEOF_UNSIGNED_LONG GRUB_CPU_SIZEOF_LONG
+#define SIZEOF_UNSIGNED_LONG_INT GRUB_CPU_SIZEOF_LONG
#define SIZEOF_UNSIGNED_INT 4
#define SIZEOF_UNSIGNED_LONG_LONG 8
#define SIZEOF_UNSIGNED_SHORT 2
--
2.35.3
_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel
next prev parent reply other threads:[~2024-02-05 7:40 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-05 7:39 [PATCH v9 00/22] Automatic Disk Unlock with TPM2 Gary Lin via Grub-devel
2024-02-05 7:39 ` Gary Lin via Grub-devel [this message]
2024-02-05 7:39 ` [PATCH v9 02/22] libtasn1: import libtasn1-4.19.0 Gary Lin via Grub-devel
2024-02-05 7:39 ` [PATCH v9 03/22] libtasn1: disable code not needed in grub Gary Lin via Grub-devel
2024-02-05 7:39 ` [PATCH v9 04/22] libtasn1: changes for grub compatibility Gary Lin via Grub-devel
2024-02-05 7:39 ` [PATCH v9 05/22] libtasn1: compile into asn1 module Gary Lin via Grub-devel
2024-02-05 7:39 ` [PATCH v9 06/22] asn1_test: test module for libtasn1 Gary Lin via Grub-devel
2024-02-05 7:39 ` [PATCH v9 07/22] libtasn1: Add the documentation Gary Lin via Grub-devel
2024-02-05 7:39 ` [PATCH v9 08/22] key_protector: Add key protectors framework Gary Lin via Grub-devel
2024-02-05 7:39 ` [PATCH v9 09/22] tpm2: Add TPM Software Stack (TSS) Gary Lin via Grub-devel
2024-02-05 7:39 ` [PATCH v9 10/22] key_protector: Add TPM2 Key Protector Gary Lin via Grub-devel
2024-02-05 7:39 ` [PATCH v9 11/22] cryptodisk: Support key protectors Gary Lin via Grub-devel
2024-02-05 7:39 ` [PATCH v9 12/22] util/grub-protect: Add new tool Gary Lin via Grub-devel
2024-02-05 7:39 ` [PATCH v9 13/22] tpm2: Add TPM2 types, structures, and command constants Gary Lin via Grub-devel
2024-02-05 7:39 ` [PATCH v9 14/22] tpm2: Add more marshal/unmarshal functions Gary Lin via Grub-devel
2024-02-05 7:39 ` [PATCH v9 15/22] tpm2: Implement more TPM2 commands Gary Lin via Grub-devel
2024-02-05 7:39 ` [PATCH v9 16/22] tpm2: Support authorized policy Gary Lin via Grub-devel
2024-02-05 7:39 ` [PATCH v9 17/22] tpm2: Implement NV index Gary Lin via Grub-devel
2024-02-05 7:39 ` [PATCH v9 18/22] cryptodisk: Fallback to passphrase Gary Lin via Grub-devel
2024-02-05 7:39 ` [PATCH v9 19/22] cryptodisk: wipe out the cached keys from protectors Gary Lin via Grub-devel
2024-02-05 7:39 ` [PATCH v9 20/22] diskfilter: look up cryptodisk devices first Gary Lin via Grub-devel
2024-02-05 7:39 ` [PATCH v9 21/22] tpm2: Enable tpm2 module for grub-emu Gary Lin via Grub-devel
2024-02-05 7:39 ` [PATCH v9 22/22] tests: Add tpm2_test Gary Lin via Grub-devel
2024-02-08 19:58 ` [PATCH v9 00/22] Automatic Disk Unlock with TPM2 Daniel Kiper
2024-02-21 8:10 ` Gary Lin via Grub-devel
2024-02-22 15:24 ` Daniel Kiper
2024-03-07 8:59 ` Gary Lin via Grub-devel
2024-04-04 21:03 ` Daniel Kiper
2024-04-08 2:30 ` Gary Lin via Grub-devel
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=20240205073955.1171-2-glin@suse.com \
--to=grub-devel@gnu.org \
--cc=christopher.co@microsoft.com \
--cc=daniel.kiper@oracle.com \
--cc=daniel.mihai@microsoft.com \
--cc=development@efficientek.com \
--cc=dja@axtens.net \
--cc=glin@suse.com \
--cc=hegatta@linux.microsoft.com \
--cc=jaredz@redhat.com \
--cc=jaskaran.khurana@microsoft.com \
--cc=jejb@linux.ibm.com \
--cc=mchang@suse.com \
--cc=phcoder@gmail.com \
--cc=shkhisti@microsoft.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).