// utf-8

/*	Copyright  (c)	Günter Woigk  2002-2004
  					mailto:kio@little-bat.de

	This file is free software

 	This program is distributed in the hope that it will be useful,
 	but WITHOUT ANY WARRANTY; without even the implied warranty of
 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  

 	Permission to use, copy, modify, distribute, and sell this software and
 	its documentation for any purpose is hereby granted without fee, provided
 	that the above copyright notice appear in all copies and that both that
 	copyright notice and this permission notice appear in supporting
 	documentation, and that the name of the copyright holder not be used
 	in advertising or publicity pertaining to distribution of the software
 	without specific, written prior permission. The copyright holder makes no
 	representations about the suitability of this software for any purpose.
 	It is provided "as is" without express or implied warranty.

 	THE COPYRIGHT HOLDER DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
 	INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
 	EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY SPECIAL, INDIRECT OR
 	CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
 	DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
 	TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 	PERFORMANCE OF THIS SOFTWARE.
*/


#ifndef _systemio_h_
#define	_systemio_h_

#include "kio/kio.h"
#include "ustring/sstring.h"
#include "unix/file_utilities.h"
#include "unix/os_utilities.h"
#include "Stream.h"



extern ulong	VolumeFlags			( cstr path );
extern double	VolumeFree			( cstr path );

extern cstr		FullPath			( cString& path, bool follow_symlink );

extern void		ChangeWorkingDir	( cString& path );
extern String	WorkingDirString	( );

extern s_type	ClassifyFile		( cString& path, bool follow_symlink=1 );
inline bool		NodeExists			( cString& path, bool follow_symlink=1 )	{ return ClassifyFile(path,follow_symlink)!=s_none; }
inline bool		IsFile				( cString& path, bool follow_symlink=1 )	{ return ClassifyFile(path,follow_symlink)==s_file; }
inline bool		IsDir				( cString& path, bool follow_symlink=1 )	{ return ClassifyFile(path,follow_symlink)==s_dir;  }
inline bool		IsLink				( cString& path )							{ return ClassifyFile(path,no            )==s_link; }

extern void		CreateFile			( cString& path, cString& data, cstr mode /*n/w/a*/ );
inline void		NewFile				( cString& path, cString& data )			{ CreateFile(path,data,"new"); }
inline void		WriteFile			( cString& path, cString& data )			{ CreateFile(path,data,"write"); }
inline void		AppendFile			( cString& path, cString& data )			{ CreateFile(path,data,"append"); }

extern void		CreateDir			( cString& path, cstr mode /*n/w*/ );
inline void		NewDir				( cString& path )							{ CreateDir(path,"new"); }
inline void		WriteDir			( cString& path )							{ CreateDir(path,"write"); }

extern void		CreateLink			( cString& path, cString& dest, cstr mode /*n/w*/ );
inline void		NewLink				( cString& path, cString& dest )			{ CreateLink(path,dest,"new"); }
inline void		WriteLink			( cString& path, cString& dest )			{ CreateLink(path,dest,"write"); }

extern void		ReadNode			( cString& path, Var& v, bool follow_symlink );
extern void		ReadFile			( cString& path, String& data );
extern void		ReadDir				( cString& path, Var& v );
extern void		ReadLink			( cString& path, String& data );

extern void		RenameNode			( cString& oldname, cString& newname, bool overwrite, bool follow_symlink, s_type typ=s_any );
inline void		RenameFile			( cString& oldname, cString& newname, bool overwrite=no );
inline void		RenameDir			( cString& oldname, cString& newname, bool overwrite=no );
inline void		RenameLink			( cString& oldname, cString& newname, bool overwrite=no );

extern void		DeleteNode			( cString& path, bool follow_symlink, s_type typ=s_any );	// file, dir, link, pipe, sock, etc.
inline void		DeleteFile			( cString& path );
inline void		DeleteDir			( cString& path );
inline void		DeleteLink			( cString& path );

extern void		SwapFiles			( cString& path, cString& path2 );
extern void		GetVolumeInfo		( Var& v );




inline void RenameFile ( cString& oldname, cString& newname, bool overwrite )
{	RenameNode( oldname, newname, overwrite, yes, s_file );	}

inline void RenameDir ( cString& oldname, cString& newname, bool overwrite )
{	RenameNode( oldname, newname, overwrite, yes, s_dir );	}

inline void RenameLink ( cString& oldname, cString& newname, bool overwrite )
{	RenameNode( oldname, newname, overwrite, no, s_link );	}


inline void DeleteFile ( cString& path )	{ DeleteNode( path, yes, s_file ); }
inline void DeleteDir ( cString& path )		{ DeleteNode( path, yes, s_dir ); }
inline void DeleteLink ( cString& path )	{ DeleteNode( path, no, s_link ); }


#endif






