121308Sache/* posixstat.h -- Posix stat(2) definitions for systems that
221308Sache   don't have them. */
321308Sache
421308Sache/* Copyright (C) 1987,1991 Free Software Foundation, Inc.
521308Sache
621308Sache   This file is part of GNU Bash, the Bourne Again SHell.
721308Sache
821308Sache   Bash is free software; you can redistribute it and/or modify it
921308Sache   under the terms of the GNU General Public License as published by
1058310Sache   the Free Software Foundation; either version 2, or (at your option)
1121308Sache   any later version.
1221308Sache
1321308Sache   Bash is distributed in the hope that it will be useful, but WITHOUT
1421308Sache   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
1521308Sache   or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
1621308Sache   License for more details.
1721308Sache
1821308Sache   You should have received a copy of the GNU General Public License
1921308Sache   along with Bash; see the file COPYING.  If not, write to the Free
2058310Sache   Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */
2121308Sache
2221308Sache/* This file should be included instead of <sys/stat.h>.
2321308Sache   It relies on the local sys/stat.h to work though. */
2421308Sache#if !defined (_POSIXSTAT_H_)
2521308Sache#define _POSIXSTAT_H_
2621308Sache
2721308Sache#include <sys/stat.h>
2821308Sache
2921308Sache#if defined (STAT_MACROS_BROKEN)
3021308Sache#  undef S_ISBLK
3121308Sache#  undef S_ISCHR
3221308Sache#  undef S_ISDIR
3321308Sache#  undef S_ISFIFO
3421308Sache#  undef S_ISREG
3521308Sache#  undef S_ISLNK
3621308Sache#endif /* STAT_MACROS_BROKEN */
3721308Sache
3821308Sache/* These are guaranteed to work only on isc386 */
3921308Sache#if !defined (S_IFDIR) && !defined (S_ISDIR)
4021308Sache#  define S_IFDIR 0040000
4121308Sache#endif /* !S_IFDIR && !S_ISDIR */
4221308Sache#if !defined (S_IFMT)
4321308Sache#  define S_IFMT  0170000
4421308Sache#endif /* !S_IFMT */
4521308Sache
4621308Sache/* Posix 1003.1 5.6.1.1 <sys/stat.h> file types */
4721308Sache
4821308Sache/* Some Posix-wannabe systems define _S_IF* macros instead of S_IF*, but
4921308Sache   do not provide the S_IS* macros that Posix requires. */
5021308Sache
5121308Sache#if defined (_S_IFMT) && !defined (S_IFMT)
5221308Sache#define S_IFMT _S_IFMT
5321308Sache#endif
5421308Sache#if defined (_S_IFIFO) && !defined (S_IFIFO)
5521308Sache#define S_IFIFO _S_IFIFO
5621308Sache#endif
5721308Sache#if defined (_S_IFCHR) && !defined (S_IFCHR)
5821308Sache#define S_IFCHR _S_IFCHR
5921308Sache#endif
6021308Sache#if defined (_S_IFDIR) && !defined (S_IFDIR)
6121308Sache#define S_IFDIR _S_IFDIR
6221308Sache#endif
6321308Sache#if defined (_S_IFBLK) && !defined (S_IFBLK)
6421308Sache#define S_IFBLK _S_IFBLK
6521308Sache#endif
6621308Sache#if defined (_S_IFREG) && !defined (S_IFREG)
6721308Sache#define S_IFREG _S_IFREG
6821308Sache#endif
6921308Sache#if defined (_S_IFLNK) && !defined (S_IFLNK)
7021308Sache#define S_IFLNK _S_IFLNK
7121308Sache#endif
7221308Sache#if defined (_S_IFSOCK) && !defined (S_IFSOCK)
7321308Sache#define S_IFSOCK _S_IFSOCK
7421308Sache#endif
7521308Sache
7621308Sache/* Test for each symbol individually and define the ones necessary (some
7721308Sache   systems claiming Posix compatibility define some but not all). */
7821308Sache
7921308Sache#if defined (S_IFBLK) && !defined (S_ISBLK)
8021308Sache#define	S_ISBLK(m)	(((m)&S_IFMT) == S_IFBLK)	/* block device */
8121308Sache#endif
8221308Sache
8321308Sache#if defined (S_IFCHR) && !defined (S_ISCHR)
8421308Sache#define	S_ISCHR(m)	(((m)&S_IFMT) == S_IFCHR)	/* character device */
8521308Sache#endif
8621308Sache
8721308Sache#if defined (S_IFDIR) && !defined (S_ISDIR)
8821308Sache#define	S_ISDIR(m)	(((m)&S_IFMT) == S_IFDIR)	/* directory */
8921308Sache#endif
9021308Sache
9121308Sache#if defined (S_IFREG) && !defined (S_ISREG)
9221308Sache#define	S_ISREG(m)	(((m)&S_IFMT) == S_IFREG)	/* file */
9321308Sache#endif
9421308Sache
9521308Sache#if defined (S_IFIFO) && !defined (S_ISFIFO)
9621308Sache#define	S_ISFIFO(m)	(((m)&S_IFMT) == S_IFIFO)	/* fifo - named pipe */
9721308Sache#endif
9821308Sache
9921308Sache#if defined (S_IFLNK) && !defined (S_ISLNK)
10021308Sache#define	S_ISLNK(m)	(((m)&S_IFMT) == S_IFLNK)	/* symbolic link */
10121308Sache#endif
10221308Sache
10321308Sache#if defined (S_IFSOCK) && !defined (S_ISSOCK)
10421308Sache#define	S_ISSOCK(m)	(((m)&S_IFMT) == S_IFSOCK)	/* socket */
10521308Sache#endif
10621308Sache
10721308Sache/*
10821308Sache * POSIX 1003.1 5.6.1.2 <sys/stat.h> File Modes
10921308Sache */
11021308Sache
11121308Sache#if !defined (S_IRWXU)
11221308Sache#  if !defined (S_IREAD)
11321308Sache#    define S_IREAD	00400
11421308Sache#    define S_IWRITE	00200
11521308Sache#    define S_IEXEC	00100
11621308Sache#  endif /* S_IREAD */
11721308Sache
11821308Sache#  if !defined (S_IRUSR)
11921308Sache#    define S_IRUSR	S_IREAD			/* read, owner */
12021308Sache#    define S_IWUSR	S_IWRITE		/* write, owner */
12121308Sache#    define S_IXUSR	S_IEXEC			/* execute, owner */
12221308Sache
12321308Sache#    define S_IRGRP	(S_IREAD  >> 3)		/* read, group */
12421308Sache#    define S_IWGRP	(S_IWRITE >> 3)		/* write, group */
12521308Sache#    define S_IXGRP	(S_IEXEC  >> 3)		/* execute, group */
12621308Sache
12721308Sache#    define S_IROTH	(S_IREAD  >> 6)		/* read, other */
12821308Sache#    define S_IWOTH	(S_IWRITE >> 6)		/* write, other */
12921308Sache#    define S_IXOTH	(S_IEXEC  >> 6)		/* execute, other */
13021308Sache#  endif /* !S_IRUSR */
13121308Sache
13221308Sache#  define S_IRWXU	(S_IRUSR | S_IWUSR | S_IXUSR)
13321308Sache#  define S_IRWXG	(S_IRGRP | S_IWGRP | S_IXGRP)
13421308Sache#  define S_IRWXO	(S_IROTH | S_IWOTH | S_IXOTH)
13521308Sache#endif /* !S_IRWXU */
13621308Sache
13721308Sache/* These are non-standard, but are used in builtins.c$symbolic_umask() */
13821308Sache#define S_IRUGO		(S_IRUSR | S_IRGRP | S_IROTH)
13921308Sache#define S_IWUGO		(S_IWUSR | S_IWGRP | S_IWOTH)
14021308Sache#define S_IXUGO		(S_IXUSR | S_IXGRP | S_IXOTH)
14121308Sache
14221308Sache#endif /* _POSIXSTAT_H_ */
143