[cs631apue] Readlink errors

Tejas Nadkarni tnadkarn at stevens.edu
Sat Oct 5 21:11:55 EDT 2013


I take it back, it seems to work the first time but on future calls it
fails! This is stumping me. Here's my code. This is called for each
directory entry when using longformat.

char buf [PATH_MAX];
int r=0;
.
.
.
if it's a link...

r = readlink(strcat(p->fts_path,p->fts_name),buf,sizeof(buf)-1);
if (r>0){
  buf[r]='\0';
  printf(" %-s -> %s",p->fts_name,buf);
}else
  printf(" %-s -> %s",p->fts_name,"Could't read link");

Again, this works the first time it's run but after that fails!! :)


On Sat, Oct 5, 2013 at 8:59 PM, Tejas Nadkarni <tnadkarn at stevens.edu> wrote:

> I'm using readlink to read symlinks to determine their actual target and
> print it out as part of the longformat. This seems to work for links I
> create but I've run into existing symlinks that don't work and I believe is
> a permissions issue.
>
> How are you handling this?
>
> for example if I run "./ls -l /etc/" on my Ubuntu VM....
>
> It works on this...
> blkid.tab -> /dev/.blkid.tab
>
>
> but not on this...
>
> vtrgb -> Could't read link
>
> and many others.
>
> I've had no issues on symlinks I've created so far.
>
> Thoughts?
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.stevens.edu/pipermail/cs631apue/attachments/20131005/6d90fb76/attachment.html>


More information about the cs631apue mailing list