Function movements

* string functions mstr*() are moved to string_utils.c
* allocation wrappers are moved to utils.h
* printf_* functions are moved to log.h

Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
This commit is contained in:
Yuxuan Shui
2018-12-15 17:42:37 +00:00
parent c2c16fb8a1
commit 0cebbc370a
15 changed files with 174 additions and 147 deletions

37
src/string_utils.h Normal file
View File

@@ -0,0 +1,37 @@
// SPDX-License-Identifier: MPL-2.0
// Copyright (c) Yuxuan Shui <yshuiv7@gmail.com>
#pragma once
#include <ctype.h>
#include <stddef.h>
#define mstrncmp(s1, s2) strncmp((s1), (s2), strlen(s1))
char *mstrcpy(const char *src);
char *mstrncpy(const char *src, unsigned len);
char *mstrjoin(const char *src1, const char *src2);
char *
mstrjoin3(const char *src1, const char *src2, const char *src3);
void mstrextend(char **psrc1, const char *src2);
static inline const char *
skip_space_const(const char *src) {
if (!src)
return NULL;
while (*src && isspace(*src))
src++;
return src;
}
static inline char *
skip_space_mut(char *src) {
if (!src)
return NULL;
while (*src && isspace(*src))
src++;
return src;
}
#define skip_space(x) _Generic((x), \
char *: skip_space_mut, \
const char *: skip_space_const \
)(x)