KiCad PCB EDA Suite
Loading...
Searching...
No Matches
gtk/io.cpp
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 (C) 2023 Mark Roszko <[email protected]>
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#include <kiplatform/io.h>
21
22#include <wx/crt.h>
23#include <wx/string.h>
24
25#include <fcntl.h>
26#include <sys/stat.h>
27#include <unistd.h>
28
29FILE* KIPLATFORM::IO::SeqFOpen( const wxString& aPath, const wxString& aMode )
30{
31 FILE* fp = wxFopen( aPath, aMode );
32
33 if( fp )
34 posix_fadvise( fileno( fp ), 0, 0, POSIX_FADV_SEQUENTIAL );
35
36 return fp;
37}
38
39bool KIPLATFORM::IO::DuplicatePermissions( const wxString &aSrc, const wxString &aDest )
40{
41 struct stat sourceStat;
42 if( stat( aSrc.fn_str(), &sourceStat ) == 0 )
43 {
44 mode_t permissions = sourceStat.st_mode & ( S_IRWXU | S_IRWXG | S_IRWXO );
45 if( chmod( aDest.fn_str(), permissions ) == 0 )
46 {
47 return true;
48 }
49 else
50 {
51 // Handle error
52 return false;
53 }
54 }
55 else
56 {
57 // Handle error
58 return false;
59 }
60}
FILE * SeqFOpen(const wxString &aPath, const wxString &mode)
Opens the file like fopen but sets flags (if available) for sequential read hinting.
Definition: gtk/io.cpp:29
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: gtk/io.cpp:39