bisect: verify that a bogus option won't try to start a bisection
[git/debian.git] / compat / disk.h
blob50a32e3d8a43bc2bc45c8c8afa2c59e79518fc07
1 #ifndef COMPAT_DISK_H
2 #define COMPAT_DISK_H
4 #include "git-compat-util.h"
6 static int get_disk_info(struct strbuf *out)
8 struct strbuf buf = STRBUF_INIT;
9 int res = 0;
11 #ifdef GIT_WINDOWS_NATIVE
12 char volume_name[MAX_PATH], fs_name[MAX_PATH];
13 DWORD serial_number, component_length, flags;
14 ULARGE_INTEGER avail2caller, total, avail;
16 strbuf_realpath(&buf, ".", 1);
17 if (!GetDiskFreeSpaceExA(buf.buf, &avail2caller, &total, &avail)) {
18 error(_("could not determine free disk size for '%s'"),
19 buf.buf);
20 res = -1;
21 goto cleanup;
24 strbuf_setlen(&buf, offset_1st_component(buf.buf));
25 if (!GetVolumeInformationA(buf.buf, volume_name, sizeof(volume_name),
26 &serial_number, &component_length, &flags,
27 fs_name, sizeof(fs_name))) {
28 error(_("could not get info for '%s'"), buf.buf);
29 res = -1;
30 goto cleanup;
32 strbuf_addf(out, "Available space on '%s': ", buf.buf);
33 strbuf_humanise_bytes(out, avail2caller.QuadPart);
34 strbuf_addch(out, '\n');
35 #else
36 struct statvfs stat;
38 strbuf_realpath(&buf, ".", 1);
39 if (statvfs(buf.buf, &stat) < 0) {
40 error_errno(_("could not determine free disk size for '%s'"),
41 buf.buf);
42 res = -1;
43 goto cleanup;
46 strbuf_addf(out, "Available space on '%s': ", buf.buf);
47 strbuf_humanise_bytes(out, (off_t)stat.f_bsize * (off_t)stat.f_bavail);
48 strbuf_addf(out, " (mount flags 0x%lx)\n", stat.f_flag);
49 #endif
51 cleanup:
52 strbuf_release(&buf);
53 return res;
56 #endif /* COMPAT_DISK_H */