KiCad PCB EDA Suite
Loading...
Searching...
No Matches
unix/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#include <wx/filename.h>
25
26#include <fcntl.h>
27#include <sys/stat.h>
28#include <unistd.h>
29
30FILE* KIPLATFORM::IO::SeqFOpen( const wxString& aPath, const wxString& aMode )
31{
32 FILE* fp = wxFopen( aPath, aMode );
33
34 if( fp )
35 posix_fadvise( fileno( fp ), 0, 0, POSIX_FADV_SEQUENTIAL );
36
37 return fp;
38}
39
40bool KIPLATFORM::IO::DuplicatePermissions( const wxString &aSrc, const wxString &aDest )
41{
42 struct stat sourceStat;
43 if( stat( aSrc.fn_str(), &sourceStat ) == 0 )
44 {
45 mode_t permissions = sourceStat.st_mode & ( S_IRWXU | S_IRWXG | S_IRWXO );
46 if( chmod( aDest.fn_str(), permissions ) == 0 )
47 {
48 return true;
49 }
50 else
51 {
52 // Handle error
53 return false;
54 }
55 }
56 else
57 {
58 // Handle error
59 return false;
60 }
61}
62
63bool KIPLATFORM::IO::IsFileHidden( const wxString& aFileName )
64{
65 wxFileName fn( aFileName );
66
67 return fn.GetName().StartsWith( wxT( "." ) );
68}
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:30
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:40
bool IsFileHidden(const wxString &aFileName)
Helper function to determine the status of the 'Hidden' file attribute.
Definition: unix/io.cpp:63