forked from enlightenment/efl
windows: Add vasprintf as helper
This commit is contained in:
parent
d40f4e87d9
commit
7b9e078cc7
|
@ -21,7 +21,6 @@
|
|||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
@ -58,6 +57,8 @@
|
|||
|
||||
#include "eina_inline_private.h"
|
||||
|
||||
#include <evil_vasprintf.h>
|
||||
|
||||
/* TODO
|
||||
* + printing logs to stdout or stderr can be implemented
|
||||
* using a queue, useful for multiple threads printing
|
||||
|
|
|
@ -4,13 +4,14 @@
|
|||
|
||||
#define EINA_SLSTR_INTERNAL
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "Eina.h"
|
||||
#include "eina_private.h"
|
||||
|
||||
#include <evil_vasprintf.h>
|
||||
|
||||
// ========================================================================= //
|
||||
|
||||
static int _slstr_init = 0;
|
||||
|
|
|
@ -11,6 +11,8 @@
|
|||
#include "eina_strbuf_common.h"
|
||||
#include "eina_unicode.h"
|
||||
|
||||
#include <evil_vasprintf.h>
|
||||
|
||||
/*============================================================================*
|
||||
* Local *
|
||||
*============================================================================*/
|
||||
|
|
|
@ -41,6 +41,7 @@
|
|||
#include "eina_safety_checks.h"
|
||||
#include "eina_stringshare.h"
|
||||
|
||||
#include <evil_vasprintf.h>
|
||||
|
||||
#ifdef CRI
|
||||
#undef CRI
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif /* HAVE_CONFIG_H */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef _MSC_VER
|
||||
|
||||
inline int
|
||||
vasprintf(char **strp, const char *fmt, va_list ap)
|
||||
{
|
||||
int ret = -1;
|
||||
|
||||
int len = _vscprintf(fmt, ap);
|
||||
if (len != -1)
|
||||
{
|
||||
char *str = (char *)malloc((len + 1) * sizeof(char));
|
||||
if (str != NULL)
|
||||
{
|
||||
ret = vsnprintf(str, (unsigned long) len + 1, fmt, ap);
|
||||
if (ret == len) *strp = str;
|
||||
else free(strp);
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif
|
|
@ -0,0 +1,59 @@
|
|||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "eina_stdio.h"
|
||||
|
||||
int
|
||||
eina_vasprintf_wrap(char **ret, const char *fmt, int nargs, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start(ap, nargs);
|
||||
|
||||
int len = eina_vasprintf(ret, fmt, ap);
|
||||
|
||||
va_end(ap);
|
||||
return len;
|
||||
}
|
||||
|
||||
int
|
||||
simple_test(void)
|
||||
{
|
||||
const char *expected_str =
|
||||
"\tString: Hello World!\n"
|
||||
"\tInteger: 46234\n"
|
||||
"\tDouble: 9.629400E-03\n";
|
||||
|
||||
const char *fmt =
|
||||
"\tString: %s\n"
|
||||
"\tInteger: %d\n"
|
||||
"\tDouble: %E\n";
|
||||
|
||||
char* str;
|
||||
int len = eina_vasprintf_wrap(&str, fmt, 3, "Hello World!", 46234, 0.0096294);
|
||||
|
||||
printf("## Expecting:\n```%s```\n", expected_str);
|
||||
printf("## Returning:\n```%s```\n", str);
|
||||
|
||||
printf("\tResult:");
|
||||
int result = strcmp(str, expected_str);
|
||||
if (!result) printf("........ok!\n");
|
||||
else printf("........nok!\n");
|
||||
|
||||
free(str);
|
||||
return result;
|
||||
}
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
#ifdef GNU
|
||||
printf("Test using vasprintf from GNU:\n");
|
||||
#else
|
||||
printf("Test using implementd eina_vasprintf:\n");
|
||||
#endif
|
||||
|
||||
simple_test();
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
#!/bin/sh
|
||||
|
||||
# clean and update
|
||||
\rm -f vasprintf_test eina_stdio.[hc]
|
||||
\cp ../../lib/eina/eina_stdio.[hc] . &&
|
||||
|
||||
# build
|
||||
clang-cl -o eina_vasprintf_test \
|
||||
-Wno-include-next-absolute-path \
|
||||
eina_vasprintf_test.c \
|
||||
eina_stdio.c &&
|
||||
|
||||
# test
|
||||
./eina_vasprintf_test
|
||||
|
||||
# clean again
|
||||
\rm -f eina_vasprintf_test eina_stdio.[hc]
|
Loading…
Reference in New Issue