libobs/util: Add function to get free disk space
This commit is contained in:
parent
ce44791932
commit
9e466a4697
@ -679,3 +679,12 @@ int os_get_logical_cores(void)
|
||||
return logical_cores;
|
||||
}
|
||||
#endif
|
||||
|
||||
uint64_t os_get_free_disk_space(const char *dir)
|
||||
{
|
||||
struct statvfs info;
|
||||
if (statvfs(dir, &info) != 0)
|
||||
return 0;
|
||||
|
||||
return (uint64_t)info.f_frsize * (uint64_t)info.f_bavail;
|
||||
}
|
||||
|
@ -946,3 +946,16 @@ int os_get_logical_cores(void)
|
||||
os_get_cores_internal();
|
||||
return logical_cores;
|
||||
}
|
||||
|
||||
uint64_t os_get_free_disk_space(const char *dir)
|
||||
{
|
||||
wchar_t *wdir = NULL;
|
||||
if (!os_utf8_to_wcs_ptr(dir, 0, &wdir))
|
||||
return 0;
|
||||
|
||||
ULARGE_INTEGER free;
|
||||
bool success = !!GetDiskFreeSpaceExW(wdir, &free, NULL, NULL);
|
||||
bfree(wdir);
|
||||
|
||||
return success ? free.QuadPart : 0;
|
||||
}
|
||||
|
@ -153,6 +153,8 @@ EXPORT int os_rmdir(const char *path);
|
||||
EXPORT char *os_getcwd(char *path, size_t size);
|
||||
EXPORT int os_chdir(const char *path);
|
||||
|
||||
EXPORT uint64_t os_get_free_disk_space(const char *dir);
|
||||
|
||||
#define MKDIR_EXISTS 1
|
||||
#define MKDIR_SUCCESS 0
|
||||
#define MKDIR_ERROR -1
|
||||
|
Loading…
x
Reference in New Issue
Block a user