1/* Shared definitions for GNU shar utilities.
2   Copyright (C) 1994, 1995 Free Software Foundation, Inc.
3
4   This program is free software; you can redistribute it and/or modify
5   it under the terms of the GNU General Public License as published by
6   the Free Software Foundation; either version 2, or (at your option)
7   any later version.
8
9   This program is distributed in the hope that it will be useful,
10   but WITHOUT ANY WARRANTY; without even the implied warranty of
11   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12   GNU General Public License for more details.
13
14   You should have received a copy of the GNU General Public License
15   along with this program; if not, write to the Free Software Foundation,
16   Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17*/
18
19#ifdef HAVE_CONFIG_H
20# include <config.h>
21#endif
22
23/* AIX requires this to be the first thing in the file.  */
24#if defined (_AIX) && !defined (__GNUC__)
25 #pragma alloca
26#endif
27
28#ifdef	__GNUC__
29# undef	alloca
30# define alloca(n) __builtin_alloca (n)
31#else
32# ifdef HAVE_ALLOCA_H
33#  include <alloca.h>
34# else
35#  ifndef _AIX
36extern char *alloca ();
37#  endif
38# endif
39#endif
40
41#if __STDC__
42# define voidstar void *
43#else
44# define voidstar char *
45#endif
46
47#ifdef STDC_HEADERS
48# include <stdlib.h>
49#else
50char *getenv ();
51#endif
52
53/* Some systems do not define EXIT_*, even with STDC_HEADERS.  */
54#ifndef EXIT_SUCCESS
55# define EXIT_SUCCESS 0
56#endif
57#ifndef EXIT_FAILURE
58# define EXIT_FAILURE 1
59#endif
60
61#if HAVE_STRING_H
62# include <string.h>
63# if !STDC_HEADERS && HAVE_MEMORY_H
64#  include <memory.h>
65# endif
66#else
67# include <strings.h>
68#endif
69#if !HAVE_MEMCPY
70# ifndef memcpy
71#  define memcpy(D, S, N) bcopy (S, D, N)
72# endif
73#endif
74#if !HAVE_STRCHR
75# ifndef strchr
76#  define strchr index
77# endif
78#endif
79
80/* Other header files.  */
81
82#include <stdio.h>
83
84#include <errno.h>
85#ifndef errno
86extern int errno;
87#endif
88
89#include <sys/types.h>
90
91#ifdef HAVE_SYS_WAIT_H
92# include <sys/wait.h>
93#endif
94
95/* Get definitions for the file permission bits.  */
96
97#include <sys/stat.h>
98
99#ifdef STAT_MACROS_BROKEN
100# undef S_ISDIR
101# undef S_ISREG
102#endif
103
104#ifndef S_IFMT
105# define S_IFMT 0170000
106#endif
107#if !defined(S_ISDIR) && defined(S_IFDIR)
108# define S_ISDIR(Mode) (((Mode) & S_IFMT) == S_IFDIR)
109#endif
110#if !defined(S_ISREG) && defined(S_IFREG)
111# define S_ISREG(Mode) (((Mode) & S_IFMT) == S_IFREG)
112#endif
113
114#ifndef S_IRWXU
115# define S_IRWXU 0700
116#endif
117#ifndef S_IRUSR
118# define S_IRUSR 0400
119#endif
120#ifndef S_IWUSR
121# define S_IWUSR 0200
122#endif
123#ifndef S_IXUSR
124# define S_IXUSR 0100
125#endif
126
127#ifndef S_IRWXG
128# define S_IRWXG 0070
129#endif
130#ifndef S_IRGRP
131# define S_IRGRP 0040
132#endif
133#ifndef S_IWGRP
134# define S_IWGRP 0020
135#endif
136#ifndef S_IXGRP
137# define S_IXGRP 0010
138#endif
139
140#ifndef S_IRWXO
141# define S_IRWXO 0007
142#endif
143#ifndef S_IROTH
144# define S_IROTH 0004
145#endif
146#ifndef S_IWOTH
147# define S_IWOTH 0002
148#endif
149#ifndef S_IXOTH
150# define S_IXOTH 0001
151#endif
152
153/* System functions.  Even if we usually avoid declaring them, we cannot
154   avoid them all.  */
155
156#ifdef HAVE_UNISTD_H
157# include <unistd.h>
158#endif
159
160FILE *fdopen ();
161long ftell ();
162FILE *popen ();
163
164/* GNU small library functions.  */
165
166#ifndef __P
167# if PROTOTYPES
168#  define __P(Args) Args
169# else
170#  define __P(Args) ()
171# endif
172#endif
173
174#if HAVE_LOCALE_H
175# include <locale.h>
176#else
177# define setlocale(Category, Locale)
178#endif
179
180//#include <libintl.h>
181
182#define _(Str) gettext (Str)
183#ifdef gettext_noop
184# define N_(Str) gettext_noop (Str)
185#else
186# define N_(Str) (Str)
187#endif
188
189
190#if HAVE_BASENAME
191char *basename ();
192#else
193char *basename __P ((const char *));
194#endif
195void error __P ((int, int, const char *, ...));
196char *xgetcwd __P ((void));
197voidstar xmalloc __P ((size_t));
198voidstar xrealloc __P ((voidstar, size_t));
199char *xstrdup __P ((const char *));
200char *stpcpy __P ((char *, const char *));
201
202/* Global functions of the shar package.  */
203
204void copy_file_encoded __P ((FILE *, FILE *));
205char *get_submitter __P ((char *));
206
207/* Debugging the memory allocator.  */
208
209#if WITH_DMALLOC
210# define MALLOC_FUNC_CHECK
211# include <dmalloc.h>
212#endif
213