KiCad PCB EDA Suite
Loading...
Searching...
No Matches
io.h
Go to the documentation of this file.
1/*
2* This program source code file is part of KiCad, a free EDA CAD application.
3*
4* Copyright The KiCad Developers, see AUTHORS.txt for contributors.
5*
6* This program is free software: you can redistribute it and/or modify it
7* under the terms of the GNU General Public License as published by the
8* Free Software Foundation, either version 3 of the License, or (at your
9* option) any later version.
10*
11* This program is distributed in the hope that it will be useful, but
12* WITHOUT ANY WARRANTY; without even the implied warranty of
13* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14* General Public License for more details.
15*
16* You should have received a copy of the GNU General Public License along
17* with this program. If not, see <http://www.gnu.org/licenses/>.
18*/
19
20#ifndef KIPLATFORM_IO_H_
21#define KIPLATFORM_IO_H_
22
23#include <stdio.h>
24#include <cstddef>
25#include <cstdint>
26#include <vector>
27
28class wxString;
29class wxFileName;
30
31namespace KIPLATFORM
32{
33namespace IO
34{
42 {
43 public:
44 explicit MAPPED_FILE( const wxString& aFileName );
46
47 MAPPED_FILE( const MAPPED_FILE& ) = delete;
48 MAPPED_FILE& operator=( const MAPPED_FILE& ) = delete;
49
50 const uint8_t* Data() const { return m_data; }
51 size_t Size() const { return m_size; }
52
53 private:
54 void readIntoBuffer( const wxString& aFileName );
55
56 const uint8_t* m_data = nullptr;
57 size_t m_size = 0;
58
59#ifdef _WIN32
60 void* m_fileHandle = nullptr;
61 void* m_mapHandle = nullptr;
62#else
63 bool m_isMapped = false;
64#endif
65
66 std::vector<uint8_t> m_fallbackBuffer;
67 };
68
77 static constexpr size_t CLOUD_SYNC_BUFFER_SIZE = 512 * 1024;
86 FILE* SeqFOpen( const wxString& aPath, const wxString& mode );
87
93 bool DuplicatePermissions( const wxString& aSrc, const wxString& aDest );
94
101 bool MakeWriteable( const wxString& aFilePath );
102
107 bool IsFileHidden( const wxString& aFileName );
108
113 void LongPathAdjustment( wxFileName& aFilename );
114
123 long long TimestampDir( const wxString& aDirPath, const wxString& aFilespec );
124} // namespace IO
125} // namespace KIPLATFORM
126
127#endif // KIPLATFORM_IO_H_
MAPPED_FILE(const MAPPED_FILE &)=delete
size_t Size() const
Definition io.h:51
MAPPED_FILE & operator=(const MAPPED_FILE &)=delete
MAPPED_FILE(const wxString &aFileName)
Definition unix/io.cpp:163
void readIntoBuffer(const wxString &aFileName)
Definition common/io.cpp:29
const uint8_t * Data() const
Definition io.h:50
const uint8_t * m_data
Definition io.h:56
std::vector< uint8_t > m_fallbackBuffer
Definition io.h:66
void LongPathAdjustment(wxFileName &aFilename)
Adjusts a filename to be a long path compatible.
Definition unix/io.cpp:98
FILE * SeqFOpen(const wxString &aPath, const wxString &mode)
Opens the file like fopen but sets flags (if available) for sequential read hinting.
Definition unix/io.cpp:36
bool DuplicatePermissions(const wxString &aSrc, const wxString &aDest)
Duplicates the file security data from one file to another ensuring that they are the same between bo...
Definition unix/io.cpp:52
bool IsFileHidden(const wxString &aFileName)
Helper function to determine the status of the 'Hidden' file attribute.
Definition unix/io.cpp:90
bool MakeWriteable(const wxString &aFilePath)
Ensures that a file has write permissions.
Definition unix/io.cpp:75
static constexpr size_t CLOUD_SYNC_BUFFER_SIZE
Buffer size for file I/O operations on cloud-synced folders.
Definition io.h:77
long long TimestampDir(const wxString &aDirPath, const wxString &aFilespec)
Computes a hash of modification times and sizes for files matching a pattern.
Definition unix/io.cpp:104