aboutsummaryrefslogtreecommitdiff
path: root/include/sb.h
blob: 1dbed9a2f7def244c2e4bdb74a2fcae19e3c63e4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// sb.h --- String Builder                                             -*- C -*-
//
// Copyright (c) 2026 Martin Michalec <martin@michalec.dev>
//
// SPDX-License-Identifier: MIT
//
// This file is part of COSMOS Codebase.
//
// Commentary:
//
//   MAYBE(cmmm): include as extension in da.h
//
// Code:

#ifndef INCLUDED_COSMOS_SB_H
#define INCLUDED_COSMOS_SB_H

#include "da.h"
#include "mv.h"

struct sb {
  struct da_hdr hdr;
  char         *arr;
};

/*  */ char *sb_cstr (struct sb *);
struct ms    sb_ms   (struct sb);

// specialized pushing
struct ms sb_push_mv     (struct sb *, struct mv    );
struct ms sb_push_mv_arr (struct sb *, struct mv_arr);
struct ms sb_pad         (struct sb *, int n, char  );

#ifndef SB_NO_FEAT_STDIO

// FORMAT_PRINTF (2, 3)
__attribute__ ((__format__ (__printf__, 2, 3)))
int sb_printf  (struct sb *, const char *fmt, ...    );
int sb_vprintf (struct sb *, const char *fmt, va_list);

#endif // SB_NO_FEAT_STDIO

#ifndef SB_NO_FEAT_UNISTD

struct ms sb_read_until_eof (struct sb *, int fd);

#ifndef IOBUF_NO_FEAT_UNISTD
#include "iobuf.h"
struct ms sb_read_until     (struct sb *, int fd,        u8 del, struct iobuf *);
struct ms sb_read_until_any (struct sb *, int fd, struct mv set, struct iobuf *);
struct ms sb_read_until_seq (struct sb *, int fd, struct mv seq, struct iobuf *);
#endif // IOBUF_NO_FEAT_UNISTD

#endif // SB_NO_FEAT_UNISTD

#endif // INCLUDED_COSMOS_SB_H

// sb.h ends here