blob: 52fbaff11550bfee2bf97cf2bdb61b478c7b508d [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>
15#include <string>
xians@webrtc.orge46bc772014-10-10 08:36:56 +000016
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020017#if defined(WEBRTC_WIN)
Patrik Höglunda8005cf2017-12-13 16:05:42 +010018#include <windows.h>
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020019#endif
20
21namespace rtc {
22
23#if defined(WEBRTC_WIN)
24typedef HANDLE PlatformFile;
25#elif defined(WEBRTC_POSIX)
26typedef int PlatformFile;
27#else
28#error Unsupported platform
29#endif
30
31extern const PlatformFile kInvalidPlatformFileValue;
32
33// Associates a standard FILE stream with an existing PlatformFile.
34// Note that after this function has returned a valid FILE stream,
35// the PlatformFile should no longer be used.
36FILE* FdopenPlatformFileForWriting(PlatformFile file);
37
Artem Titove62f6002018-03-19 15:40:00 +010038// Associates a standard FILE stream with an existing PlatformFile.
39// Note that after this function has returned a valid FILE stream,
40// the PlatformFile should no longer be used.
41FILE* FdopenPlatformFile(PlatformFile file, const char* modes);
42
Karl Wiberg04042252018-02-22 11:41:25 +010043// Closes a PlatformFile. Returns true on success, false on failure.
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020044// Don't use ClosePlatformFile to close a file opened with FdopenPlatformFile.
45// Use fclose instead.
46bool ClosePlatformFile(PlatformFile file);
47
48// Removes a file in the filesystem.
49bool RemoveFile(const std::string& path);
50
51// Opens a file for reading and writing. You might want to use base/file.h
52// instead.
53PlatformFile OpenPlatformFile(const std::string& path);
54
Artem Titove62f6002018-03-19 15:40:00 +010055// Opens a file for reading only. You might want to use base/file.h
56// instead.
57PlatformFile OpenPlatformFileReadOnly(const std::string& path);
58
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020059// Creates a new file for reading and writing. If the file already exists it
60// will be overwritten. You might want to use base/file.h instead.
61PlatformFile CreatePlatformFile(const std::string& path);
62
63} // namespace rtc
xians@webrtc.orge46bc772014-10-10 08:36:56 +000064
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020065#endif // RTC_BASE_PLATFORM_FILE_H_