Subversion Repositories Kolibri OS

Rev

Rev 5056 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5056 Rev 6936
Line 11... Line 11...
11
#include 
11
#include 
Line 12... Line 12...
12
 
12
 
13
/* Simplified asprintf. */
13
/* Simplified asprintf. */
14
char *kvasprintf(gfp_t gfp, const char *fmt, va_list ap)
14
char *kvasprintf(gfp_t gfp, const char *fmt, va_list ap)
15
{
15
{
16
	unsigned int len;
16
	unsigned int first, second;
17
	char *p;
17
	char *p;
Line 18... Line 18...
18
	va_list aq;
18
	va_list aq;
19
 
19
 
20
	va_copy(aq, ap);
20
	va_copy(aq, ap);
Line 21... Line 21...
21
	len = vsnprintf(NULL, 0, fmt, aq);
21
	first = vsnprintf(NULL, 0, fmt, aq);
22
	va_end(aq);
22
	va_end(aq);
23
 
23
 
Line 24... Line 24...
24
    p = kmalloc(len+1, gfp);
24
    p = kmalloc(first+1, gfp);
-
 
25
	if (!p)
-
 
26
		return NULL;
Line 25... Line 27...
25
	if (!p)
27
 
26
		return NULL;
28
	second = vsnprintf(p, first+1, fmt, ap);
27
 
29
	WARN(first != second, "different return values (%u and %u) from vsnprintf(\"%s\", ...)",
Line -... Line 30...
-
 
30
	     first, second, fmt);
-
 
31
 
-
 
32
	return p;
-
 
33
}
-
 
34
EXPORT_SYMBOL(kvasprintf);
-
 
35
 
-
 
36
/*
-
 
37
 * If fmt contains no % (or is exactly %s), use kstrdup_const. If fmt
-
 
38
 * (or the sole vararg) points to rodata, we will then save a memory
-
 
39
 * allocation and string copy. In any case, the return value should be
-
 
40
 * freed using kfree_const().
-
 
41
 */
-
 
42
const char *kvasprintf_const(gfp_t gfp, const char *fmt, va_list ap)
-
 
43
{
-
 
44
	if (!strchr(fmt, '%'))
-
 
45
        return strdup(fmt);
28
	vsnprintf(p, len+1, fmt, ap);
46
	if (!strcmp(fmt, "%s"))
29
 
47
        return strdup(va_arg(ap, const char*));
30
	return p;
48
	return kvasprintf(gfp, fmt, ap);
31
}
49
}