rtl_433/include/abuf.h

51 lines
1.2 KiB
C
Raw Permalink Normal View History

/** @file
array buffer (string builder).
2019-02-15 17:04:27 +01:00
Copyright (C) 2018 Christian Zuckschwerdt
2019-02-15 17:04:27 +01:00
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
*/
2018-12-16 17:23:01 +00:00
#ifndef INCLUDE_ABUF_H_
#define INCLUDE_ABUF_H_
2021-12-08 11:11:38 +01:00
#if defined _MSC_VER || defined ESP32 // Microsoft Visual Studio or ESP32
// MSC and ESP32 have something like C99 restrict as __restrict
2019-11-09 15:28:24 +01:00
#ifndef restrict
#define restrict __restrict
#endif
2018-12-17 13:41:14 +01:00
#endif
2021-01-27 18:02:33 +01:00
// Defined in newer <sal.h> for MSVC.
#ifndef _Printf_format_string_
#define _Printf_format_string_
#endif
2018-12-17 13:41:14 +01:00
2018-12-16 17:23:01 +00:00
#include <stddef.h>
typedef struct abuf {
char *head;
char *tail;
size_t left;
} abuf_t;
void abuf_init(abuf_t *buf, char *dst, size_t len);
void abuf_setnull(abuf_t *buf);
char *abuf_push(abuf_t *buf);
void abuf_pop(abuf_t *buf, char *end);
void abuf_cat(abuf_t *buf, const char *str);
2021-01-27 18:02:33 +01:00
int abuf_printf(abuf_t *buf, _Printf_format_string_ char const *restrict format, ...)
#if defined(__GNUC__) || defined(__clang__)
__attribute__((format(printf, 2, 3)))
#endif
;
2018-12-16 17:23:01 +00:00
#endif /* INCLUDE_ABUF_H_ */