Thread: readlink segmentation fault

  1. #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?

  2. #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?

  3. #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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Why am I getting segmentation fault on this?
    By arya6000 in forum C++ Programming
    Replies: 6
    Last Post: 10-12-2008, 06:32 AM
  2. Segmentation fault
    By bennyandthejets in forum C++ Programming
    Replies: 7
    Last Post: 09-07-2005, 05:04 PM
  3. Segmentation fault
    By NoUse in forum C Programming
    Replies: 4
    Last Post: 03-26-2005, 03:29 PM
  4. Locating A Segmentation Fault
    By Stack Overflow in forum C Programming
    Replies: 12
    Last Post: 12-14-2004, 01:33 PM
  5. Segmentation fault...
    By alvifarooq in forum C++ Programming
    Replies: 14
    Last Post: 09-26-2004, 12:53 PM