Commit c5611b26 authored by Daniel Verkamp's avatar Daniel Verkamp
Browse files

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: default avatarDaniel Verkamp <daniel.verkamp@intel.com>
parent 87d3dd87
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -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
+20 −0
Original line number Diff line number Diff line
/*-
 *   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;
}