LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 12-13-2004, 01:22 AM   #1
dogbird
Member
 
Registered: Nov 2004
Location: oklahoma
Distribution: slackware 9.0
Posts: 98

Rep: Reputation: 15
Angry still problems in libraries -- libc ?


I have run into a brick Wall trying to build a simple scanner in FLEX.

this is the back trace of a call to fread that hangs.


0x400f79b4 in read () from /lib/libc.so.6
(gdb) bt
#0 0x400f79b4 in read () from /lib/libc.so.6
#1 0x40156234 in __DTOR_END__ () from /lib/libc.so.6
#2 0x40097dae in _IO_file_xsgetn_internal () from /lib/libc.so.6
#3 0x40098ca8 in _IO_sgetn_internal () from /lib/libc.so.6
#4 0x4008c610 in fread () from /lib/libc.so.6
#5 0x080490d1 in yy_get_next_buffer () at lex.yy.c:1295
#6 0x08048d22 in yylex () at lex.yy.c:1129
#7 0x08049b06 in main (argc=2, argv=0xbffffa04) at algol.l:137
#8 0x4003dbb4 in __libc_start_main () from /lib/libc.so.6
(gdb) p yyin
$1 = (struct _IO_FILE *) 0x401531e0

this is the file yyin
It was openned with fopen(argv[1],"rw");
the file exists and has 20 lines of text.

(gdb) p * yyin
$2 = {_flags = -72539512, _IO_read_ptr = 0x40016000 "",
_IO_read_end = 0x40016000 "", _IO_read_base = 0x40016000 "",
_IO_write_base = 0x40016000 "", _IO_write_ptr = 0x40016000 "",
_IO_write_end = 0x40016000 "", _IO_buf_base = 0x40016000 "",
_IO_buf_end = 0x40017000 <Address 0x40017000 out of bounds>,
_IO_save_base = 0x0, _IO_backup_base = 0x0, _IO_save_end = 0x0,
_markers = 0x0, _chain = 0x0, _fileno = 0, _flags2 = 0, _old_offset = -1,
_cur_column = 0, _vtable_offset = 0 '\0', _shortbuf = "",
_lock = 0x40152128, _offset = -1, __pad1 = 0x0, __pad2 = 0x40153120,
_mode = 0, _unused2 = '\0' <repeats 51 times>}
(gdb)


So I need help. I do not know what to do now.
 
Old 12-13-2004, 06:15 AM   #2
rjlee
Senior Member
 
Registered: Jul 2004
Distribution: Ubuntu 7.04
Posts: 1,990

Rep: Reputation: 67
The w frag to fopen will always truncate the file on opening. You can't fread() a truncated file.

You want to open it with
Code:
fopen(argv[1],"r");
for reading or
Code:
fopen(argv[1],"ra");
for read/appending or
Code:
fopen(argv[1],"r+");
for read/writing.

Edit: Note that rw will give you read access to the file, but only to read back what you've written after suitable seeking and/or flushing.

Last edited by rjlee; 12-13-2004 at 09:37 AM.
 
Old 12-13-2004, 07:38 AM   #3
dogbird
Member
 
Registered: Nov 2004
Location: oklahoma
Distribution: slackware 9.0
Posts: 98

Original Poster
Rep: Reputation: 15
Ok, I 'll byte its a gotcha. in K&rR I had to use RW and it was just a habit. RW meant read write not read and reset. I hoe this works. The Libraries really are broken for very simple things. this business of trapping in fileno is bad enugh.
josephus

Every body is ignorant-- jist on different subjects
-- Will Rogers Jr.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Installation of Linux-Libc-Headers problems Damon Spector Linux From Scratch 12 10-29-2005 10:09 AM
Fedora 4 & libc++.so.5 and X display problems Nightfox Linux - Newbie 1 06-15-2005 02:49 AM
Libc and other libraries movitto Linux - Software 2 06-18-2004 09:18 PM
libc.so verse libc.so.5 markstevens Linux - Software 4 06-19-2003 11:41 AM
GNU libc libraries error Kaotica Linux - Software 1 04-16-2003 04:56 AM


All times are GMT -5. The time now is 07:17 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration