Browse Source

feat: string load demo

dev
Dnomd343 2 years ago
parent
commit
36142ef5c5
  1. 1
      include/common/sundry.h
  2. 10
      src/cleardns.c
  3. 11
      src/common/sundry.c

1
include/common/sundry.h

@ -4,6 +4,7 @@
#include <stdint.h>
char* show_bool(uint8_t value);
char* string_load(const char *fmt, ...);
char* uint32_to_string(uint32_t number);
char* string_join(const char *base, const char *add);
void string_list_debug(char *describe, char **string_list);

10
src/cleardns.c

@ -115,8 +115,12 @@ void cleardns() { // cleardns service
}
int main(int argc, char *argv[]) {
init(argc, argv);
log_info("ClearDNS server start (%s)", VERSION);
cleardns();
// init(argc, argv);
// log_info("ClearDNS server start (%s)", VERSION);
// cleardns();
char *test = string_load("`%s` -> %d", "test", 2333);
printf("%s\n", test);
return 0;
}

11
src/common/sundry.c

@ -1,8 +1,9 @@
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>
#include <unistd.h>
#include <sys/time.h>
#include "logger.h"
#include "constant.h"
#include "structure.h"
@ -19,6 +20,14 @@ char* string_join(const char *base, const char *add) { // combine string
return strcat(strcpy(ret, base), add);
}
char* string_load(const char *fmt, ...) {
va_list ap;
va_start(ap, fmt);
char *buf = NULL;
vasprintf(&buf, fmt, ap);
return buf;
}
char* uint32_to_string(uint32_t number) { // convert uint32 -> string
char to_str[11]; // MAX_LEN(uint32) -> 4294967296(10-bytes)
sprintf(to_str, "%u", number);

Loading…
Cancel
Save