//	utf-8

/*	Copyright  (c)	Günter Woigk   2001-2003
  					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 _file_utilities_h_
#define	_file_utilities_h_

#include "kio/kio.h"


#if !defined(_POSIX_SOURCE) && !defined(_SOLARIS)
	#define M_TIME(TS) ((TS).st_mtimespec.tv_sec)
	#define A_TIME(TS) ((TS).st_atimespec.tv_sec)
	#define C_TIME(TS) ((TS).st_ctimespec.tv_sec)
#else
	#define M_TIME(TS) ((TS).st_mtime)
	#define A_TIME(TS) ((TS).st_atime)
	#define C_TIME(TS) ((TS).st_ctime)
#endif


typedef enum
{
	s_none	= M4('n','o','n','e'),
	s_file	= M4('f','i','l','e'),
	s_dir	= M4('d','i','r',' '),
	s_tty	= M4('t','t','y',' '),
	s_pipe	= M4('p','i','p','e'),
	s_sock	= M4('s','o','c','k'),
	s_block	= M4('b','l','o','k'),
	s_link	= M4('l','i','n','k'),
	s_null	= M4('n','u','l','l'),
	s_unkn	= M4('u','n','k','n')
}
s_type;


extern	s_type	ClassifyFile	( mode_t mode );
extern	s_type	ClassifyFile	( int    fd   );
extern	s_type	ClassifyFile	( FILE*  file );
extern	s_type	ClassifyFile	( cstr   path, bool follow_symlink=1 );



extern	void	SetBlocking		( int fd, bool onoff );
extern	void	SetAsync		( int fd, bool onoff );
extern	void	SetBlocking		( FILE*, bool onoff );
extern	void	SetAsync		( FILE*, bool onoff );


extern	time_t	FileMTime		( cstr path, bool follow_symlink=1 );	// modification time
extern	time_t	FileATime		( cstr path, bool follow_symlink=1 );	// last access time
extern	time_t	FileCTime		( cstr path, bool follow_symlink=1 );	// last status change time



extern	off_t	FileLength		( cstr  path, bool follow_symlink=1 );
extern	off_t	FileLength		( int   fd   );
extern	off_t	FileLength		( FILE* file );


extern	cstr	FileNameFromPath	( cstr path );
extern	cstr	ExtensionFromPath	( cstr path );
extern	cstr	BasenameFromPath	( cstr path );
extern	cstr	DirectoryPathFromPath ( cstr path );

extern	cstr	FullPath		( cstr path, bool follow_symlink=1 );
extern	cstr	TempFileName	( cstr file, bool follow_symlink=1 );


extern	void	TerminalSize	( int tty, uint& rows, uint& cols );
extern	uint	TerminalRows	( int tty );
extern	uint	TerminalCols	( int tty );
extern	uint	TerminalWidth	( int tty );
extern	uint	TerminalHeight	( int tty );


#endif


