/* general.h -- defines that everybody likes to use. */
-/* Copyright (C) 1993 Free Software Foundation, Inc.
+/* Copyright (C) 1993-2016 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
- Bash 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.
+ Bash 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 of the License, or
+ (at your option) any later version.
- Bash 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.
+ Bash 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 Bash; see the file COPYING. If not, write to the Free Software
- Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */
+ You should have received a copy of the GNU General Public License
+ along with Bash. If not, see <http://www.gnu.org/licenses/>.
+*/
#if !defined (_GENERAL_H_)
#define _GENERAL_H_
#include "stdc.h"
#include "bashtypes.h"
+#include "chartypes.h"
#if defined (HAVE_SYS_RESOURCE_H) && defined (RLIMTYPE)
# if defined (HAVE_SYS_TIME_H)
# include <strings.h>
#endif /* !HAVE_STRING_H */
-/* Generic pointer type. */
-#if defined (__STDC__)
-# define PTR_T void *
-#else
-# define PTR_T char *
+#if defined (HAVE_LIMITS_H)
+# include <limits.h>
#endif
+#include "xmalloc.h"
+
/* NULL pointer type. */
#if !defined (NULL)
# if defined (__STDC__)
# endif /* !__STDC__ */
#endif /* !NULL */
-#define pointer_to_int(x) (int)((long)(x))
-
-extern char *xmalloc (), *xrealloc ();
+/* Hardly used anymore */
+#define pointer_to_int(x) (int)((char *)x - (char *)0)
#if defined (alpha) && defined (__GNUC__) && !defined (strchr) && !defined (__STDC__)
extern char *strchr (), *strrchr ();
#endif
-#if !defined (strcpy)
-extern char *strcpy ();
+#if !defined (strcpy) && (defined (HAVE_DECL_STRCPY) && !HAVE_DECL_STRCPY)
+extern char *strcpy __P((char *, const char *));
#endif
#if !defined (savestring)
#endif
#ifndef member
-# define member(c, s) ((c) ? ((char *)strchr ((s), (c)) != (char *)NULL) : 0)
+# define member(c, s) ((c) ? ((char *)mbschr ((s), (c)) != (char *)NULL) : 0)
#endif
#ifndef whitespace
#define whitespace(c) (((c) == ' ') || ((c) == '\t'))
#endif
-#ifndef digit
-#define digit(c) (isdigit(c))
+#ifndef CHAR_MAX
+# ifdef __CHAR_UNSIGNED__
+# define CHAR_MAX 0xff
+# else
+# define CHAR_MAX 0x7f
+# endif
#endif
-#ifndef isletter
-#define isletter(c) (isalpha(c))
+#ifndef CHAR_BIT
+# define CHAR_BIT 8
#endif
-#ifndef digit_value
-#define digit_value(c) ((c) - '0')
+/* Nonzero if the integer type T is signed. */
+#define TYPE_SIGNED(t) (! ((t) 0 < (t) -1))
+
+/* The width in bits of the integer type or expression T.
+ Padding bits are not supported; this is checked at compile-time below. */
+#define TYPE_WIDTH(t) (sizeof (t) * CHAR_BIT)
+
+/* Bound on length of the string representing an unsigned integer
+ value representable in B bits. log10 (2.0) < 146/485. The
+ smallest value of B where this bound is not tight is 2621. */
+#define INT_BITS_STRLEN_BOUND(b) (((b) * 146 + 484) / 485)
+
+/* Bound on length of the string representing an integer value of type T.
+ Subtract one for the sign bit if T is signed;
+ 302 / 1000 is log10 (2) rounded up;
+ add one for integer division truncation;
+ add one more for a minus sign if t is signed. */
+#define INT_STRLEN_BOUND(t) \
+ ((TYPE_WIDTH (t) - TYPE_SIGNED (t)) * 302 / 1000 \
+ + 1 + TYPE_SIGNED (t))
+
+/* Updated version adapted from gnulib/intprops.h, not used right now.
+ Changes the approximation of log10(2) from 302/1000 to 146/485. */
+#if 0
+#define INT_STRLEN_BOUND(t) \
+ (INT_BITS_STRLEN_BOUND (TYPE_WIDTH (t) - TYPE_SIGNED (t)) + TYPE_SIGNED(t))
#endif
-#ifndef ISOCTAL
-#define ISOCTAL(c) ((c) >= '0' && (c) <= '7')
-#endif
+/* Bound on buffer size needed to represent an integer type or expression T,
+ including the terminating null. */
+#define INT_BUFSIZE_BOUND(t) (INT_STRLEN_BOUND (t) + 1)
/* Define exactly what a legal shell identifier consists of. */
-#define legal_variable_starter(c) (isletter(c) || (c == '_'))
-#define legal_variable_char(c) (isletter (c) || digit (c) || c == '_')
+#define legal_variable_starter(c) (ISALPHA(c) || (c == '_'))
+#define legal_variable_char(c) (ISALNUM(c) || c == '_')
/* Definitions used in subst.c and by the `read' builtin for field
splitting. */
int token;
} STRING_INT_ALIST;
-/* A macro to avoid making an uneccessary function call. */
+/* A macro to avoid making an unnecessary function call. */
#define REVERSE_LIST(list, type) \
- ((list && list->next) ? (type)reverse_list ((GENERIC_LIST *)list) \
+ ((list && list->next) ? (type)list_reverse ((GENERIC_LIST *)list) \
: (type)(list))
#if __GNUC__ > 1
-# define FASTCOPY(s, d, n) __builtin_memcpy (d, s, n)
+# define FASTCOPY(s, d, n) __builtin_memcpy ((d), (s), (n))
#else /* !__GNUC__ */
# if !defined (HAVE_BCOPY)
# if !defined (HAVE_MEMMOVE)
-# define FASTCOPY(s, d, n) memcpy (d, s, n)
+# define FASTCOPY(s, d, n) memcpy ((d), (s), (n))
# else
-# define FASTCOPY(s, d, n) memmove (d, s, n)
+# define FASTCOPY(s, d, n) memmove ((d), (s), (n))
# endif /* !HAVE_MEMMOVE */
# else /* HAVE_BCOPY */
-# define FASTCOPY(s, d, n) bcopy (s, d, n)
+# define FASTCOPY(s, d, n) bcopy ((s), (d), (n))
# endif /* HAVE_BCOPY */
#endif /* !__GNUC__ */
# define _FUNCTION_DEF
typedef int Function ();
typedef void VFunction ();
-typedef char *CPFunction ();
-typedef char **CPPFunction ();
+typedef char *CPFunction (); /* no longer used */
+typedef char **CPPFunction (); /* no longer used */
#endif /* _FUNCTION_DEF */
+#ifndef SH_FUNCTION_TYPEDEF
+# define SH_FUNCTION_TYPEDEF
+
+/* Shell function typedefs with prototypes */
+/* `Generic' function pointer typedefs */
+
+typedef int sh_intfunc_t __P((int));
+typedef int sh_ivoidfunc_t __P((void));
+typedef int sh_icpfunc_t __P((char *));
+typedef int sh_icppfunc_t __P((char **));
+typedef int sh_iptrfunc_t __P((PTR_T));
+
+typedef void sh_voidfunc_t __P((void));
+typedef void sh_vintfunc_t __P((int));
+typedef void sh_vcpfunc_t __P((char *));
+typedef void sh_vcppfunc_t __P((char **));
+typedef void sh_vptrfunc_t __P((PTR_T));
+
+typedef int sh_wdesc_func_t __P((WORD_DESC *));
+typedef int sh_wlist_func_t __P((WORD_LIST *));
+
+typedef int sh_glist_func_t __P((GENERIC_LIST *));
+
+typedef char *sh_string_func_t __P((char *)); /* like savestring, et al. */
+
+typedef int sh_msg_func_t __P((const char *, ...)); /* printf(3)-like */
+typedef void sh_vmsg_func_t __P((const char *, ...)); /* printf(3)-like */
+
+/* Specific function pointer typedefs. Most of these could be done
+ with #defines. */
+typedef void sh_sv_func_t __P((char *)); /* sh_vcpfunc_t */
+typedef void sh_free_func_t __P((PTR_T)); /* sh_vptrfunc_t */
+typedef void sh_resetsig_func_t __P((int)); /* sh_vintfunc_t */
+
+typedef int sh_ignore_func_t __P((const char *)); /* sh_icpfunc_t */
+
+typedef int sh_assign_func_t __P((const char *));
+typedef int sh_wassign_func_t __P((WORD_DESC *, int));
+
+typedef int sh_load_func_t __P((char *));
+typedef void sh_unload_func_t __P((char *));
+
+typedef int sh_builtin_func_t __P((WORD_LIST *)); /* sh_wlist_func_t */
+
+#endif /* SH_FUNCTION_TYPEDEF */
+
#define NOW ((time_t) time ((time_t *) 0))
/* Some defines for calling file status functions. */
#define FS_EXEC_ONLY 0x8
#define FS_DIRECTORY 0x10
#define FS_NODIRS 0x20
+#define FS_READABLE 0x40
+
+/* Default maximum for move_to_high_fd */
+#define HIGH_FD_MAX 256
+
+/* The type of function passed as the fourth argument to qsort(3). */
+#ifdef __STDC__
+typedef int QSFUNC (const void *, const void *);
+#else
+typedef int QSFUNC ();
+#endif
/* Some useful definitions for Unix pathnames. Argument convention:
x == string, c == character */
# define ABSPATH(x) ((x)[0] == '/')
# define RELPATH(x) ((x)[0] != '/')
#else /* __CYGWIN__ */
-# define ABSPATH(x) (((x)[0] && isalpha((x)[0]) && (x)[1] == ':' && (x)[2] == '/') || (x)[0] == '/')
-# define RELPATH(x) (!(x)[0] || ((x)[1] != ':' && (x)[0] != '/'))
+# define ABSPATH(x) (((x)[0] && ISALPHA((unsigned char)(x)[0]) && (x)[1] == ':') || ISDIRSEP((x)[0]))
+# define RELPATH(x) (ABSPATH(x) == 0)
#endif /* __CYGWIN__ */
#define ROOTEDPATH(x) (ABSPATH(x))
#define DIRSEP '/'
-#define ISDIRSEP(c) ((c) == '/')
+#if !defined (__CYGWIN__)
+# define ISDIRSEP(c) ((c) == '/')
+#else
+# define ISDIRSEP(c) ((c) == '/' || (c) == '\\')
+#endif /* __CYGWIN__ */
#define PATHSEP(c) (ISDIRSEP(c) || (c) == 0)
+#if 0
/* Declarations for functions defined in xmalloc.c */
-extern char *xmalloc __P((size_t));
-extern char *xrealloc __P((void *, size_t));
+extern PTR_T xmalloc __P((size_t));
+extern PTR_T xrealloc __P((void *, size_t));
extern void xfree __P((void *));
+#endif
/* Declarations for functions defined in general.c */
extern void posix_initialize __P((int));
+extern int num_posix_options __P((void));
+extern char *get_posix_options __P((char *));
+extern void set_posix_options __P((const char *));
+
#if defined (RLIMTYPE)
extern RLIMTYPE string_to_rlimtype __P((char *));
extern void print_rlimtype __P((RLIMTYPE, int));
#endif
-extern int all_digits __P((char *));
-extern int legal_number __P((char *, long *));
-extern int legal_identifier __P((char *));
+extern int all_digits __P((const char *));
+extern int legal_number __P((const char *, intmax_t *));
+extern int legal_identifier __P((const char *));
+extern int importable_function_name __P((const char *, size_t));
+extern int exportable_function_name __P((const char *));
extern int check_identifier __P((WORD_DESC *, int));
+extern int valid_nameref_value __P((const char *, int));
+extern int check_selfref __P((const char *, char *, int));
+extern int legal_alias_name __P((const char *, int));
+extern int line_isblank __P((const char *));
+extern int assignment __P((const char *, int));
extern int sh_unset_nodelay_mode __P((int));
+extern int sh_setclexec __P((int));
+extern int sh_validfd __P((int));
+extern int fd_ispipe __P((int));
extern void check_dev_tty __P((void));
-extern int same_file (); /* too many problems with prototype */
extern int move_to_high_fd __P((int, int, int));
-extern int check_binary_file __P((unsigned char *, int));
+extern int check_binary_file __P((const char *, int));
+
+#ifdef _POSIXSTAT_H_
+extern int same_file __P((const char *, const char *, struct stat *, struct stat *));
+#endif
+
+extern int sh_openpipe __P((int *));
+extern int sh_closepipe __P((int *));
-extern char *make_absolute __P((char *, char *));
-extern int absolute_pathname __P((char *));
-extern int absolute_program __P((char *));
+extern int file_exists __P((const char *));
+extern int file_isdir __P((const char *));
+extern int file_iswdir __P((const char *));
+extern int path_dot_or_dotdot __P((const char *));
+extern int absolute_pathname __P((const char *));
+extern int absolute_program __P((const char *));
+
+extern char *make_absolute __P((const char *, const char *));
extern char *base_pathname __P((char *));
extern char *full_pathname __P((char *));
extern char *polite_directory_format __P((char *));
+extern char *trim_pathname __P((char *, int));
+extern char *printable_filename __P((char *, int));
extern char *extract_colon_unit __P((char *, int *));
extern void tilde_initialize __P((void));
-extern char *bash_tilde_expand __P((char *));
+extern char *bash_tilde_find_word __P((const char *, int, int *));
+extern char *bash_tilde_expand __P((const char *, int));
extern int group_member __P((gid_t));
extern char **get_group_list __P((int *));
extern int *get_group_array __P((int *));
+extern char *conf_standard_path __P((void));
+extern int default_columns __P((void));
+
#endif /* _GENERAL_H_ */