/* libsizzle/posix.h - posix/unix function bindings
 
  Copyright (C) 2000 Martin Grabmueller <mgrabmue@cs.tu-berlin.de>
 
  This is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2, or (at your option)
  any later version.
  
  This software 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.  See the
  GNU General Public License for more details.
  
  You should have received a copy of the GNU General Public License
  along with this package; see the file COPYING.  If not, write to the
  Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
  MA 02111-1307, USA.  */

#ifndef __SIZZLE_POSIX_H__
#define __SIZZLE_POSIX_H__

#if HAVE_CONFIG_H
# include <config.h>
#endif 

#if __SIZZLE_IMPORT__
# define SIZZLE_API __declspec (dllimport)
#elif __SIZZLE_EXPORT__ 
# define SIZZLE_API __declspec (dllexport)
#else
# define SIZZLE_API
#endif

#define _GNU_SOURCE
#include <sys/stat.h>
#include "node.h"

/* Discriminator and accessor macros for the directory stream type.  */
#define dir_stream_p(c)      (tagged_p(c) && \
                              tagged_type(c) == zzz_tagged_type_dir_stream)
#ifdef __MINGW32__
#define dir_stream_dir(c)    ((HANDLE) tagged_data0(c))
#else
#define dir_stream_dir(c)    ((DIR *) tagged_data0(c))
#endif
#define dir_stream_open_p(c) ((zzz_object_t) tagged_data1(c))

/* This is non-zero if the posix bindings are available.  */
SIZZLE_API extern int zzz_config_have_posix;

/* Tagged type identifier for the directory stream type.  */
SIZZLE_API extern zzz_object_t zzz_tagged_type_dir_stream;

/* Returns an exception object with the error message corresponding to
   the current value of the @code{errno} variable.  */
SIZZLE_API zzz_scm_t zzz_make_system_exception (void);

/* Initialize the Posix module.  Registers some tagged type (such as
   the directory stream type) and registers the Posix primitives.  */
SIZZLE_API result_t zzz_init_posix (void);

/* 
 * This little modification is necessary for the native Win32 compiler.
 * We do have these macros defined in the MinGW32 and Cygwin headers
 * but not within the native Win32 headers.
 */
#ifndef S_ISDIR
# define S_ISDIR(Mode) ((Mode) & S_IFDIR)
# define S_ISCHR(Mode) ((Mode) & S_IFCHR)
# define S_ISREG(Mode) ((Mode) & S_IFREG)
# define S_ISLNK(Mode) S_ISREG (Mode)
#endif /* not S_ISDIR */

#ifndef S_IRWXU
# define S_IRWXU 0000700 /* rwx, owner */
# define S_IRUSR 0000400 /* read permission, owner */
# define S_IWUSR 0000200 /* write permission, owner */
# define S_IXUSR 0000100 /* execute/search permission, owner */
#endif /* not S_IRWXU */

#endif /* not __SIZZLE_POSIX_H__ */
