2021-11-13 21:56:53 +00:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
2020-06-09 21:40:46 +01:00
|
|
|
/*
|
2020-08-03 20:56:38 +01:00
|
|
|
* Very simple C string buffer implementation
|
2020-06-09 21:40:46 +01:00
|
|
|
*
|
|
|
|
|
* Copyright Johan Malm 2020
|
|
|
|
|
*/
|
|
|
|
|
|
2023-05-13 16:10:33 +03:00
|
|
|
#ifndef LABWC_BUF_H
|
|
|
|
|
#define LABWC_BUF_H
|
2020-06-09 21:40:46 +01:00
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
|
|
struct buf {
|
|
|
|
|
char *buf;
|
|
|
|
|
int alloc;
|
|
|
|
|
int len;
|
|
|
|
|
};
|
|
|
|
|
|
2021-06-30 19:56:31 +01:00
|
|
|
/**
|
2023-09-21 23:09:05 +01:00
|
|
|
* buf_expand_tilde - expand ~ in buffer
|
|
|
|
|
* @s: buffer
|
|
|
|
|
*/
|
|
|
|
|
void buf_expand_tilde(struct buf *s);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* buf_expand_shell_variables - expand $foo and ${foo} in buffer
|
2021-06-30 19:56:31 +01:00
|
|
|
* @s: buffer
|
2021-10-13 21:30:44 +01:00
|
|
|
* Note: $$ is not handled
|
2021-06-30 19:56:31 +01:00
|
|
|
*/
|
|
|
|
|
void buf_expand_shell_variables(struct buf *s);
|
|
|
|
|
|
2020-08-07 20:21:14 +01:00
|
|
|
/**
|
2020-08-03 20:56:38 +01:00
|
|
|
* buf_init - allocate NULL-terminated C string buffer
|
2021-06-30 19:56:31 +01:00
|
|
|
* @s: buffer
|
2021-10-13 21:30:44 +01:00
|
|
|
* Note: use free(s->buf) to free it
|
2020-08-03 20:56:38 +01:00
|
|
|
*/
|
2020-06-09 21:40:46 +01:00
|
|
|
void buf_init(struct buf *s);
|
2020-08-03 20:56:38 +01:00
|
|
|
|
2020-08-07 20:21:14 +01:00
|
|
|
/**
|
2020-08-03 20:56:38 +01:00
|
|
|
* buf_add - add data to C string buffer
|
2021-06-30 19:56:31 +01:00
|
|
|
* @s: buffer
|
|
|
|
|
* @data: data to be added
|
2020-08-03 20:56:38 +01:00
|
|
|
*/
|
2020-06-09 21:40:46 +01:00
|
|
|
void buf_add(struct buf *s, const char *data);
|
|
|
|
|
|
2024-03-16 04:39:45 +01:00
|
|
|
/**
|
|
|
|
|
* buf_add_char - add single char to C string buffer
|
|
|
|
|
* @s: buffer
|
|
|
|
|
* @data: char to be added
|
|
|
|
|
*/
|
|
|
|
|
void buf_add_char(struct buf *s, char data);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* buf_clear - clear the buffer, internal allocations are preserved
|
|
|
|
|
* @s: buffer
|
|
|
|
|
*/
|
|
|
|
|
void buf_clear(struct buf *s);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* buf_reset - reset the buffer, internal allocations are free'd
|
|
|
|
|
* @s: buffer
|
|
|
|
|
*/
|
|
|
|
|
void buf_reset(struct buf *s);
|
|
|
|
|
|
2023-05-13 16:10:33 +03:00
|
|
|
#endif /* LABWC_BUF_H */
|