diff mbox

[RFC,06/24] xen: Add new string functions

Message ID 1376687156-6737-7-git-send-email-julien.grall@linaro.org
State Superseded, archived
Headers show

Commit Message

Julien Grall Aug. 16, 2013, 9:05 p.m. UTC
Add kbasename and strcasecmp. The code is copied from Linux.

Signed-off-by: Julien Grall <julien.grall@linaro.org>
---
 xen/common/string.c      |   15 +++++++++++++++
 xen/include/xen/string.h |   14 ++++++++++++++
 2 files changed, 29 insertions(+)

Comments

Jan Beulich Aug. 19, 2013, 9:54 a.m. UTC | #1
>>> Julien Grall <julien.grall@linaro.org> 08/16/13 11:06 PM >>>
>Add kbasename and strcasecmp. The code is copied from Linux.

For the latter I can see its general purpose, but Xen isn't dealing with path names,
so this doesn't look warranted in the common header (and likely not in any header
at all - I'd guess this has just a single source file as consumer).

Jan
Ian Campbell Aug. 19, 2013, 2:57 p.m. UTC | #2
On Mon, 2013-08-19 at 10:54 +0100, Jan Beulich wrote:
> >>> Julien Grall <julien.grall@linaro.org> 08/16/13 11:06 PM >>>
> >Add kbasename and strcasecmp. The code is copied from Linux.
> 
> For the latter I can see its general purpose, but Xen isn't dealing with path names,

I presumed this was something to do with the path like structure of
device tree.

> so this doesn't look warranted in the common header (and likely not in any header
> at all - I'd guess this has just a single source file as consumer).
> 
> Jan
>
Julien Grall Aug. 19, 2013, 3:13 p.m. UTC | #3
On 08/19/2013 03:57 PM, Ian Campbell wrote:
> On Mon, 2013-08-19 at 10:54 +0100, Jan Beulich wrote:
>>>>> Julien Grall <julien.grall@linaro.org> 08/16/13 11:06 PM >>>
>>> Add kbasename and strcasecmp. The code is copied from Linux.
>>
>> For the latter I can see its general purpose, but Xen isn't dealing with path names,
> 
> I presumed this was something to do with the path like structure of
> device tree.

Right. As this function is generic, I though it was better to let in
string.h. I can move this function to the device tree header.

Cheers,
Jan Beulich Aug. 20, 2013, 8:32 a.m. UTC | #4
>>> On 19.08.13 at 17:13, Julien Grall <julien.grall@linaro.org> wrote:
> On 08/19/2013 03:57 PM, Ian Campbell wrote:
>> On Mon, 2013-08-19 at 10:54 +0100, Jan Beulich wrote:
>>>>>> Julien Grall <julien.grall@linaro.org> 08/16/13 11:06 PM >>>
>>>> Add kbasename and strcasecmp. The code is copied from Linux.
>>>
>>> For the latter I can see its general purpose, but Xen isn't dealing with 
> path names,
>> 
>> I presumed this was something to do with the path like structure of
>> device tree.
> 
> Right. As this function is generic, I though it was better to let in
> string.h. I can move this function to the device tree header.

Afaic - yes, please do.

Jan
diff mbox

Patch

diff --git a/xen/common/string.c b/xen/common/string.c
index db9d9d5..9a5a4ba 100644
--- a/xen/common/string.c
+++ b/xen/common/string.c
@@ -41,6 +41,21 @@  int strnicmp(const char *s1, const char *s2, size_t len)
 }
 #endif
 
+#ifndef __HAVE_ARCH_STRCASECMP
+int strcasecmp(const char *s1, const char *s2)
+{
+    int c1, c2;
+
+    do
+    {
+        c1 = tolower(*s1++);
+        c2 = tolower(*s2++);
+    } while ( c1 == c2 && c1 != 0 );
+
+    return c1 - c2;
+}
+#endif
+
 #ifndef __HAVE_ARCH_STRLCPY
 /**
  * strlcpy - Copy a %NUL terminated string into a sized buffer
diff --git a/xen/include/xen/string.h b/xen/include/xen/string.h
index f26b994..9b7511e 100644
--- a/xen/include/xen/string.h
+++ b/xen/include/xen/string.h
@@ -43,6 +43,9 @@  extern int strncmp(const char *,const char *,__kernel_size_t);
 #ifndef __HAVE_ARCH_STRNICMP
 extern int strnicmp(const char *, const char *, __kernel_size_t);
 #endif
+#ifndef __HAVE_ARCH_STRCASECMP
+extern int strcasecmp(const char *, const char *);
+#endif
 #ifndef __HAVE_ARCH_STRCHR
 extern char * strchr(const char *,int);
 #endif
@@ -94,4 +97,15 @@  extern void * memchr(const void *,int,__kernel_size_t);
     (strlcat(d, s, sizeof(d)) >= sizeof(d));    \
 })
 
+/**
+ * kbasename - return the last part of a pathname.
+ *
+ * @path: path to extract the filename from.
+ */
+static inline const char *kbasename(const char *path)
+{
+    const char *tail = strrchr(path, '/');
+    return tail ? tail + 1 : path;
+}
+
 #endif /* _LINUX_STRING_H_ */