initial checkin
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@1481 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
00d29fe4dd
commit
9363d444c8
53
src/apps/bin/tty.c
Normal file
53
src/apps/bin/tty.c
Normal file
@ -0,0 +1,53 @@
|
||||
// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
|
||||
//
|
||||
// Copyright (c) 2001-2003, OpenBeOS
|
||||
//
|
||||
// This software is part of the OpenBeOS distribution and is covered
|
||||
// by the OpenBeOS license.
|
||||
//
|
||||
//
|
||||
// File: tty.c
|
||||
// Author: Daniel Reinhold (danielre@users.sf.net)
|
||||
// Description: prints the file name of the user's terminal
|
||||
//
|
||||
// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
|
||||
|
||||
#include <OS.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
|
||||
void
|
||||
usage()
|
||||
{
|
||||
printf("Usage: tty [-s]\n"
|
||||
"Prints the file name for the terminal connected to standard input.\n"
|
||||
" -s silent mode: no output -- only return an exit status\n");
|
||||
|
||||
exit(2);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
|
||||
if (argc > 2)
|
||||
usage();
|
||||
|
||||
else {
|
||||
bool silent = false;
|
||||
|
||||
if (argc == 2) {
|
||||
if (!strcmp(argv[1], "-s"))
|
||||
silent = true;
|
||||
else
|
||||
usage();
|
||||
}
|
||||
|
||||
if (!silent)
|
||||
printf("%s\n", ttyname(STDIN_FILENO));
|
||||
}
|
||||
|
||||
return (isatty(STDIN_FILENO) ? 0 : 1);
|
||||
}
|
Loading…
Reference in New Issue
Block a user