Skip to content

Commit

Permalink
text: make text_vprintf static, it is only used within text.c
Browse files Browse the repository at this point in the history
  • Loading branch information
martanne committed Dec 23, 2016
1 parent 25f5a92 commit 58001e9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
26 changes: 13 additions & 13 deletions text.c
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,19 @@ bool text_insert(Text *txt, size_t pos, const char *data, size_t len) {
return true;
}

static bool text_vprintf(Text *txt, size_t pos, const char *format, va_list ap) {
va_list ap_save;
va_copy(ap_save, ap);
int len = vsnprintf(NULL, 0, format, ap);
if (len == -1)
return false;
char *buf = malloc(len+1);
bool ret = buf && (vsnprintf(buf, len+1, format, ap_save) == len) && text_insert(txt, pos, buf, len);
free(buf);
va_end(ap_save);
return ret;
}

bool text_appendf(Text *txt, const char *format, ...) {
va_list ap;
va_start(ap, format);
Expand All @@ -653,19 +666,6 @@ bool text_printf(Text *txt, size_t pos, const char *format, ...) {
return ret;
}

bool text_vprintf(Text *txt, size_t pos, const char *format, va_list ap) {
va_list ap_save;
va_copy(ap_save, ap);
int len = vsnprintf(NULL, 0, format, ap);
if (len == -1)
return false;
char *buf = malloc(len+1);
bool ret = buf && (vsnprintf(buf, len+1, format, ap_save) == len) && text_insert(txt, pos, buf, len);
free(buf);
va_end(ap_save);
return ret;
}

size_t text_insert_newline(Text *txt, size_t pos) {
const char *data = text_newline_char(txt);
size_t len = strlen(data);
Expand Down
1 change: 0 additions & 1 deletion text.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ Text *text_load(const char *filename);
struct stat text_stat(Text*);
bool text_appendf(Text*, const char *format, ...);
bool text_printf(Text*, size_t pos, const char *format, ...);
bool text_vprintf(Text*, size_t pos, const char *format, va_list ap);
/* inserts a line ending character (depending on file type) */
size_t text_insert_newline(Text*, size_t pos);
/* insert `len' bytes starting from `data' at `pos' which has to be
Expand Down

0 comments on commit 58001e9

Please sign in to comment.