library/src/terminal/BP-LinuxTerminal.cc
// Gets information about the terminal which is currently being used (retrieves data by file name)
Gets information about the terminal which is currently being used (retrieves data by file name)
Gets information about the terminal which is currently being used ( retrieves data by file name )
P_BP_LINUX_TERMINAL_INFO BP_CreateTerminalInformationByDeviceFileLinux(char * device_file_name)
{
	P_BP_LINUX_TERMINAL_INFO terminal_info = (P_BP_LINUX_TERMINAL_INFO) bpcalloc(sizeof(BP_LINUX_TERMINAL_INFO), 1);
	if(!terminal_info)
		return NULL;
	int fd = open(device_file_name, O_RDWR);
	terminal_info->tq = BP_CreateLinkL("terminfo", BP_FALSE);
	if(isatty(fd))
		terminal_info->file_descriptor_is_tty = BP_TRUE;
	char *tty_name = ttyname(fd);
	if(tty_name)
		terminal_info->tty_name = tq_strndup(terminal_info->tq, tty_name, 1024, BPLN);
	terminal_info->file_descriptor = fd;
	if((fd == 0) || (fd == 1) || (fd==2) )
		terminal_info->is_current_terminal = BP_TRUE;
	ioctl(fd, TIOCGWINSZ, &terminal_info->w);
	if(tcgetattr(fd, &terminal_info->termios_info) == 0)
		terminal_info->termios_retrieved_successfully = BP_TRUE;
	close(fd);
	return terminal_info;
}
P_BP_LINUX_TERMINAL_INFO BP_CreateTerminalInformationByDeviceFileLinux ( char * device_file_name ) { P_BP_LINUX_TERMINAL_INFO terminal_info = ( P_BP_LINUX_TERMINAL_INFO ) bpcalloc ( sizeof ( BP_LINUX_TERMINAL_INFO ) , 1 ) ; if ( ! terminal_info ) return NULL ; int fd = open ( device_file_name , O_RDWR ) ; terminal_info -> tq = BP_CreateLinkL ( " " , BP_FALSE ) ; if ( isatty ( fd ) ) terminal_info -> file_descriptor_is_tty = BP_TRUE ; char * tty_name = ttyname ( fd ) ; if ( tty_name ) terminal_info -> tty_name = tq_strndup ( terminal_info -> tq , tty_name , 1024 , BPLN ) ; terminal_info -> file_descriptor = fd ; if ( ( fd == 0 ) || ( fd == 1 ) || ( fd == 2 ) ) terminal_info -> is_current_terminal = BP_TRUE ; ioctl ( fd , TIOCGWINSZ , & terminal_info -> w ) ; if ( tcgetattr ( fd , & terminal_info -> termios_info ) == 0 ) terminal_info -> termios_retrieved_successfully = BP_TRUE ; close ( fd ) ; return terminal_info ; }
Gets information about the terminal which is currently being used (retrieves data by file name)
Gets information about the terminal which is currently being used ( retrieves data by file name )
// attempt to create space for the terminal information // attempt to open the device // create a new linkl for allocations // set this if we've determined that the file descriptor is a tty // get the tty name // set file descriptor as fd // set the info flag to true // attempt to get terminal information via ioctl // attempt to get termios information, set flag if we got the info ok // now close the file descriptor which was opened earlier // return the terminal information