grub-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 4/4] misc: Change grub_strword to return a string like grub_strst


From: Glenn Washburn
Subject: [PATCH 4/4] misc: Change grub_strword to return a string like grub_strstr
Date: Fri, 19 Mar 2021 22:06:49 -0500

This makes grub_strword more versatile. All code as of this change using
grub_strword uses it in a conditional or boolean operator context where its
return value would be silently converted to a 1 or 0, so this does not
affect current usage. A few lines in loader/xnu.c have been changed to
enhance clarity there.

Signed-off-by: Glenn Washburn <development@efficientek.com>
---
 grub-core/kern/misc.c  | 6 +++---
 grub-core/loader/xnu.c | 7 ++++---
 include/grub/misc.h    | 2 +-
 3 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/grub-core/kern/misc.c b/grub-core/kern/misc.c
index 73563b59b..31f169291 100644
--- a/grub-core/kern/misc.c
+++ b/grub-core/kern/misc.c
@@ -320,7 +320,7 @@ grub_strrchr (const char *s, int c)
   return p;
 }
 
-int
+char *
 grub_strword (const char *haystack, const char *needle)
 {
   const char *n_pos = needle;
@@ -343,7 +343,7 @@ grub_strword (const char *haystack, const char *needle)
       next word (or the end of string) and "reset" the needle.  */
       if ( (!*haystack || grub_iswordseparator (*haystack))
          && (!*n_pos || grub_iswordseparator (*n_pos)))
-        return 1;
+        return (char *)(haystack - (n_pos - needle));
       else
         {
           n_pos = needle;
@@ -354,7 +354,7 @@ grub_strword (const char *haystack, const char *needle)
         }
     }
 
-  return 0;
+  return NULL;
 }
 
 int
diff --git a/grub-core/loader/xnu.c b/grub-core/loader/xnu.c
index 1c0cf6a43..ce35600d9 100644
--- a/grub-core/loader/xnu.c
+++ b/grub-core/loader/xnu.c
@@ -975,7 +975,8 @@ grub_xnu_check_os_bundle_required (char *plistname,
 
   /* Set the return value for the case when no OSBundleRequired tag is found. 
*/
   if (osbundlereq)
-    ret = grub_strword (osbundlereq, "all") || grub_strword (osbundlereq, "-");
+    ret = grub_strword (osbundlereq, "all") != 0
+      || grub_strword (osbundlereq, "-") != 0;
   else
     ret = 1;
 
@@ -996,8 +997,8 @@ grub_xnu_check_os_bundle_required (char *plistname,
          {
            for (ptr2 = stringptr; *ptr2; ptr2++)
              *ptr2 = grub_tolower (*ptr2);
-           ret = grub_strword (osbundlereq, stringptr)
-             || grub_strword (osbundlereq, "all");
+           ret = grub_strword (osbundlereq, stringptr) != 0
+             || grub_strword (osbundlereq, "all") != 0;
          }
        if (stringptr && binnamekeyfound && binname && depth == 4)
          {
diff --git a/include/grub/misc.h b/include/grub/misc.h
index 7d2b55196..c2cbc8f5d 100644
--- a/include/grub/misc.h
+++ b/include/grub/misc.h
@@ -85,7 +85,7 @@ int EXPORT_FUNC(grub_strncmp) (const char *s1, const char 
*s2, grub_size_t n);
 
 char *EXPORT_FUNC(grub_strchr) (const char *s, int c);
 char *EXPORT_FUNC(grub_strrchr) (const char *s, int c);
-int EXPORT_FUNC(grub_strword) (const char *s, const char *w);
+char *EXPORT_FUNC(grub_strword) (const char *s, const char *w);
 
 /* Copied from gnulib.
    Written by Bruno Haible <bruno@clisp.org>, 2005. */
-- 
2.27.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]