[net.sources] how to determine your operating environment

arnold@gatech.UUCP (Mister Snuffle-upagus) (10/23/84)

# I have placed an exit after the archive, so don't worry about the .signature
#! /bin/sh
echo 'extracting --- README' 1>&2
cat > README << 'End of README'
README:

These two files are designed to do two things:
	1) Help your C programs figure out if they are being compiled
	in a System V, 4.1BSD, or 4.2BSD environment, and

	2) Return a printable string that returns your system name.
	This file depends on the first.

These have been tested on a Pyramid, in both universes, on a vax running
4.1, and on a vax running System V.  The files should be pretty
self explanotory.  Basically, it depends on the preprocessor identifiers
USG (System V), BSD (4.1 and 4.2), and BSD4_2 (4.2 only).

A makefile using these might have a line like
CFLAGS= -O `where`

Comments, suggestions, etc, are welcome.  Have fun!
'End of README'
echo 'extracting --- where.sh' 1>&2
cat > where.sh << 'End of where.sh'
#! /bin/sh

# where --- shell file to determine what kind of environment we are in

if test -r /bin/universe	# on a pyramid
then
	case `/bin/universe` in
	att)	echo "-DUSG -UBSD -UBSD4_2"
		;;

	ucb)	echo "-UUSG -DBSD -DBSD4_2"
		;;

	*)	echo unknown operating system! 1>&2
		echo "-UUSG -UBSD -UBSD4_2"	# undefine them all
		;;
	esac
else		# on something that is not a pyrmaid, probably a vax
	if grep SIGTSTP /usr/include/signal.h > /dev/null
	then		# berkeley unix
		if test -r /usr/include/whoami.h	# 4.1
		then
			echo "-UUSG -DBSD -UBSD4_2"
		else					# 4.2
			echo "-UUSG -DBSD -DBSD4_2"
		fi
	else			# ATT unix
		echo "-DUSG -UBSD -UBSD4_2"
	fi
fi
End of where.sh
chmod +x where.sh
echo 'extracting --- sysname.c' 1>&2
cat > sysname.c << 'End of sysname.c'
/* sysname --- return a string telling us who we are */

#include <stdio.h>

#define EOS 	'\0'

#ifdef USG
#include <sys/utsname.h>	/* stuff to find out who we are */
#endif

char *sysname ()
{
	int i, j, k;
	char c;
	static char buf[MAXLINE] = "";
	FILE *fp;

#ifdef USG	/* System V */
	struct utsname whoarewe;

	uname (& whoarewe);
	return (whoarewe.sysname);
#else
#ifdef BSD4_2	/* Berkeley 4.2 */
	if (buf[0] != EOS)
		return (buf);		/* something already there */

	j = sizeof (buf);
	k = gethostname (buf, & j);
	if (k != 0)
		return ("unknown");
	else
		return (buf);
#else		/* Berkeley 4.1 */
	if (buf[0] != EOS)
		return (buf);

	if ((fp = fopen ("/usr/include/whoami.h", "r")) == NULL)
		return ("unknown");
	else
	{
		auto char *cp;
		/*
		 * file should contain a single line:
		 * #define sysname "......"
		 */
		while ((c = getc (fp)) != '"' && c != EOF)
			;
		if (c == EOF)
			cp = "unknown";
		else
		{
			for (i = 0; (c = getc (fp)) != '"' && c != EOF; i++)
				buf[i] = c;
			buf[i] = EOS;
			if (c == EOF && i == 0)
				cp = "unknown";
			else
				cp = buf;
		}
		fclose (fp);
		return (cp);
	}
#endif
#endif
}
End of sysname.c
exit
-- 
Arnold Robbins
CSNET: arnold@gatech	ARPA:	arnold%gatech.csnet@csnet-relay.arpa
UUCP: { akgua, allegra, hplabs, ihnp4 }!gatech!arnold

Can you tell me how to get, how to get to Sesame Street?