473,657 Members | 2,953 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Termios is freezing

hem
Hi,

I have the following small program which read password from user after
echoing off. But the problem is, it is freezing for some time (not sure
about the duration) before going to the next statement and I have to
press "enter" multiple times (maximum 4, it is not consistent though).
I am trying it on a hp-ux machine with aCC compiler.

Any pointers/help would be greatly appreciated.

#include <stdio.h>
#include <termios.h>
#include <unistd.h>
#include<string .h>

int main(int argc, char *argv[])
{
struct termios oldt,
newt;
char ch;
char userpasswd[50];

printf("enter password:");
tcgetattr( STDIN_FILENO, &oldt );
newt = oldt;
newt.c_lflag &= ~( ICANON | ECHO );
tcsetattr( STDIN_FILENO, TCSANOW, &newt );
gets(userpasswd );
tcsetattr( STDIN_FILENO, TCSANOW, &oldt );
printf("\nPassw ord enetered %s\n", userpasswd);
return 0;
}
Thanks,
Reddy

Apr 22 '06 #1
6 2810
hem wrote:
#include <termios.h>


Please use Google Groups to find a newsgroup that discusses termios. You
will get a much better answer there than on a generic newsgroup about C++.

(Also, your code is C, so learn the difference!)

--
Phlip
http://www.greencheese.org/ZeekLand <-- NOT a blog!!!
Apr 22 '06 #2
hem wrote:
Hi,

I have the following small program which read password from user after
echoing off. But the problem is, it is freezing for some time (not sure
about the duration) before going to the next statement and I have to
press "enter" multiple times (maximum 4, it is not consistent though).
I am trying it on a hp-ux machine with aCC compiler.

Any pointers/help would be greatly appreciated.

#include <stdio.h>
#include <termios.h>
#include <unistd.h>
#include<string .h>
<stdio.h> and <string.h> are OK but should be replaced by <cstdio> and
<cstring> if your C++ compiler supports it.

<termios.h> and <unistd.h> are system headers, and are not defined by
the C++ standard, so we can't help you with them here.

int main(int argc, char *argv[])
The argc and argv variables are not used. Consider using the other form
of main, with no arguments.
{
struct termios oldt,
newt;
char ch;
The ch variable is not used.
char userpasswd[50];

printf("enter password:");
There is no newline here, and no flush, so it may not be output on your
screen before you wait for user input. Try fflush(stdout);
tcgetattr( STDIN_FILENO, &oldt );
newt = oldt;
newt.c_lflag &= ~( ICANON | ECHO );
tcsetattr( STDIN_FILENO, TCSANOW, &newt );
gets(userpasswd );
The gets function is dangerous. What if the user enters more than 49
characters? The solution is to use an input function that limits the
length of input. A reasonable replacement is fgets. But then you have to
manually remove the newline character.
tcsetattr( STDIN_FILENO, TCSANOW, &oldt );
printf("\nPassw ord enetered %s\n", userpasswd);
return 0;
}


Your actual problem is likely to be caused by the system-specific stuff,
which I have ignored. Post to a unix newsgroup for a more useful
response if necessary. I suggest comp.unix.progr ammer

Simon.
Apr 22 '06 #3
On 22/04/2006, hem wrote:
I have the following small program which read password from user after
echoing off. But the problem is, it is freezing for some time (not
sure about the duration) before going to the next statement and I
have to press "enter" multiple times (maximum 4, it is not consistent
though). I am trying it on a hp-ux machine with aCC compiler.

Any pointers/help would be greatly appreciated.
comp.unix.progr ammer might be a better newsgroup for this question.
#include <stdio.h>
#include <termios.h>
#include <unistd.h>
#include<string .h>

int main(int argc, char *argv[])
{
struct termios oldt,
newt;
char ch;
char userpasswd[50];

printf("enter password:");
tcgetattr( STDIN_FILENO, &oldt );
newt = oldt;
newt.c_lflag &= ~( ICANON | ECHO );
I'm not sure what gets() does when canonical mode is disabled. As I
mentioned, the guys over at comp.unix.progr ammer will know.
tcsetattr( STDIN_FILENO, TCSANOW, &newt );
gets(userpasswd );
tcsetattr( STDIN_FILENO, TCSANOW, &oldt );
printf("\nPassw ord enetered %s\n", userpasswd);
return 0;
}


--
Simon Elliott http://www.ctsn.co.uk
Apr 22 '06 #4
Phlip wrote:
hem wrote:

#include <termios.h>

Please use Google Groups to find a newsgroup that discusses termios. You
will get a much better answer there than on a generic newsgroup about C++.


I agree. As I and the other Simon suggested, comp.unix.progr ammer is a
good choice.
(Also, your code is C, so learn the difference!)


The code provided appears to be valid as both C and C++, apart from the
system-specific parts. I don't see how you can conclude that the OP does
not know the difference between C and C++.

Simon.
Apr 22 '06 #5
Simon Biber wrote:
(Also, your code is C, so learn the difference!)


The code provided appears to be valid as both C and C++, apart from the
system-specific parts. I don't see how you can conclude that the OP does
not know the difference between C and C++.


There's a spectrum of code styles, from C-style to C++-style. The given code
used stuff that C++ should not use, such as <stdio.h>.

However you are correct that I should have stated the observation as a
question.

--
Phlip
http://www.greencheese.org/ZeekLand <-- NOT a blog!!!
Apr 23 '06 #6
hem
Hi,

Thanks for your valuable responses. I will try it out in
comp.unix.progr ammer.

Regards,
Reddy

Apr 24 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1154
by: Jonathan Hodges | last post by:
Posted with an Unregistered Version of NewsHunter - The Newsgroup Utility for OS X. Get your copy today at: http://www.parkersoftware.com/products/newshunter/ Can anyone provide details on how the python implementation of termios.h differs from the POSIX library? Are there platform specific issues, especially for the Darwin build? It seems that if I make identical function calls in a python script and in some c code, the result on my COM...
3
11008
by: henry xie | last post by:
Hi, All: I am a newbie in Python. I am trying to use pexpect package in the project. But when I installed the package, it couldn't be used as termios.py was missing. I checked the LIB directory. It had TERMIOS.py but no termios.py. Could any body explain to me where can I found this file and solve this problem? Thanks in advance. Henry
5
6516
by: Petr Jakes | last post by:
On my box (Fedora Core4, Python 2.4.1) I am getting following error: >>> import termios, sys >>> fd = sys.stdin.fileno() >>> oldSettings = termios.tcgetattr(fd) Traceback (innermost last): File "<stdin>", line 1, in ? error: (22, 'Invalid argument') Thanks for your comments. Petr Jakes
7
2036
by: bearophileHUGS | last post by:
Most of my ideas seem usless or stupid, but I think expressing them here doesn't harm much. This is an idea for Py 3.0, because it's not backward compatible. Dicts and sets require immutable keys, like tuples or frozensets, but to me they look like a duplication. So the idea is to remove tuples and frozensets (and replace the few other uses of tuples with lists, like the % interpolation), and to add a freeze operation, to freeze lists,...
0
1617
by: Derek Peschel | last post by:
Should I add an RFE to SourceForge too? I'd like a wide audience in case someone has enough experience to comment or is solving the same problem. I'm using the urwid library which uses curses. On my system (Mac OS 10.3.7) I specifically have ncurses. The programs I'm running turn off echoing and set raw mode but don't disable interrupts. For development purposes I like having interrupts, but my preferred keystrokes (WordStar) conflict...
0
2334
by: Laszlo Nagy | last post by:
Hi All, I have a python program that downloads database backups from a remote server, and tries to replace the local database with the downloaded backup. The database is a PostgreSQL server and my program calls the pg_restore command with the aid of the wonderful pexpect module. Everything works fine if I start this program from a tty. When I try to start the same program from cron, I get this nasty exception: Traceback (most recent call...
2
5753
by: Brice Rebsamen | last post by:
Hi I wrote the following program that reads the keyboard in medium raw mode (keycode mode). Here is the initialization code, the full code is at the end. fd = open("/dev/tty0", O_RDONLY); tcgetattr ( fd, &newkbd ); newkbd.c_lflag &= ~ (ECHO | ICANON | ISIG); newkbd.c_iflag = 0;
3
4725
by: goblin | last post by:
Hi all I'm struggeling to get my serial port settings changed using termios. I can change the baud rate fine, but none of the control flags respond to my changes. As an example: #include <stdio.h> #Iinclude <termios.h> int main (void) {
1
1729
by: jorba101 | last post by:
I'm programming an ARM's UART that comes with a library implementing the standard unix termios interface. Regarding termios, I have following trouble: When I do following syscall: write( myFd, myStr, myLen ) It is placing myStr into an output buffer, implemented in the driver, that will send out all bytes through the UART.
0
8302
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8820
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8718
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7314
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5630
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4150
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1937
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1601
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.