/* Shared definitions for GNU shar utilities.

   Copyright (C) 1994-2015 Free Software Foundation, Inc.

   This program 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 3, or (at your option)
   any later version.

   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.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, see <http://gnu.org/licenses/gpl.html>
*/

#ifndef SHARUTILS_SYSTEM_H_GUARD
#define SHARUTILS_SYSTEM_H_GUARD 1

#ifndef HAVE_CONFIG_H
choke me -- I need config.h
#endif
#include "config.h"

#ifndef USE_UNLOCKED_IO
#  define USE_UNLOCKED_IO 1
#endif

#include <sys/types.h>
#include <sys/stat.h>

#include <errno.h>
#include <error.h>
#include <stdio.h>
#include <stdlib.h>

#if HAVE_INTTYPES_H
# include <inttypes.h>
#endif

#ifndef HAVE_INTMAX_T
#define HAVE_INTMAX_T
typedef long intmax_t;
#endif

#ifdef HAVE_STDBOOL_H
#include <stdbool.h>
#else
typedef enum {false = 0, true = 1} bool;
#endif

#if !HAVE_DECL_STRTOIMAX && !defined strtoimax
intmax_t strtoimax (const char *nptr, char **endptr, int base);
#endif

#if HAVE_STRING_H
# include <string.h>
# if !STDC_HEADERS && HAVE_MEMORY_H
#  include <memory.h>
# endif
#else
# include <strings.h>
#endif

#ifdef HAVE_SYS_WAIT_H
# include <sys/wait.h>
#endif

/* System functions.  Even if we usually avoid declaring them, we cannot
   avoid them all.  */

#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif

FILE *fdopen (int fd, const char *mode);
FILE *popen (const char *command, const char *type);

/* Global functions of the shar package.  */

void copy_file_encoded (FILE *, FILE *);
char *get_submitter (char *);

/* Debugging the memory allocator.  */

#if WITH_DMALLOC
# define MALLOC_FUNC_CHECK
# include <dmalloc.h>
#endif

/* Some gcc specials.  */
#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 6)
# define ATTRIBUTE(list) __attribute__ (list)
#else
# define ATTRIBUTE(list)
#endif

#if __CYGWIN__
# include <fcntl.h>
# include <io.h> /* for setmode */
#endif
#endif // SHARUTILS_SYSTEM_H_GUARD
