]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
2009-11-20 Colin D Bennett <colin@gibibit.com>
authorColin D Bennett <colin@gibibit.com>
Fri, 20 Nov 2009 14:09:48 +0000 (15:09 +0100)
committerVladimir 'phcoder' Serbinenko <phcoder@gmail.com>
Fri, 20 Nov 2009 14:09:48 +0000 (15:09 +0100)
* include/grub/misc.h (grub_iscntrl): New inline function.
(grub_isalnum): Likewise.
(grub_strtol): Likewise.

ChangeLog.gfxmenumisc [new file with mode: 0644]
include/grub/misc.h

diff --git a/ChangeLog.gfxmenumisc b/ChangeLog.gfxmenumisc
new file mode 100644 (file)
index 0000000..ace9862
--- /dev/null
@@ -0,0 +1,6 @@
+2009-11-20  Colin D Bennett  <colin@gibibit.com>
+
+       * include/grub/misc.h (grub_iscntrl): New inline function.
+       (grub_isalnum): Likewise.
+       (grub_strtol): Likewise.
+
index faa2d5c42ad9c1d3c7cb57979dd347793df969f7..b843b9202749572b361fef8a143fe52808ce49c3 100644 (file)
@@ -94,6 +94,12 @@ char *EXPORT_FUNC(grub_strstr) (const char *haystack, const char *needle);
 int EXPORT_FUNC(grub_isspace) (int c);
 int EXPORT_FUNC(grub_isprint) (int c);
 
+static inline int
+grub_iscntrl (int c)
+{
+  return (c >= 0x00 && c <= 0x1F) || c == 0x7F;
+}
+
 static inline int
 grub_isalpha (int c)
 {
@@ -112,6 +118,12 @@ grub_isdigit (int c)
   return (c >= '0' && c <= '9');
 }
 
+static inline int
+grub_isalnum (int c)
+{
+  return grub_isalpha (c) || grub_isdigit (c);
+}
+
 static inline int
 grub_tolower (int c)
 {
@@ -166,6 +178,43 @@ grub_strncasecmp (const char *s1, const char *s2, grub_size_t n)
 
 unsigned long EXPORT_FUNC(grub_strtoul) (const char *str, char **end, int base);
 unsigned long long EXPORT_FUNC(grub_strtoull) (const char *str, char **end, int base);
+
+static inline long
+grub_strtol (const char *str, char **end, int base)
+{
+  int negative = 0;
+  unsigned long magnitude;
+
+  while (*str && grub_isspace (*str))
+    str++;
+
+  if (*str == '-')
+    {
+      negative = 1;
+      str++;
+    }
+
+  magnitude = grub_strtoull (str, end, base);
+  if (negative)
+    {
+      if (magnitude > (unsigned long) GRUB_LONG_MAX + 1)
+        {
+          grub_error (GRUB_ERR_OUT_OF_RANGE, "negative overflow");
+          return GRUB_LONG_MIN;
+        }
+      return -((long) magnitude);
+    }
+  else
+    {
+      if (magnitude > GRUB_LONG_MAX)
+        {
+          grub_error (GRUB_ERR_OUT_OF_RANGE, "positive overflow");
+          return GRUB_LONG_MAX;
+        }
+      return (long) magnitude;
+    }
+}
+
 char *EXPORT_FUNC(grub_strdup) (const char *s);
 char *EXPORT_FUNC(grub_strndup) (const char *s, grub_size_t n);
 void *EXPORT_FUNC(grub_memset) (void *s, int c, grub_size_t n);