refs: fix format migration on Cygwin
[git/debian.git] / compat / disk.h
blob23bc1bef86c87a0853b87d75e0fc35ea1932f99d
1 #ifndef COMPAT_DISK_H
2 #define COMPAT_DISK_H
4 #include "abspath.h"
5 #include "gettext.h"
7 static int get_disk_info(struct strbuf *out)
9 struct strbuf buf = STRBUF_INIT;
10 int res = 0;
12 #ifdef GIT_WINDOWS_NATIVE
13 char volume_name[MAX_PATH], fs_name[MAX_PATH];
14 DWORD serial_number, component_length, flags;
15 ULARGE_INTEGER avail2caller, total, avail;
17 strbuf_realpath(&buf, ".", 1);
18 if (!GetDiskFreeSpaceExA(buf.buf, &avail2caller, &total, &avail)) {
19 error(_("could not determine free disk size for '%s'"),
20 buf.buf);
21 res = -1;
22 goto cleanup;
25 strbuf_setlen(&buf, offset_1st_component(buf.buf));
26 if (!GetVolumeInformationA(buf.buf, volume_name, sizeof(volume_name),
27 &serial_number, &component_length, &flags,
28 fs_name, sizeof(fs_name))) {
29 error(_("could not get info for '%s'"), buf.buf);
30 res = -1;
31 goto cleanup;
33 strbuf_addf(out, "Available space on '%s': ", buf.buf);
34 strbuf_humanise_bytes(out, avail2caller.QuadPart);
35 strbuf_addch(out, '\n');
36 #else
37 struct statvfs stat;
39 strbuf_realpath(&buf, ".", 1);
40 if (statvfs(buf.buf, &stat) < 0) {
41 error_errno(_("could not determine free disk size for '%s'"),
42 buf.buf);
43 res = -1;
44 goto cleanup;
47 strbuf_addf(out, "Available space on '%s': ", buf.buf);
48 strbuf_humanise_bytes(out, (off_t)stat.f_bsize * (off_t)stat.f_bavail);
49 strbuf_addf(out, " (mount flags 0x%lx)\n", stat.f_flag);
50 #endif
52 cleanup:
53 strbuf_release(&buf);
54 return res;
57 #endif /* COMPAT_DISK_H */