Sponsored Content
Top Forums Programming What happens on opening /dev/tty failure? Post 302399825 by jim mcnamara on Monday 1st of March 2010 05:20:03 PM
Old 03-01-2010
Checking to see that the stream pointer is NULL/not NULL is okay.

What happens in the case that stdin is redirected, which is, I think, what you may want.
try something like this:
Code:
File *in=NULL;
if( isatty(0) ) 
   in=fopen("dev/tty", "r");  
else
  in=stdin;
if(in==NULL) 
   barf();

Your best bet is to refer to Steven's "Advanced Programming in the UNIX Environment"
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Cannot open "/dev/tty"

Hi, When it proccesing the backup with cpio report this message: Cannot open "/dev/tty" and cancel de backup. Cuando se procesa la tarea del backup reporta el error: Cannot open "/dev/tty" y cancela el backup y no termina correctamente, a que se devera esta advertencia. Gracias. Thacks.... (3 Replies)
Discussion started by: cmr88
3 Replies

2. UNIX for Advanced & Expert Users

timeout opening writing control channel /dev/initctl problem occur i cant shoudown

Hi... This is message that occurs when i am trying to shutdown the linux system timeout opening writing control channel /dev/initctl how can i shutdown what is the problem here.. Thanks in advance ... (2 Replies)
Discussion started by: arunkumar_mca
2 Replies

3. Solaris

What is /dev/tty /dev/null and /dev/console

Hi, Anyone can help My solaris 8 system has the following /dev/null , /dev/tty and /dev/console All permission are lrwxrwxrwx Can this be change to a non-world write ?? any impact ?? (12 Replies)
Discussion started by: civic2005
12 Replies

4. Programming

sniff /dev/tty

hello all, Being root, I would like to log user activity (also multiple root activity), i don't really like history file based logging, lets assume that users have access to their .profile. I would like to write a monitoring daemon in C that would capture /dev/ttys, so I need to do a... (0 Replies)
Discussion started by: wayward
0 Replies

5. UNIX for Dummies Questions & Answers

read from terminal/keyboard > /dev/tty

Hi, I need to provide more than one character to "> /dev/tty" through terminal/keyboard input, I have this: ok=false while do echo " Enter r1 to reformat " > /dev/tty read choice case $choice in ) echo " bla bla bla " ;; done However, in this way,... (3 Replies)
Discussion started by: Gery
3 Replies

6. Programming

Create a pipe to /dev/tty

Hello everybody: I have a child process which reads a password from /dev/tty, as far as I know file descriptors for the child process can be seen by using lsof, so I want to connect to such device in order to send the password through a pipe, how could I do that? (2 Replies)
Discussion started by: edgarvm
2 Replies

7. UNIX for Dummies Questions & Answers

/dev/tty find last modified time

what can I use to find the last modified time of a /dev/tty ? (4 Replies)
Discussion started by: l flipboi l
4 Replies

8. UNIX for Dummies Questions & Answers

Reading password from /dev/tty

hi, From the below script: ##########################################pwd_auth.sh######################################################################################## #Author: Pandeeswaran Bhoopathy #Written on:26th Jan 2012 2:00PM #This script describes the feature of stty and illustrates... (3 Replies)
Discussion started by: pandeesh
3 Replies

9. AIX

Error opening device: /dev/fscsi0

Hello, One one of my AIX boxes I'm having the following errror: fcstat fcs0: Port Speed (supported): 4 GBIT Error opening device: /dev/fscsi0 errno: 0000003d Has anyone encountered similar errors? Thank you! (1 Reply)
Discussion started by: aixn00b
1 Replies

10. Shell Programming and Scripting

Simply question about capturing output to /dev/tty

Suppose another person wrote the following one-line shell script: echo $RANDOM > /dev/tty QUESTION #1: How can the random number, which is output to the terminal by this script, be captured in a variable? QUESTION #2: How can this be done in a cron job? Specific code, whether in ksh or... (1 Reply)
Discussion started by: Paul R
1 Replies
TTYNAME(3)						   BSD Library Functions Manual 						TTYNAME(3)

NAME
isatty, ttyname, ttyslot -- get name of associated terminal (tty) from file descriptor LIBRARY
Standard C Library (libc, -lc) SYNOPSIS
#include <unistd.h> int isatty(int fildes); char * ttyname(int fildes); int ttyslot(void); DESCRIPTION
These functions operate on the system file descriptors for terminal type devices. These descriptors are not related to the standard I/O FILE typedef, but refer to the special device files found in /dev and named /dev/ttyxx and for which an entry exists in the initialization file /etc/ttys. (See ttys(5).) The isatty() function determines if the file descriptor fildes refers to a valid terminal type device. The ttyname() function gets the related device name of a file descriptor for which isatty() is true. The ttyslot() function fetches the current process' control terminal number from the ttys(5) file entry. RETURN VALUES
The ttyname() function returns the null terminated name if the device is found and isatty() is true; otherwise, a NULL pointer is returned. The ttyslot() function returns the unit number of the device file if found; otherwise, the value zero is returned. FILES
/dev/* /etc/ttys SEE ALSO
ioctl(2), ttys(5) HISTORY
A isatty(), ttyname(), and ttyslot() function appeared in Version 7 AT&T UNIX. BUGS
The ttyname() function leaves its result in an internal static object and returns a pointer to that object. Subsequent calls to ttyname() will modify the same object. BSD
June 4, 1993 BSD
All times are GMT -4. The time now is 12:38 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy