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>
This commit is contained in:

committed by
Junio C Hamano

parent
0f30233a11
commit
e3b1e3bdc0
13
wrapper.c
13
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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user