summaryrefslogtreecommitdiffstats
path: root/wrapper.c
diff options
context:
space:
mode:
authorPranit Bauva <pranit.bauva@gmail.com>2019-01-02 16:38:32 +0100
committerJunio C Hamano <gitster@pobox.com>2019-01-02 19:23:02 +0100
commite3b1e3bdc0aa5fa6a474874a2395ae0584b2aea7 (patch)
tree386a67166934950ca7779382b767bd7a1416c4b9 /wrapper.c
parentbisect--helper: `bisect_write` shell function in C (diff)
downloadgit-e3b1e3bdc0aa5fa6a474874a2395ae0584b2aea7.tar.xz
git-e3b1e3bdc0aa5fa6a474874a2395ae0584b2aea7.zip
wrapper: move is_empty_file() and rename it as is_empty_or_missing_file()
is_empty_file() can help to refactor a lot of code. This will be very helpful in porting "git bisect" to C. Suggested-by: Torsten Bögershausen <tboegi@web.de> Mentored-by: Lars Schneider <larsxschneider@gmail.com> Mentored-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Pranit Bauva <pranit.bauva@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'wrapper.c')
-rw-r--r--wrapper.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/wrapper.c b/wrapper.c
index e4fa9d84cd..ea3cf64d4c 100644
--- a/wrapper.c
+++ b/wrapper.c
@@ -690,3 +690,16 @@ int xgethostname(char *buf, size_t len)
buf[len - 1] = 0;
return ret;
}
+
+int is_empty_or_missing_file(const char *filename)
+{
+ struct stat st;
+
+ if (stat(filename, &st) < 0) {
+ if (errno == ENOENT)
+ return 1;
+ die_errno(_("could not stat %s"), filename);
+ }
+
+ return !st.st_size;
+}