- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- getc() trap into infinite-loop
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-27-2001 12:14 AM
тАО11-27-2001 12:14 AM
getc() trap into infinite-loop
The following source is euc_jp encoding,
aCC compiling, running result just output
"1" string, and it doesn't seem to jump out
of the first function getc(), and program
trap into infinite-loop, cannot exit. but
if changing source's encoding to shift-jis,
it works well.
How to fix this? Thanks a lot.
OS: HP-UX 11.0 LANG: euc_jp with JSE support
NOTICE: remote shell xsh's input parameter is
necessary for test
====================gdb info==================
(gdb) n
Single stepping until exit from function getc,
which has no line number information.
0x77c37650 in _nss_files_read_line () from /usr/lib/libnss_files.1
(gdb) n
Single stepping until exit from function _nss_files_read_line,
which has no line number information.
Breakpoint 1, 0x77fa1ff8 in getc () from /usr/lib/libc.2
(gdb) n
Single stepping until exit from function getc,
which has no line number information.
0x77c37650 in _nss_files_read_line () from /usr/lib/libnss_files.1
(gdb) n
Single stepping until exit from function _nss_files_read_line,
which has no line number information.
Breakpoint 1, 0x77fa1ff8 in getc () from /usr/lib/libc.2
(gdb)
***********************************************
#include
#include
#include
#include
#include
#include
char *host[] = { "192.168.3.61" };
char *user = "gyomu";
char *passwd = "gyomu";
char *cmd = "/export/disk1/p2/gyomu/jwu/rexec/xsh ??????????????????1??????";
main(int argc, char **argv)
{
int sd;
int n=0;
FILE *fp;
char ch;
char sBuf[1024];
struct servent *servent;
servent = getservbyname("exec", "tcp");
sd = rexec(host, servent->s_port, user, passwd, cmd, 0);
fp = fdopen(sd, "r");
printf("1\n");
getc(fp);
printf("2\n");
getc(fp);
printf("3\n");
getc(fp);
printf("4\n");
// while ((ch = getc(fp)) != EOF) {
// putchar(ch);
// }
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-27-2001 12:55 AM
тАО11-27-2001 12:55 AM
Re: getc() trap into infinite-loop
getc() and getchar() are implemented both as library functions and
macros. The macro versions, which are used by default, are defined in
remove the macro definition or, if compiling in ANSI-C mode, enclose
the function name in parenthesis or use the function address. The
following example illustrates each of these methods :
#include
#undef getc
...
main()
{
int (*get_char()) ();
...
return_val=getc(c,fd);
...
return_val=(getc)(c,fd1);
...
get_char = getchar;
};
If the integer value returned by getc(), getc_unlocked(), getchar(),
getchar_unlocked(), or fgetc() is stored into a character variable
then compared against the integer constant EOF, the comparison may
never succeed because sign-extension of a character on widening to
integer is machine-dependent.
You are using char type.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-27-2001 01:27 AM
тАО11-27-2001 01:27 AM
Re: getc() trap into infinite-loop
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-27-2001 01:37 AM
тАО11-27-2001 01:37 AM
Re: getc() trap into infinite-loop
Commenting in C is
/* to be commented include here */
like this . in ur programe it // won't work.
Regards
Joe.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-27-2001 01:39 AM
тАО11-27-2001 01:39 AM
Re: getc() trap into infinite-loop
while loop in ur program should be like following.
/* while ((ch = getc(fp)) != EOF) {
putchar(ch);
*/
Try this
Regards
Joe.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-27-2001 01:44 AM
тАО11-27-2001 01:44 AM
Re: getc() trap into infinite-loop
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-27-2001 01:47 AM
тАО11-27-2001 01:47 AM
Re: getc() trap into infinite-loop
I thought it is in ANSI-C.
Do u have fflush(stdin) in that. try giving this after getc() function.
Regards
Joe.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-27-2001 01:57 AM
тАО11-27-2001 01:57 AM
Re: getc() trap into infinite-loop
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-27-2001 04:14 AM
тАО11-27-2001 04:14 AM
Re: getc() trap into infinite-loop
Well.. check returns for gethostbyname, rexec and fdopen
Good luck.