Fix function

FossilOrigin-Name: a8910644e6f7612e6793e8be844926f6d87659b2f9b2ac44543b0f5c0851837f
This commit is contained in:
nekobit 2023-03-03 18:30:07 +00:00
parent d979621621
commit 7606545a27
3 changed files with 28 additions and 20 deletions

View file

@ -4,11 +4,18 @@ set(MASTODONT_VERSION 0.1)
# Get parent directory of this config file
find_package(CURL REQUIRED)
find_package(PkgConfig REQUIRED)
# TODO account for built-in cjson lib
pkg_check_modules(MSTDNT_CJSON libcjson)
set(MASTODONT_INCLUDE_DIRS
"${CMAKE_CURRENT_LIST_DIR}/../include"
"${CMAKE_CURRENT_LIST_DIR}/../libs"
../include
../libs
)
set(MASTODONT_LIBRARIES ${CMAKE_CURRENT_LIST_DIR})
set(MASTODONT_LIBRARIES
mastodont
${MSTDNT_CJSON_LIBRARIES}
${CURL_LIBRARIES}
)

View file

@ -1,6 +1,10 @@
include(../cmake/mastodont-config.cmake)
add_executable(get_feed get_feed.c)
target_compile_options(get_feed PUBLIC -std=c99 -Wall)
target_link_libraries(get_feed PUBLIC
${MASTODONT_LIBRARIES}
)
target_include_directories(get_feed PUBLIC
../include
${CURL_INCLUDE_DIRS}
../libs)
${MASTODONT_INCLUDE_DIRS}
)

View file

@ -1,11 +1,12 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <mastodont.h>
char* get_line(char const* prompt, size_t* res_size)
char* get_line(char const* prompt)
{
char* result = NULL;
#define GL_BUF_SIZE 25
size_t _res_size;
#define GL_BUF_SIZE 255
char buffer[GL_BUF_SIZE];
if (prompt)
@ -14,21 +15,15 @@ char* get_line(char const* prompt, size_t* res_size)
fputs(": ", stdout);
}
while (fgets(buffer, GL_BUF_SIZE, stdin) != NULL)
{
_res_size += GL_BUF_SIZE;
result = realloc(result, _res_size);
memcpy(result, buffer, GL_BUF_SIZE);
}
fgets(buffer, GL_BUF_SIZE, stdin);
result = realloc(result, strlen(buffer)+1);
strcpy(result, buffer);
if (res_size)
*res_size = _res_size;
return result;
}
int
main()
main(int argc, char** argv)
{
mstdnt_global_curl_init();
@ -39,7 +34,7 @@ main()
fputs("Couldn't initialize Mastodont-c!", stderr);
}
char* instance = get_line("Instance: ", NULL);
char* instance = get_line("Instance");
puts(instance);
@ -47,4 +42,6 @@ main()
mstdnt_cleanup(&data);
mstdnt_global_curl_cleanup();
return 1;
}