summaryrefslogtreecommitdiffstats
path: root/third_party/libwebrtc/webrtc/rtc_base/unixfilesystem.cc
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
commit2aa4a82499d4becd2284cdb482213d541b8804dd (patch)
treeb80bf8bf13c3766139fbacc530efd0dd9d54394c /third_party/libwebrtc/webrtc/rtc_base/unixfilesystem.cc
parentInitial commit. (diff)
downloadfirefox-upstream.tar.xz
firefox-upstream.zip
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/libwebrtc/webrtc/rtc_base/unixfilesystem.cc')
-rw-r--r--third_party/libwebrtc/webrtc/rtc_base/unixfilesystem.cc142
1 files changed, 142 insertions, 0 deletions
diff --git a/third_party/libwebrtc/webrtc/rtc_base/unixfilesystem.cc b/third_party/libwebrtc/webrtc/rtc_base/unixfilesystem.cc
new file mode 100644
index 0000000000..8732d477a3
--- /dev/null
+++ b/third_party/libwebrtc/webrtc/rtc_base/unixfilesystem.cc
@@ -0,0 +1,142 @@
+/*
+ * Copyright 2004 The WebRTC Project Authors. All rights reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+#include "rtc_base/unixfilesystem.h"
+
+#include <errno.h>
+#include <fcntl.h>
+#include <stdlib.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+#if defined(WEBRTC_MAC) && !defined(WEBRTC_IOS)
+#include <CoreServices/CoreServices.h>
+#include <IOKit/IOCFBundle.h>
+#include <sys/statvfs.h>
+#include "rtc_base/macutils.h"
+#endif // WEBRTC_MAC && !defined(WEBRTC_IOS)
+
+#if defined(WEBRTC_POSIX) && !defined(WEBRTC_MAC) || defined(WEBRTC_IOS)
+#include <sys/types.h>
+#if defined(WEBRTC_ANDROID)
+#include <sys/statfs.h>
+#elif !defined(__native_client__)
+#include <sys/statvfs.h>
+#endif // !defined(__native_client__)
+#include <limits.h>
+#include <pwd.h>
+#include <stdio.h>
+#endif // WEBRTC_POSIX && !WEBRTC_MAC || WEBRTC_IOS
+
+#if defined(WEBRTC_LINUX) && !defined(WEBRTC_ANDROID)
+#include <ctype.h>
+#include <algorithm>
+#endif
+
+#if defined(__native_client__) && !defined(__GLIBC__)
+#include <sys/syslimits.h>
+#endif
+
+#include "rtc_base/arraysize.h"
+#include "rtc_base/checks.h"
+#include "rtc_base/fileutils.h"
+#include "rtc_base/pathutils.h"
+#include "rtc_base/stream.h"
+#include "rtc_base/stringutils.h"
+
+namespace rtc {
+
+UnixFilesystem::UnixFilesystem() {}
+
+UnixFilesystem::~UnixFilesystem() {}
+
+bool UnixFilesystem::DeleteFile(const Pathname &filename) {
+ RTC_LOG(LS_INFO) << "Deleting file:" << filename.pathname();
+
+ if (!IsFile(filename)) {
+ RTC_DCHECK(IsFile(filename));
+ return false;
+ }
+ return ::unlink(filename.pathname().c_str()) == 0;
+}
+
+std::string UnixFilesystem::TempFilename(const Pathname &dir,
+ const std::string &prefix) {
+ int len = dir.pathname().size() + prefix.size() + 2 + 6;
+ char *tempname = new char[len];
+
+ snprintf(tempname, len, "%s/%sXXXXXX", dir.pathname().c_str(),
+ prefix.c_str());
+ int fd = ::mkstemp(tempname);
+ if (fd != -1)
+ ::close(fd);
+ std::string ret(tempname);
+ delete[] tempname;
+
+ return ret;
+}
+
+bool UnixFilesystem::MoveFile(const Pathname &old_path,
+ const Pathname &new_path) {
+ if (!IsFile(old_path)) {
+ RTC_DCHECK(IsFile(old_path));
+ return false;
+ }
+ RTC_LOG(LS_VERBOSE) << "Moving " << old_path.pathname() << " to "
+ << new_path.pathname();
+ if (rename(old_path.pathname().c_str(), new_path.pathname().c_str()) != 0) {
+ return false;
+ }
+ return true;
+}
+
+bool UnixFilesystem::IsFolder(const Pathname &path) {
+ struct stat st;
+ if (stat(path.pathname().c_str(), &st) < 0)
+ return false;
+ return S_ISDIR(st.st_mode);
+}
+
+bool UnixFilesystem::IsFile(const Pathname& pathname) {
+ struct stat st;
+ int res = ::stat(pathname.pathname().c_str(), &st);
+ // Treat symlinks, named pipes, etc. all as files.
+ return res == 0 && !S_ISDIR(st.st_mode);
+}
+
+bool UnixFilesystem::GetFileSize(const Pathname& pathname, size_t *size) {
+ struct stat st;
+ if (::stat(pathname.pathname().c_str(), &st) != 0)
+ return false;
+ *size = st.st_size;
+ return true;
+}
+
+char* UnixFilesystem::CopyString(const std::string& str) {
+ size_t size = str.length() + 1;
+
+ char* buf = new char[size];
+ if (!buf) {
+ return nullptr;
+ }
+
+ strcpyn(buf, size, str.c_str());
+ return buf;
+}
+
+} // namespace rtc
+
+#if defined(__native_client__)
+extern "C" int __attribute__((weak))
+link(const char* oldpath, const char* newpath) {
+ errno = EACCES;
+ return -1;
+}
+#endif