2017-02-08 21:14:30 +00:00
|
|
|
/*
|
2018-02-22 13:23:33 +00:00
|
|
|
* gluon-web Template - Utility header
|
2017-02-08 21:14:30 +00:00
|
|
|
*
|
|
|
|
* Copyright (C) 2010-2012 Jo-Philipp Wich <jow@openwrt.org>
|
2018-02-22 13:23:33 +00:00
|
|
|
* Copyright (C) 2018 Matthias Schiffer <mschiffer@universe-factory.net>
|
2017-02-08 21:14:30 +00:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _TEMPLATE_UTILS_H_
|
|
|
|
#define _TEMPLATE_UTILS_H_
|
|
|
|
|
2018-02-22 16:41:38 +00:00
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stddef.h>
|
2017-02-08 21:14:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* buffer object */
|
|
|
|
struct template_buffer {
|
|
|
|
char *data;
|
|
|
|
char *dptr;
|
2018-02-22 16:41:38 +00:00
|
|
|
size_t size;
|
2017-02-08 21:14:30 +00:00
|
|
|
};
|
|
|
|
|
2018-02-22 16:41:38 +00:00
|
|
|
struct template_buffer * buf_init(size_t size);
|
2018-02-22 23:57:03 +00:00
|
|
|
bool buf_putchar(struct template_buffer *buf, char c);
|
2018-02-22 16:41:38 +00:00
|
|
|
bool buf_append(struct template_buffer *buf, const char *s, size_t len);
|
2017-02-08 21:14:30 +00:00
|
|
|
char * buf_destroy(struct template_buffer *buf);
|
|
|
|
|
|
|
|
/* read buffer length */
|
2018-02-23 01:08:11 +00:00
|
|
|
static inline size_t buf_length(const struct template_buffer *buf)
|
2017-02-08 21:14:30 +00:00
|
|
|
{
|
2018-02-22 16:41:38 +00:00
|
|
|
return buf->dptr - buf->data;
|
2017-02-08 21:14:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-02-22 16:41:38 +00:00
|
|
|
char * pcdata(const char *s, size_t l, size_t *outl);
|
2017-02-08 21:14:30 +00:00
|
|
|
|
|
|
|
#endif
|