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 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6*
7* This program is free software: you can redistribute it and/or modify it
8* under the terms of the GNU General Public License as published by the
9* Free Software Foundation, either version 3 of the License, or (at your
10* option) any later version.
11*
12* This program is distributed in the hope that it will be useful, but
13* WITHOUT ANY WARRANTY; without even the implied warranty of
14* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15* General Public License for more details.
16*
17* You should have received a copy of the GNU General Public License along
18* with this program. If not, see <http://www.gnu.org/licenses/>.
19*/
20
21#include <kiplatform/io.h>
22
23#include <wx/crt.h>
24#include <wx/string.h>
25#include <wx/filename.h>
26
27#include <fcntl.h>
28#include <sys/stat.h>
29#include <unistd.h>
30
31FILE* KIPLATFORM::IO::SeqFOpen( const wxString& aPath, const wxString& aMode )
32{
33 FILE* fp = wxFopen( aPath, aMode );
34
35 if( fp )
36 {
37 if( posix_fadvise( fileno( fp ), 0, 0, POSIX_FADV_SEQUENTIAL ) != 0 )
38 {
39 fclose( fp );
40 fp = nullptr;
41 }
42 }
43
44 return fp;
45}
46
47bool KIPLATFORM::IO::DuplicatePermissions( const wxString &aSrc, const wxString &aDest )
48{
49 struct stat sourceStat;
50 if( stat( aSrc.fn_str(), &sourceStat ) == 0 )
51 {
52 mode_t permissions = sourceStat.st_mode & ( S_IRWXU | S_IRWXG | S_IRWXO );
53 if( chmod( aDest.fn_str(), permissions ) == 0 )
54 {
55 return true;
56 }
57 else
58 {
59 // Handle error
60 return false;
61 }
62 }
63 else
64 {
65 // Handle error
66 return false;
67 }
68}
69
70bool KIPLATFORM::IO::IsFileHidden( const wxString& aFileName )
71{
72 wxFileName fn( aFileName );
73
74 return fn.GetName().StartsWith( wxT( "." ) );
75}
76
77
78void KIPLATFORM::IO::LongPathAdjustment( wxFileName& aFilename )
79{
80 // no-op
81}
void LongPathAdjustment(wxFileName &aFilename)
Adjusts a filename to be a long path compatible.
Definition: unix/io.cpp:78
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:31
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:47
bool IsFileHidden(const wxString &aFileName)
Helper function to determine the status of the 'Hidden' file attribute.
Definition: unix/io.cpp:70