summaryrefslogtreecommitdiff
path: root/builtin-stripspace.c
diff options
context:
space:
mode:
authorPierre Habouzit <madcoder@debian.org>2007-09-10 12:35:09 +0200
committerJunio C Hamano <gitster@pobox.com>2007-09-10 12:50:58 -0700
commitfd17f5b5f77716bf90098c6e49e3cf7fd9f56306 (patch)
tree7b6ed050e8283c9fe80d0c8229281de4bed4dccf /builtin-stripspace.c
parent635d043f30c60f5ec8121bd94304e529f90407c7 (diff)
downloadgit-fd17f5b5f77716bf90098c6e49e3cf7fd9f56306.tar.gz
Replace all read_fd use with strbuf_read, and get rid of it.
This brings builtin-stripspace, builtin-tag and mktag to use strbufs. Signed-off-by: Pierre Habouzit <madcoder@debian.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin-stripspace.c')
-rw-r--r--builtin-stripspace.c21
1 files changed, 9 insertions, 12 deletions
diff --git a/builtin-stripspace.c b/builtin-stripspace.c
index 916355ca5d..c4cf2f05ca 100644
--- a/builtin-stripspace.c
+++ b/builtin-stripspace.c
@@ -1,5 +1,6 @@
#include "builtin.h"
#include "cache.h"
+#include "strbuf.h"
/*
* Returns the length of a line, without trailing spaces.
@@ -74,26 +75,22 @@ size_t stripspace(char *buffer, size_t length, int skip_comments)
int cmd_stripspace(int argc, const char **argv, const char *prefix)
{
- char *buffer;
- unsigned long size;
+ struct strbuf buf;
int strip_comments = 0;
if (argc > 1 && (!strcmp(argv[1], "-s") ||
!strcmp(argv[1], "--strip-comments")))
strip_comments = 1;
- size = 1024;
- buffer = xmalloc(size);
- if (read_fd(0, &buffer, &size)) {
- free(buffer);
+ strbuf_init(&buf, 0);
+ if (strbuf_read(&buf, 0, 1024) < 0)
die("could not read the input");
- }
- size = stripspace(buffer, size, strip_comments);
- write_or_die(1, buffer, size);
- if (size)
- putc('\n', stdout);
+ strbuf_setlen(&buf, stripspace(buf.buf, buf.len, strip_comments));
+ if (buf.len)
+ strbuf_addch(&buf, '\n');
- free(buffer);
+ write_or_die(1, buf.buf, buf.len);
+ strbuf_release(&buf);
return 0;
}