tests: file lists [not finished]
This commit is contained in:
+49
-6
@@ -1,13 +1,54 @@
|
||||
#include "../../src/main.h"
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include "utils.h"
|
||||
|
||||
void fill_list_with_samples(fl_t *fl_sample, fl_t **fl_st,
|
||||
fl_t **fl_cur, int amount) {
|
||||
dbuf_t *dbuf_init(size_t init_sz) {
|
||||
dbuf_t *dbuf = malloc(sizeof(dbuf_t));
|
||||
dbuf->ptr = malloc(init_sz);
|
||||
dbuf->len = 0;
|
||||
dbuf->capacity = init_sz;
|
||||
return dbuf;
|
||||
}
|
||||
|
||||
static int it_times = 0;
|
||||
|
||||
int32_t dbuf_write(const char *text, size_t text_len, dbuf_t **__dbuf) {
|
||||
dbuf_t *dbuf = *__dbuf;
|
||||
if (text_len > (dbuf->capacity - dbuf->len)) {
|
||||
if (text_len > (dbuf->capacity * 2 - dbuf->len)) {
|
||||
dbuf->capacity = text_len * 2;
|
||||
} else {
|
||||
dbuf->capacity = dbuf->capacity * 2;
|
||||
}
|
||||
(*__dbuf)->ptr = realloc(dbuf->ptr, dbuf->capacity);
|
||||
dbuf = *__dbuf;
|
||||
}
|
||||
|
||||
it_times++;
|
||||
int _it_times = it_times;
|
||||
strncpy(dbuf->ptr + dbuf->len, text, text_len);
|
||||
dbuf->len += text_len;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t dbuf_destroy(dbuf_t **dbuf) {
|
||||
free((*dbuf)->ptr);
|
||||
free(*dbuf);
|
||||
*dbuf = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void fill_list_with_samples(fl_t *fl_sample, fl_t **fl_st, fl_t **fl_cur,
|
||||
int amount) {
|
||||
fl_t *_fl_st, *_fl_cur;
|
||||
|
||||
if (fl_st == NULL) return;
|
||||
|
||||
if (fl_st == NULL)
|
||||
return;
|
||||
|
||||
for (int i = 0; i < amount; i++) {
|
||||
if (i == 0) {
|
||||
@@ -19,6 +60,8 @@ void fill_list_with_samples(fl_t *fl_sample, fl_t **fl_st,
|
||||
_fl_cur = _fl_cur->next;
|
||||
}
|
||||
|
||||
_fl_cur->next = NULL;
|
||||
|
||||
_fl_cur->name = malloc(sizeof(char) * (strlen(fl_sample->name) + 32));
|
||||
_fl_cur->description =
|
||||
malloc(sizeof(char) * strlen(fl_sample->description) + 1);
|
||||
@@ -31,7 +74,7 @@ void fill_list_with_samples(fl_t *fl_sample, fl_t **fl_st,
|
||||
sizeof(char) * strlen(fl_sample->owner) + 1);
|
||||
}
|
||||
*fl_st = _fl_st;
|
||||
if (fl_cur != NULL) {
|
||||
*fl_cur = _fl_cur;
|
||||
if (fl_cur != NULL) {
|
||||
*fl_cur = _fl_cur;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user