lib/util: add spdk_strlwr()

Add function to convert string to lowercase in place.

Originally based on code imported from istgt.

Change-Id: Ica9fe2208e6ee09b22c9a652a33c5affe5be23cc
Signed-off-by: Daniel Verkamp <daniel.verkamp@intel.com>
This commit is contained in:
Daniel Verkamp 2016-04-28 16:30:56 -07:00
parent 87d3dd870a
commit c5611b26b3
2 changed files with 27 additions and 0 deletions

View File

@ -47,6 +47,13 @@ extern "C" {
*/
char *spdk_sprintf_alloc(const char *format, ...) __attribute__((format(printf, 1, 2)));
/**
* Convert string to lowercase in place.
*
* \param s String to convert to lowercase.
*/
char *spdk_strlwr(char *s);
#ifdef __cplusplus
}
#endif

View File

@ -1,6 +1,7 @@
/*-
* BSD LICENSE
*
* Copyright (C) 2008-2012 Daisuke Aoyama <aoyama@peach.ne.jp>.
* Copyright (c) Intel Corporation.
* All rights reserved.
*
@ -34,6 +35,7 @@
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include "spdk/string.h"
@ -80,3 +82,21 @@ spdk_sprintf_alloc(const char *format, ...)
return NULL;
}
char *
spdk_strlwr(char *s)
{
char *p;
if (s == NULL) {
return NULL;
}
p = s;
while (*p != '\0') {
*p = tolower(*p);
p++;
}
return s;
}