tree-wide: use memstream-util

This commit is contained in:
Yu Watanabe
2023-05-26 15:40:12 +09:00
parent abe72100cf
commit 2485b7e2b8
29 changed files with 302 additions and 479 deletions

View File

@@ -15,6 +15,7 @@
#include "locale-util.h"
#include "macro.h"
#include "memory-util.h"
#include "memstream-util.h"
#include "string-util.h"
#include "strv.h"
#include "terminal-util.h"
@@ -604,9 +605,9 @@ char *strip_tab_ansi(char **ibuf, size_t *_isz, size_t highlight[2]) {
STATE_CSI,
STATE_CSO,
} state = STATE_OTHER;
_cleanup_free_ char *obuf = NULL;
_cleanup_fclose_ FILE *f = NULL;
size_t osz = 0, isz, shift[2] = {}, n_carriage_returns = 0;
_cleanup_(memstream_done) MemStream m = {};
size_t isz, shift[2] = {}, n_carriage_returns = 0;
FILE *f;
assert(ibuf);
assert(*ibuf);
@@ -629,7 +630,7 @@ char *strip_tab_ansi(char **ibuf, size_t *_isz, size_t highlight[2]) {
/* Note we turn off internal locking on f for performance reasons. It's safe to do so since we
* created f here and it doesn't leave our scope. */
f = open_memstream_unlocked(&obuf, &osz);
f = memstream_init(&m);
if (!f)
return NULL;
@@ -714,19 +715,12 @@ char *strip_tab_ansi(char **ibuf, size_t *_isz, size_t highlight[2]) {
}
}
if (fflush_and_check(f) < 0)
return NULL;
f = safe_fclose(f);
if (!obuf)
char *obuf;
if (memstream_finalize(&m, &obuf, _isz) < 0)
return NULL;
free_and_replace(*ibuf, obuf);
if (_isz)
*_isz = osz;
if (highlight) {
highlight[0] += shift[0];
highlight[1] += shift[1];