All the mail mirrored from lore.kernel.org
 help / color / mirror / Atom feed
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, patrick.colp@oracle.com,
	Stefan Berger <stefanb@linux.ibm.com>,
	Vladimir Serbinenko <phcoder@gmail.com>
Subject: [PATCH v13 01/20] posix_wrap: tweaks in preparation for libtasn1
Date: Thu, 25 Apr 2024 16:01:47 +0800	[thread overview]
Message-ID: <20240425080206.23902-2-glin@suse.com> (raw)
In-Reply-To: <20240425080206.23902-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

  reply	other threads:[~2024-04-25  8:03 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-25  8:01 [PATCH v13 00/20] Automatic Disk Unlock with TPM2 Gary Lin via Grub-devel
2024-04-25  8:01 ` Gary Lin via Grub-devel [this message]
2024-04-25  8:01 ` [PATCH v13 02/20] libtasn1: import libtasn1-4.19.0 Gary Lin via Grub-devel
2024-04-25  8:01 ` [PATCH v13 03/20] libtasn1: disable code not needed in grub Gary Lin via Grub-devel
2024-04-25  8:01 ` [PATCH v13 04/20] libtasn1: changes for grub compatibility Gary Lin via Grub-devel
2024-04-30 13:14   ` Stefan Berger
2024-04-25  8:01 ` [PATCH v13 05/20] libtasn1: fix the potential buffer overrun Gary Lin via Grub-devel
2024-04-25  8:01 ` [PATCH v13 06/20] libtasn1: compile into asn1 module Gary Lin via Grub-devel
2024-04-25  8:01 ` [PATCH v13 07/20] asn1_test: test module for libtasn1 Gary Lin via Grub-devel
2024-04-25  8:01 ` [PATCH v13 08/20] libtasn1: Add the documentation Gary Lin via Grub-devel
2024-04-27  8:27   ` Glenn Washburn
2024-04-29  6:21     ` Gary Lin via Grub-devel
2024-04-25  8:01 ` [PATCH v13 09/20] key_protector: Add key protectors framework Gary Lin via Grub-devel
2024-04-25  8:01 ` [PATCH v13 10/20] tpm2: Add TPM Software Stack (TSS) Gary Lin via Grub-devel
2024-04-25  8:01 ` [PATCH v13 11/20] key_protector: Add TPM2 Key Protector Gary Lin via Grub-devel
2024-04-25  8:01 ` [PATCH v13 12/20] cryptodisk: Support key protectors Gary Lin via Grub-devel
2024-04-25  8:01 ` [PATCH v13 13/20] util/grub-protect: Add new tool Gary Lin via Grub-devel
2024-04-25  8:02 ` [PATCH v13 14/20] tpm2: Support authorized policy Gary Lin via Grub-devel
2024-04-25  8:02 ` [PATCH v13 15/20] tpm2: Implement NV index Gary Lin via Grub-devel
2024-04-25  8:02 ` [PATCH v13 16/20] cryptodisk: Fallback to passphrase Gary Lin via Grub-devel
2024-04-25  8:02 ` [PATCH v13 17/20] cryptodisk: wipe out the cached keys from protectors Gary Lin via Grub-devel
2024-04-25  8:02 ` [PATCH v13 18/20] diskfilter: look up cryptodisk devices first Gary Lin via Grub-devel
2024-04-25  8:02 ` [PATCH v13 19/20] tpm2: Enable tpm2 module for grub-emu Gary Lin via Grub-devel
2024-04-25  8:02 ` [PATCH v13 20/20] tests: Add tpm2_test Gary Lin via Grub-devel
2024-04-26 22:18   ` Glenn Washburn
2024-04-29  8:10     ` Gary Lin via Grub-devel
2024-04-30  8:09       ` 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=20240425080206.23902-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=patrick.colp@oracle.com \
    --cc=phcoder@gmail.com \
    --cc=shkhisti@microsoft.com \
    --cc=stefanb@linux.ibm.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.