lib: move parse_size_and_unit()

... into its own CU, to build it into an archive.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Julien Grall <jgrall@amazon.com>
Acked-by: Wei Liu <wl@xen.org>
Reviewed-by: Bertrand Marquis <bertrand.marquis@arm.com>
This commit is contained in:
Jan Beulich committed 2020-12-18 13:21:25 +01:00
1 parent 26dfde919c
commit 65fdf25768
3 files changed
+51 -39

No files matched your search

-39
View File
@@ -423,45 +423,6 @@ uint64_t muldiv64(uint64_t a, uint32_t b, uint32_t c)
#endif
}
unsigned long long parse_size_and_unit(const char *s, const char **ps)
{
unsigned long long ret;
const char *s1;
ret = simple_strtoull(s, &s1, 0);
switch ( *s1 )
{
case 'T': case 't':
ret <<= 10;
/* fallthrough */
case 'G': case 'g':
ret <<= 10;
/* fallthrough */
case 'M': case 'm':
ret <<= 10;
/* fallthrough */
case 'K': case 'k':
ret <<= 10;
/* fallthrough */
case 'B': case 'b':
s1++;
break;
case '%':
if ( ps )
break;
/* fallthrough */
default:
ret <<= 10; /* default to kB */
break;
}
if ( ps != NULL )
*ps = s1;
return ret;
}
typedef void (*ctor_func_t)(void);
extern const ctor_func_t __ctors_start[], __ctors_end[];
+1
View File
@@ -2,3 +2,4 @@ obj-$(CONFIG_X86) += x86/
lib-y += ctype.o
lib-y += list-sort.o
lib-y += parse-size.o
+50
View File
@@ -0,0 +1,50 @@
#include <xen/lib.h>
unsigned long long parse_size_and_unit(const char *s, const char **ps)
{
unsigned long long ret;
const char *s1;
ret = simple_strtoull(s, &s1, 0);
switch ( *s1 )
{
case 'T': case 't':
ret <<= 10;
/* fallthrough */
case 'G': case 'g':
ret <<= 10;
/* fallthrough */
case 'M': case 'm':
ret <<= 10;
/* fallthrough */
case 'K': case 'k':
ret <<= 10;
/* fallthrough */
case 'B': case 'b':
s1++;
break;
case '%':
if ( ps )
break;
/* fallthrough */
default:
ret <<= 10; /* default to kB */
break;
}
if ( ps != NULL )
*ps = s1;
return ret;
}
/*
* Local variables:
* mode: C
* c-file-style: "BSD"
* c-basic-offset: 4
* tab-width: 4
* indent-tabs-mode: nil
* End:
*/
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.