\helpref{wxBITMAP}{wxbitmapmacro}\\
\helpref{wxBeginBusyCursor}{wxbeginbusycursor}\\
\helpref{wxBell}{wxbell}\\
+\helpref{wxCHANGE\_UMASK}{wxchangeumask}\\
\helpref{wxCHECK}{wxcheck}\\
\helpref{wxCHECK2\_MSG}{wxcheck2msg}\\
\helpref{wxCHECK2}{wxcheck2}\\
\wxheading{Include files}
-<wx/utils.h>
+<wx/filefn.h>
\wxheading{See also}
slashes with backslashes.
+\membersection{wxCHANGE\_UMASK}\label{wxchangeumask}
+
+\func{}{wxCHANGE\_UMASK}{\param{int }{mask}}
+
+Under Unix this macro changes the current process umask to the given value,
+unless it is equal to $-1$ in which case nothing is done, and restores it to
+the original value on scope exit. It works by declaring a variable which sets
+umask to \arg{mask} in its constructor and restores it in its destructor.
+
+Under other platforms this macro expands to nothing.
+
+
\membersection{::wxConcatFiles}\label{wxconcatfiles}
\func{bool}{wxConcatFiles}{\param{const wxString\& }{file1}, \param{const wxString\& }{file2},
// classes
// ----------------------------------------------------------------------------
+#ifdef __UNIX__
+
+// set umask to the given value in ctor and reset it to the old one in dtor
+class WXDLLIMPEXP_BASE wxUmaskChanger
+{
+public:
+ // change the umask to the given one if it is not -1: this allows to write
+ // the same code whether you really want to change umask or not, as is in
+ // wxFileConfig::Flush() for example
+ wxUmaskChanger(int umaskNew)
+ {
+ m_umaskOld = umaskNew == -1 ? -1 : umask((mode_t)umaskNew);
+ }
+
+ ~wxUmaskChanger()
+ {
+ if ( m_umaskOld != -1 )
+ umask((mode_t)m_umaskOld);
+ }
+
+private:
+ int m_umaskOld;
+};
+
+// this macro expands to an "anonymous" wxUmaskChanger object under Unix and
+// nothing elsewhere
+#define wxCHANGE_UMASK(m) wxUmaskChanger wxMAKE_UNIQUE_NAME(umaskChanger_)(m)
+
+#else // !__UNIX__
+
+#define wxCHANGE_UMASK(m)
+
+#endif // __UNIX__/!__UNIX__
+
+
// Path searching
class WXDLLIMPEXP_BASE wxPathList : public wxStringList
{
#include "wx/memtext.h"
#include "wx/config.h"
#include "wx/fileconf.h"
+#include "wx/filefn.h"
#if wxUSE_STREAMS
#include "wx/stream.h"
#include <stdlib.h>
#include <ctype.h>
-// headers needed for umask()
-#ifdef __UNIX__
- #include <sys/types.h>
- #include <sys/stat.h>
-#endif // __UNIX__
-
// ----------------------------------------------------------------------------
// macros
// ----------------------------------------------------------------------------
#if wxUSE_STREAMS
wxFileConfig::wxFileConfig(wxInputStream &inStream, wxMBConv& conv)
- : m_conv(conv)
+ : m_conv(conv)
{
// always local_file when this constructor is called (?)
SetStyle(GetStyle() | wxCONFIG_USE_LOCAL_FILE);
if ( LineListIsEmpty() || !m_pRootGroup->IsDirty() || !m_strLocalFile )
return true;
-#ifdef __UNIX__
// set the umask if needed
- mode_t umaskOld = 0;
- if ( m_umask != -1 )
- {
- umaskOld = umask((mode_t)m_umask);
- }
-#endif // __UNIX__
+ wxCHANGE_UMASK(m_umask);
wxTempFile file(m_strLocalFile);
}
#endif // __WXMAC__
-#ifdef __UNIX__
- // restore the old umask if we changed it
- if ( m_umask != -1 )
- {
- (void)umask(umaskOld);
- }
-#endif // __UNIX__
-
return ret;
}
return false;
}
-#ifdef __UNIX__
// reset the umask as we want to create the file with exactly the same
// permissions as the original one
- mode_t oldUmask = umask( 0 );
-#endif // __UNIX__
+ wxCHANGE_UMASK(0);
// create file2 with the same permissions than file1 and open it for
// writing
if ( !fileOut.Create(file2, overwrite, fbuf.st_mode & 0777) )
return false;
-#ifdef __UNIX__
- /// restore the old umask
- umask(oldUmask);
-#endif // __UNIX__
-
// copy contents of file1 to file2
char buf[4096];
size_t count;