blob: 303d9f5f7bb12b9a582fac50f9911216e38dd99d [file] [log] [blame]
xians@webrtc.orge46bc772014-10-10 08:36:56 +00001/*
2 * Copyright 2014 The WebRTC Project Authors. All rights reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef RTC_BASE_PLATFORM_FILE_H_
12#define RTC_BASE_PLATFORM_FILE_H_
xians@webrtc.orge46bc772014-10-10 08:36:56 +000013
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020014#include <stdio.h>
Jonas Olssona4d87372019-07-05 19:08:33 +020015
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020016#include <string>
xians@webrtc.orge46bc772014-10-10 08:36:56 +000017
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020018#if defined(WEBRTC_WIN)
Patrik Höglunda8005cf2017-12-13 16:05:42 +010019#include <windows.h>
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020020#endif
21
22namespace rtc {
23
24#if defined(WEBRTC_WIN)
25typedef HANDLE PlatformFile;
26#elif defined(WEBRTC_POSIX)
27typedef int PlatformFile;
28#else
29#error Unsupported platform
30#endif
31
32extern const PlatformFile kInvalidPlatformFileValue;
33
34// Associates a standard FILE stream with an existing PlatformFile.
35// Note that after this function has returned a valid FILE stream,
36// the PlatformFile should no longer be used.
37FILE* FdopenPlatformFileForWriting(PlatformFile file);
38
Artem Titove62f6002018-03-19 15:40:00 +010039// Associates a standard FILE stream with an existing PlatformFile.
40// Note that after this function has returned a valid FILE stream,
41// the PlatformFile should no longer be used.
42FILE* FdopenPlatformFile(PlatformFile file, const char* modes);
43
Karl Wiberg04042252018-02-22 11:41:25 +010044// Closes a PlatformFile. Returns true on success, false on failure.
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020045// Don't use ClosePlatformFile to close a file opened with FdopenPlatformFile.
46// Use fclose instead.
47bool ClosePlatformFile(PlatformFile file);
48
49// Removes a file in the filesystem.
50bool RemoveFile(const std::string& path);
51
52// Opens a file for reading and writing. You might want to use base/file.h
53// instead.
54PlatformFile OpenPlatformFile(const std::string& path);
55
Artem Titove62f6002018-03-19 15:40:00 +010056// Opens a file for reading only. You might want to use base/file.h
57// instead.
58PlatformFile OpenPlatformFileReadOnly(const std::string& path);
59
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020060// Creates a new file for reading and writing. If the file already exists it
61// will be overwritten. You might want to use base/file.h instead.
62PlatformFile CreatePlatformFile(const std::string& path);
63
64} // namespace rtc
xians@webrtc.orge46bc772014-10-10 08:36:56 +000065
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020066#endif // RTC_BASE_PLATFORM_FILE_H_