From ac78e548049f4e86b38368d2c4b4dbb546c64ac6 Mon Sep 17 00:00:00 2001 From: Alex Riesen Date: Thu, 19 Apr 2007 02:05:03 +0200 Subject: Simplify calling of CR/LF conversion routines Signed-off-by: Alex Riesen Signed-off-by: Junio C Hamano --- builtin-apply.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) (limited to 'builtin-apply.c') diff --git a/builtin-apply.c b/builtin-apply.c index fd92ef7174..ccd342c1c4 100644 --- a/builtin-apply.c +++ b/builtin-apply.c @@ -1475,8 +1475,8 @@ static int read_old_data(struct stat *st, const char *path, char **buf_p, unsign } close(fd); nsize = got; - nbuf = buf; - if (convert_to_git(path, &nbuf, &nsize)) { + nbuf = convert_to_git(path, buf, &nsize); + if (nbuf) { free(buf); *buf_p = nbuf; *alloc_p = nsize; @@ -2355,9 +2355,8 @@ static void add_index_file(const char *path, unsigned mode, void *buf, unsigned static int try_create_file(const char *path, unsigned int mode, const char *buf, unsigned long size) { - int fd, converted; + int fd; char *nbuf; - unsigned long nsize; if (has_symlinks && S_ISLNK(mode)) /* Although buf:size is counted string, it also is NUL @@ -2369,13 +2368,10 @@ static int try_create_file(const char *path, unsigned int mode, const char *buf, if (fd < 0) return -1; - nsize = size; - nbuf = (char *) buf; - converted = convert_to_working_tree(path, &nbuf, &nsize); - if (converted) { + nbuf = convert_to_working_tree(path, buf, &size); + if (nbuf) buf = nbuf; - size = nsize; - } + while (size) { int written = xwrite(fd, buf, size); if (written < 0) @@ -2387,7 +2383,7 @@ static int try_create_file(const char *path, unsigned int mode, const char *buf, } if (close(fd) < 0) die("closing file %s: %s", path, strerror(errno)); - if (converted) + if (nbuf) free(nbuf); return 0; } -- cgit v1.2.3