Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d0f1fed2 authored by Jonathan Cameron's avatar Jonathan Cameron Committed by Rusty Russell
Browse files

Add a strtobool function matching semantics of existing in kernel equivalents



This is a rename of the usr_strtobool proposal, which was a renamed,
relocated and fixed version of previous kstrtobool RFC

Signed-off-by: default avatarJonathan Cameron <jic23@cam.ac.uk>
Signed-off-by: default avatarRusty Russell <rusty@rustcorp.com.au>
parent 6845756b
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -123,6 +123,7 @@ extern char **argv_split(gfp_t gfp, const char *str, int *argcp);
extern void argv_free(char **argv);
extern void argv_free(char **argv);


extern bool sysfs_streq(const char *s1, const char *s2);
extern bool sysfs_streq(const char *s1, const char *s2);
extern int strtobool(const char *s, bool *res);


#ifdef CONFIG_BINARY_PRINTF
#ifdef CONFIG_BINARY_PRINTF
int vbin_printf(u32 *bin_buf, size_t size, const char *fmt, va_list args);
int vbin_printf(u32 *bin_buf, size_t size, const char *fmt, va_list args);
+29 −0
Original line number Original line Diff line number Diff line
@@ -535,6 +535,35 @@ bool sysfs_streq(const char *s1, const char *s2)
}
}
EXPORT_SYMBOL(sysfs_streq);
EXPORT_SYMBOL(sysfs_streq);


/**
 * strtobool - convert common user inputs into boolean values
 * @s: input string
 * @res: result
 *
 * This routine returns 0 iff the first character is one of 'Yy1Nn0'.
 * Otherwise it will return -EINVAL.  Value pointed to by res is
 * updated upon finding a match.
 */
int strtobool(const char *s, bool *res)
{
	switch (s[0]) {
	case 'y':
	case 'Y':
	case '1':
		*res = true;
		break;
	case 'n':
	case 'N':
	case '0':
		*res = false;
		break;
	default:
		return -EINVAL;
	}
	return 0;
}
EXPORT_SYMBOL(strtobool);

#ifndef __HAVE_ARCH_MEMSET
#ifndef __HAVE_ARCH_MEMSET
/**
/**
 * memset - Fill a region of memory with the given value
 * memset - Fill a region of memory with the given value