#ifndef _DW_FILES_H
#define _DW_FILES_H

/*--------------------------------------------------------------------------
 *  Copyright (c) 2001-2004 Igor Daniloff. 
 *	All rights reserved.
 *
 * By using this file, you agree to the terms and conditions set
 * forth in the LICENSE file which can be found at this directory.
 *------------------------------------------------------------------------*/

/* $Id: dw_files.h,v 1.30.2.2 2009/04/03 15:04:05 akorkov Exp $ */

#if defined(__UNIX_DW)
#include <unistd.h>
#endif /* UNIX */
#include "dwc_type.h"
#include "dwc_macro.h"
#include "dw_options.h"
#if !defined(DW_SAMBA)                                          
#include "dw_mail.h"
#endif /* not SAMBA */

extern dwc_path_t   dw_basename         ( dwc_path_t            path );
extern dwc_path_t   dw_normalize_path   ( dwc_const_path_t            fname,
                                          dwc_bool_t            need_expand,
                                          dwc_path_t            prefix,
                                          dwc_count_t           strips );
//#if !defined(DW_SAMBA)                                          
#if defined(DW_QMAIL) || defined(DW_PIPE)
extern dwc_path_t   dw_stdin_to_tmpfile ( const dwc_tmpfiles_t *tmpl );
#endif /* QMAIL || PIPE */
extern dwc_fd_t     dw_open_tmpfile     ( const dwc_tmpfiles_t *tmpl, 
                                          dwc_path_t           *pname );
/* startup checks */
extern dwc_syserr_t dw_check_read       ( const dwc_path_t      fname );
#if defined(DW_HAVE_SPOOL)
extern dwc_syserr_t dw_check_spool      ( const dwc_tmpfiles_t *tmpl,
                                          const dwc_bool_t      local,
                                          dwc_path_t            prefix,
                                          dwc_count_t           strips );
extern dwc_syserr_t dw_check_quarantine ( const dwc_tmpfiles_t *srctmpl, 
                                          const dwc_tmpfiles_t *dsttmpl, 
                                          const dwc_bool_t      local,
                                          dwc_path_t            prefix,
                                          dwc_count_t           strips );
#endif /* HAVE_SPOOL */                                          
/* work routines */                                         
extern dwc_path_t   dw_quarantine_file  ( const dwc_tmpfiles_t *tmpl, 
                                          const dwc_const_path_t fname,
                                          const dwc_bool_t      moving );
extern dwc_bool_t   dw_write_file_to_fd ( const dwc_path_t      from_name,
                                          const dwc_off_t       start,
                                          const dwc_off_t       length, 
                                          dwc_fd_t              to_fd );
extern dwc_bool_t   dw_write_fd_to_fd   ( dwc_fd_t              from_fd, 
                                          dwc_fd_t              to_fd, 
                                          dwc_length_t          length );
extern dwc_bool_t   dw_write_file_to_buf( const dwc_path_t      from_name,
                                          const dwc_off_t       start,
                                          const dwc_membuf_t    buf, 
                                          dwc_length_t          buf_len );
extern dwc_bool_t   dw_write_buf        ( dwc_fd_t              to_fd, 
                                          const dwc_membuf_t    buf, 
                                          dwc_length_t          buf_len );
extern dwc_bool_t   dw_read_buf         ( dwc_fd_t              from_fd, 
                                          dwc_membuf_t          buf, 
                                          dwc_length_t          buf_len );
extern dwc_bool_t   dw_write_str        ( dwc_fd_t              to_fd,
                                          const dwc_string_t    str );


extern dwc_syserr_t dw_copy_file        ( const dwc_const_path_t oldpath, 
                                          const dwc_const_path_t newpath, 
                                          const dwc_mode_t nmode );
extern dwc_syserr_t dw_move_file        ( const dwc_const_path_t oldpath, 
                                          const dwc_const_path_t newpath, 
                                          const dwc_mode_t nmode );

//#endif /* not SAMBA */

#endif /* _DWC_FILES_H */
