mirror of
https://github.com/obsproject/obs-studio.git
synced 2024-09-20 13:08:50 +02:00
libobs/util: Add function to get free space
Meant as a part of solving mantis issue 105 ("Disk space usage monitor when recording"). From pull request: jp9000/obs-studio#374 Relevant mantis issue: https://obsproject.com/mantis/view.php?id=105
This commit is contained in:
parent
3e6db990fc
commit
e354a433c7
@ -18,6 +18,7 @@
|
||||
#include <errno.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/statvfs.h>
|
||||
#include <dirent.h>
|
||||
#include <stdlib.h>
|
||||
#include <limits.h>
|
||||
@ -333,6 +334,17 @@ void os_closedir(os_dir_t *dir)
|
||||
}
|
||||
}
|
||||
|
||||
int64_t os_get_free_space(const char *path)
|
||||
{
|
||||
struct statvfs info;
|
||||
int64_t ret = (int64_t)statvfs(path, &info);
|
||||
|
||||
if (ret == 0)
|
||||
ret = (int64_t)info.f_bsize * (int64_t)info.f_bfree;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
struct posix_glob_info {
|
||||
struct os_glob_info base;
|
||||
glob_t gl;
|
||||
|
@ -362,6 +362,25 @@ void os_closedir(os_dir_t *dir)
|
||||
}
|
||||
}
|
||||
|
||||
int64_t os_get_free_space(const char *path)
|
||||
{
|
||||
ULARGE_INTEGER remainingSpace;
|
||||
char abs_path[512];
|
||||
wchar_t w_abs_path[512];
|
||||
|
||||
if (os_get_abs_path(path, abs_path, 512) > 0) {
|
||||
if (os_utf8_to_wcs(abs_path, 0, w_abs_path, 512) > 0) {
|
||||
BOOL success = GetDiskFreeSpaceExW(w_abs_path,
|
||||
(PULARGE_INTEGER)&remainingSpace,
|
||||
NULL, NULL);
|
||||
if (success)
|
||||
return (int64_t)remainingSpace.QuadPart;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void make_globent(struct os_globent *ent, WIN32_FIND_DATA *wfd,
|
||||
const char *pattern)
|
||||
{
|
||||
|
@ -52,6 +52,7 @@ EXPORT bool os_quick_write_mbs_file(const char *path, const char *str,
|
||||
size_t len);
|
||||
|
||||
EXPORT int64_t os_get_file_size(const char *path);
|
||||
EXPORT int64_t os_get_free_space(const char *path);
|
||||
|
||||
EXPORT size_t os_mbs_to_wcs(const char *str, size_t str_len, wchar_t *dst,
|
||||
size_t dst_size);
|
||||
|
Loading…
Reference in New Issue
Block a user