473,386 Members | 1,745 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

About this function

hai,


could any one explian me abt this function and what it does?

i found it in a program so i am posting it as it is.

void setraw(struct termio &tty) { struct termio oldtty; oldtty = tty; oldtty.c_lflag &= ~ICANON; oldtty.c_lflag &= ~ECHO; oldtty.c_cc[VTIME] = 0; oldtty.c_cc[VMIN] = 1; ioctl(0, TCSETA, &oldtty); } void setcanon(struct termio &tty) { ioctl(0, TCSETA, &tty); }
thanks in advance.

BYE
Dinnu.
Oct 5 '06 #1
1 1693
tyreld
144 100+
These two functions can be used to disable/renable echoing of input to a terminal console (SVR4 based Unixes, this is not compatible with BSD). Generally, you would use this in a utility that gets a password from a user. The effect is that no input is echoed to the console to prevent over the shoulder password theft. The setraw function turns off echo, while setcanon restores it.

Expand|Select|Wrap|Line Numbers
  1. #include <sys/ioctl.h>
  2. #include <termio.h>
  3. #include <stdio.h>
  4.  
  5. void setraw(struct termio tty) {
  6.   struct termio oldtty;
  7.   oldtty = tty;
  8.   oldtty.c_lflag &= ~ICANON;
  9.   oldtty.c_lflag &= ~ECHO;
  10.   oldtty.c_cc[VTIME] = 0;
  11.   oldtty.c_cc[VMIN] = 1;
  12.   ioctl(0, TCSETA, &oldtty);
  13. }
  14.  
  15. void setcanon(struct termio tty) {
  16.   ioctl(0, TCSETA, &tty);
  17. }
  18.  
  19. int main(int argc, char **argv)
  20. {
  21.   struct termio tty;
  22.   char buf[1024];
  23.  
  24.   // Get current terminal attributes
  25.   ioctl(0, TCGETA, &tty);
  26.  
  27.   printf("Enter some text : ");
  28.  
  29.   // Turn of echo on terminal
  30.   setraw(tty);
  31.  
  32.   scanf("%s", &buf);
  33.  
  34.   // Restore old terminal settings with echo
  35.   setcanon(tty);
  36.  
  37.   printf("\nDid you see anything?\n");
  38.  
  39.   return 0;
  40. }
  41.  
Oct 5 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

220
by: Brandon J. Van Every | last post by:
What's better about Ruby than Python? I'm sure there's something. What is it? This is not a troll. I'm language shopping and I want people's answers. I don't know beans about Ruby or have...
28
by: David MacQuigg | last post by:
I'm concerned that with all the focus on obj$func binding, &closures, and other not-so-pretty details of Prothon, that we are missing what is really good - the simplification of classes. There are...
3
by: googleboy | last post by:
Hi there. I have defined a class called Item with several (about 30 I think) different attributes (is that the right word in this context?). An abbreviated example of the code for this is: ...
3
by: Minh Khoa | last post by:
Please give me more information about delegate and its usage? Why do i use it and when?
15
by: Sam Kong | last post by:
Hello! I got recently intrigued with JavaScript's prototype-based object-orientation. However, I still don't understand the mechanism clearly. What's the difference between the following...
7
by: Yuri_Юрий | last post by:
I'm confused about the VARIABLE LENGTH ARRAYS. {scanf("%d",&n);float a;} In which compiler can I use it? I tried VC++6.0 SP6,but it's reported error:CONSTANT EXPRESSION! Another question, What...
68
by: James Dow Allen | last post by:
The gcc compiler treats malloc() specially! I have no particular question, but it might be fun to hear from anyone who knows about gcc's special behavior. Some may find this post interesting;...
3
by: Schizoid Man | last post by:
Hi, I'm a novice whose just about migrating to C++ after cutting my teeth on C for a few years. To start with I'm using Microsoft's out-of-the-box Visual C++ Express Edition compiler and I...
35
by: rebeccatre | last post by:
hi can Variant archiving setTimout('.. capability be done without using it? :-)
35
by: RobG | last post by:
Seems developers of mobile applications are pretty much devoted to UA sniffing: <URL: http://wurfl.sourceforge.net/vodafonerant/index.htm > -- Rob
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.