mirror of
https://github.com/systemd/systemd.git
synced 2026-07-13 19:10:58 +00:00
tree-wide: use memstream-util
This commit is contained in:
@@ -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];
|
||||
|
||||
Reference in New Issue
Block a user