#!/bin/sh # stack-direction -- determine direction of stack growth # Author: Noah Friedman # Created: 2002-10-09 # Public domain. # $Id: stack-direction,v 2.2 2008/12/10 21:22:12 friedman Exp $ # Commentary: # This program determines whether the stack grows from lower # addresses to higher addresses, or vice-versa. # The C compiler is called by this shell script. The environment variable # `CC' and `CFLAGS' are used to determine exactly what compiler and args to # use. `cc' is the default. # Code: cd /tmp || exit 1 file="stackdir$$" trap 'rm -f "$file" "${file}".[acos]' 0 1 2 3 15 { echo 'int sub (char *a) { char b; return (&b < a); }' echo 'int main () { char a; return sub (&a); }' } > "${file}.c" ${CC-cc} $CFLAGS "${file}.c" -o "./$file" || exit 1 ./"$file" case $? in 0) echo "up" ;; 1) echo "down" ;; *) echo "unknown" ;; esac # eof