ulib uprintf to pipe not termdev, ulib Add stringbuffer and linearlist, tb Capture subshell output
This commit is contained in:
26
ulib/string/stringbuffer.c
Normal file
26
ulib/string/stringbuffer.c
Normal file
@ -0,0 +1,26 @@
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <string/stringbuffer.h>
|
||||
#include <umalloc/umalloc.h>
|
||||
#include <string/string.h>
|
||||
#include <linearlist.h>
|
||||
|
||||
void stringbuffer_init(StringBuffer *sb) {
|
||||
string_memset(sb, 0, sizeof(*sb));
|
||||
}
|
||||
|
||||
void stringbuffer_free(StringBuffer *sb) {
|
||||
LINLIST_FREE(sb);
|
||||
}
|
||||
|
||||
void stringbuffer_appendchar(StringBuffer *sb, char c) {
|
||||
LINLIST_APPEND(sb, c);
|
||||
}
|
||||
|
||||
void stringbuffer_appendcstr(StringBuffer *sb, char *cstr) {
|
||||
char *s = cstr;
|
||||
while (*s) {
|
||||
stringbuffer_appendchar(sb, *s);
|
||||
s++;
|
||||
}
|
||||
}
|
15
ulib/string/stringbuffer.h
Normal file
15
ulib/string/stringbuffer.h
Normal file
@ -0,0 +1,15 @@
|
||||
#ifndef ULIB_STRING_STRINGBUFFER_H_
|
||||
#define ULIB_STRING_STRINGBUFFER_H_
|
||||
|
||||
typedef struct {
|
||||
size_t count;
|
||||
size_t capacity;
|
||||
char *data;
|
||||
} StringBuffer;
|
||||
|
||||
void stringbuffer_init(StringBuffer *sb);
|
||||
void stringbuffer_free(StringBuffer *sb);
|
||||
void stringbuffer_appendchar(StringBuffer *sb, char c);
|
||||
void stringbuffer_appendcstr(StringBuffer *sb, char *cstr);
|
||||
|
||||
#endif // ULIB_STRING_STRINGBUFFER_H_
|
Reference in New Issue
Block a user