#!/bin/sh
################################################################################
##                                                                            ##
## Copyright (c) International Business Machines  Corp., 2008                 ##
##                                                                            ##
## This program 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 of the License, or          ##
## (at your option) any later version.                                        ##
##                                                                            ##
## This program 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 this program;  if not, write to the Free Software               ##
## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA    ##
##                                                                            ##
################################################################################

export TCID=ioctl01_02
export TST_TOTAL=2
export TST_COUNT=0

has_tty()
{
    if command -v stty >/dev/null 2>&1; then
        stty -F $1 > /dev/null
        if [ $? -ne 0 ]; then
            return 0
        fi
    fi
    return 1
}

for tttype in `ls /dev/tty*`
do
device_no=${tttype#/dev/tty}
case "$device_no" in
[0-9]|[0-9][0-9])
    has_tty $tttype
    if [ $? -eq 0 ]; then
        tst_resm TINFO "Skipping ioctl01 with $tttype"
        continue
    fi
    tst_resm TINFO "Testing ioctl01 with $tttype"
    ioctl01 -D $tttype
    RC=$?
    if  [ $RC -eq 0 ]
    then
     tst_resm TPASS "ioctl01 Passed with $tttype"
    else
     tst_resm TFAIL "ioctl01 Failed with $tttype"
    fi
echo;;
esac
done

for tttype in `ls /dev/tty*`
do
device_no=${tttype#/dev/tty}
case "$device_no" in
[0-9]|[0-9][0-9])
    has_tty $tttype
    if [ $? -eq 0 ]; then
        tst_resm TINFO "Skipping ioctl02 with $tttype"
        continue
    fi
    tst_resm TINFO "Testing ioctl02 with $tttype"
    ioctl02 -D $tttype
    RC=$?
    if  [ $RC -eq 0 ]
    then
     tst_resm TPASS "ioctl02 Passed with $tttype"
    else
     tst_resm TFAIL "ioctl02 Failed with $tttype"
    fi
echo;;
esac
done
tst_exit