Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sys/ioctl.h

Status
Not open for further replies.

666cartman

Programmer
Aug 27, 2002
20
DE
i am looking for a good man/tutorial or information about the functions of sys/ioctl,
is it possible to get information about a device with this header ?
 
Cartman:

I don't know of any FAQ that covers the control device header, ioctl.h. What I know I learned from two books and experimenting. Here are the books:

Using C on the Unix System by David Curry

and to a lesser extent:

Unix Newtwork Programming by W. Richard Stevens ISBN-0-13-949876-1

Here's a little something that manipulates the terminal driver under unix:

#include <stdio.h>
#include <termio.h>
#include <fcntl.h>

main()
{
printf(&quot;%c\n&quot;, ret_char());
}

/* ret_char.c. System V dependent.
* This function is designed to return the ascii value of a
* single character * as long as it's alphanumeric, an interrupt,
* control-c or a Carriage Return. This function only accepts
* an alphanumeric, an interrupt or control-c.
*
* 1. Save original terminal settings.
* 2. Turn off canonial mode and echoing.
* 3. Get the character.
* 4. Reset the original terminal settings.
* 5. Return the character.
*/
int ret_char()
{
struct termio tsave, chgit;
int c;

/* save original terminal settings */
if(ioctl(0, TCGETA, &tsave) == -1)
{
perror(&quot;bad term setting&quot;);
exit(1);
}
chgit = tsave;

/* turn off canonial mode and echoing */
chgit.c_lflag &= ~(ICANON|ECHO);
chgit.c_cc[VMIN] = 1;
chgit.c_cc[VTIME] = 0;

/* modify terminal settings */
if(ioctl(0, TCSETA, &chgit) == -1)
perror(&quot;can't modify terminal settings &quot;);

while (1)
{ /* break when an alphanumeric, interrupt,
control-c, CR is pressed */
c = getchar();
/* CR is ascii value 13, interrupt is -1, control-c is 3 */
if(isalnum(c) || c == '\r' || c == '\n' || c == '\b'
|| c == -1 || c == 3)
break;
}

/* reset to original terminal settings */
if(ioctl(0, TCSETA, &tsave) == -1)
{
perror(&quot;can't reset original setting&quot;);
exit(1);
}
/* return the character */
return(c);
}

/* End of File */


Regards,

Ed
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top