mirror of
https://github.com/falk-werner/webfuse
synced 2024-10-27 20:34:10 +00:00
chore: replaced wf_string_create by asprintf
This commit is contained in:
parent
01a9488f6e
commit
60141c4d8a
@ -9,8 +9,6 @@
|
||||
#include "webfuse/adapter/impl/session.h"
|
||||
#include "webfuse/adapter/impl/mountpoint.h"
|
||||
|
||||
#include "webfuse/core/string.h"
|
||||
|
||||
#include <libwebsockets.h>
|
||||
|
||||
#include <sys/stat.h>
|
||||
|
@ -1,32 +0,0 @@
|
||||
#include "webfuse/core/string.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
char * wf_create_string(char const * format, ...)
|
||||
{
|
||||
char * result = NULL;
|
||||
|
||||
va_list measure_args;
|
||||
va_start(measure_args, format);
|
||||
char buffer;
|
||||
int needed = vsnprintf(&buffer, 1, format, measure_args);
|
||||
va_end(measure_args);
|
||||
|
||||
if (0 <= needed)
|
||||
{
|
||||
result = malloc(needed + 1);
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
int count = vsnprintf(result, needed + 1, format, args);
|
||||
va_end(args);
|
||||
|
||||
if ((count < 0) || (needed < count))
|
||||
{
|
||||
free(result);
|
||||
result = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
#ifndef WF_CORE_STRING_H
|
||||
#define WF_CORE_STRING_H
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <stdarg.h>
|
||||
#else
|
||||
#include <cstdarg>
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern char * wf_create_string(char const * format, ...);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
@ -25,7 +25,6 @@ webfuse_core = static_library('webfuse_core',
|
||||
'lib/webfuse/core/message.c',
|
||||
'lib/webfuse/core/message_queue.c',
|
||||
'lib/webfuse/core/status.c',
|
||||
'lib/webfuse/core/string.c',
|
||||
'lib/webfuse/core/base64.c',
|
||||
'lib/webfuse/core/lws_log.c',
|
||||
'lib/webfuse/core/json_util.c',
|
||||
@ -224,7 +223,6 @@ alltests = executable('alltests',
|
||||
'test/webfuse/mocks/mock_adapter_client_callback.cc',
|
||||
'test/webfuse//tests/core/test_util.cc',
|
||||
'test/webfuse/tests/core/test_container_of.cc',
|
||||
'test/webfuse/tests/core/test_string.cc',
|
||||
'test/webfuse/tests/core/test_slist.cc',
|
||||
'test/webfuse/tests/core/test_base64.cc',
|
||||
'test/webfuse/tests/core/test_status.cc',
|
||||
|
@ -1,18 +0,0 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "webfuse/core/string.h"
|
||||
|
||||
TEST(wf_string_create, Default)
|
||||
{
|
||||
char * value = wf_create_string("test %s/%d", "hello", 42);
|
||||
ASSERT_STREQ("test hello/42", value);
|
||||
free(value);
|
||||
}
|
||||
|
||||
TEST(wf_string_create, EmptyString)
|
||||
{
|
||||
char * value = wf_create_string("");
|
||||
ASSERT_STREQ("", value);
|
||||
free(value);
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
#include "webfuse/core/string.h"
|
||||
#include "webfuse/utils/tempdir.hpp"
|
||||
|
||||
#include <unistd.h>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <stdexcept>
|
||||
|
||||
@ -9,8 +9,8 @@ namespace webfuse_test
|
||||
{
|
||||
|
||||
TempDir::TempDir(char const * prefix)
|
||||
: path_(wf_create_string("/tmp/%s_XXXXXX", prefix))
|
||||
{
|
||||
asprintf(&path_, "/tmp/%s_XXXXXX", prefix);
|
||||
char * result = mkdtemp(path_);
|
||||
if (NULL == result)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user