C Board  

Go Back   C Board > Platform Specific Boards > Linux Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 05-21-2003, 07:44 AM   #1
Registered User
 
Join Date: Apr 2003
Posts: 23
readlink segmentation fault

Code:
 if( S_ISLNK(mode) )
			{ 
				type = 'l'; /*symlink*/
				readlink(fileName, buf, sizeof(buf));
				printf("\n %s \n",buf);

				
			}
I have this and I keep getting segmentation faults. All I am trying to do is print out the location of a symbolic link. Any suggestions?
Schwarzhelm is offline   Reply With Quote
Old 05-21-2003, 07:54 AM   #2
Registered User
 
Join Date: Mar 2003
Posts: 143
Very difficult to say for certain without knowing exactly what readlink() does, but segmentation faults usually arise when you write over the end of allocated memory. My suspicion would be on buf. How is it declared? Is it big enough to hold the string? Is sizeof(buf) giving you the answer you expect?
DavT is offline   Reply With Quote
Old 05-21-2003, 08:02 AM   #3
Registered User
 
Join Date: Apr 2003
Posts: 23
I have buf declared as a char *buf. I tried the code that was suggested and it is still getting a segmentation fault. filename is dirp->d_name after a lstat.

Thank you.
Schwarzhelm is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Why am I getting segmentation fault on this? arya6000 C++ Programming 6 10-12-2008 06:32 AM
Segmentation fault bennyandthejets C++ Programming 7 09-07-2005 05:04 PM
Segmentation fault NoUse C Programming 4 03-26-2005 03:29 PM
Locating A Segmentation Fault Stack Overflow C Programming 12 12-14-2004 01:33 PM
Segmentation fault... alvifarooq C++ Programming 14 09-26-2004 12:53 PM


All times are GMT -6. The time now is 12:33 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22