summaryrefslogtreecommitdiff
path: root/win32/win32.c
diff options
context:
space:
mode:
authorusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-04-22 15:45:00 +0000
committerusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-04-22 15:45:00 +0000
commit86dc863bd84ce79d48e5ada9f57bbe24b97db948 (patch)
tree0f09d8edf917936b230dc8855bed33d0dc3ecc17 /win32/win32.c
parent900ede40532640376f7a2ee359e70df2a546e060 (diff)
* win32/win32.c, include/ruby/win32.h (ustatfs): implementation of
statfs(2) clone. [EXPERIMENTAL] * file.c (rb_io_statfs): use above function. * configure.in, win32/Makefile.sub (struct statfs): available. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45672 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'win32/win32.c')
-rw-r--r--win32/win32.c48
1 files changed, 48 insertions, 0 deletions
diff --git a/win32/win32.c b/win32/win32.c
index 79519aa..f8b2ff0 100644
--- a/win32/win32.c
+++ b/win32/win32.c
@@ -5865,6 +5865,54 @@ rb_w32_pipe(int fds[2])
}
/* License: Ruby's */
+int
+ustatfs(const char *path, struct statfs *buf)
+{
+ WCHAR *wpath = utf8_to_wstr(path, NULL);
+ WCHAR root[MAX_PATH], system[8];
+ DWORD serial, spc, bps, unused, total;
+ char *tmp;
+
+ if (!wpath) {
+ return -1;
+ }
+
+ if (!GetVolumePathNameW(wpath, root, sizeof(root) / sizeof(WCHAR))) {
+ free(wpath);
+ errno = map_errno(GetLastError());
+ return -1;
+ }
+ free(wpath);
+
+ if (!GetVolumeInformationW(root, NULL, 0, &serial, NULL, NULL,
+ system, sizeof(system) / sizeof(WCHAR))) {
+ errno = map_errno(GetLastError());
+ return -1;
+ }
+
+ if (!GetDiskFreeSpaceW(root, &spc, &bps, &unused, &total)) {
+ errno = map_errno(GetLastError());
+ return -1;
+ }
+
+ tmp = wstr_to_filecp(system, NULL);
+ if (!tmp) {
+ return -1;
+ }
+ strlcpy(buf->f_fstypename, tmp, sizeof(buf->f_fstypename));
+ free(tmp);
+
+ buf->f_type = 0;
+ buf->f_bsize = (uint64_t)spc * bps;
+ buf->f_blocks = total;
+ buf->f_bfree = buf->f_bavail = unused;
+ buf->f_files = buf->f_ffree = 0;
+ buf->f_fsid = serial;
+
+ return 0;
+}
+
+/* License: Ruby's */
static int
console_emulator_p(void)
{