tiger0516
asked on
Relatiev path question
Hi folks,
I am writing a ls-like program in unix. I got some problem when dealing with relative path.
My program runs correctly in I give absolute path or do not give path (I use "." instead"). However, when provided with relative path, either in ../ format or in ~/ format, I got problems.
i.e.
MYCODE -l ../../foo
reports an error but ls -l ../../foo can go thought
or
MYCODE ~/ list all files in the ROOT directory instead of my home directory
I think it is sth due to chdir. Any help?
Pls provide an example. Many thanks.
Pls tell me in which step shall I use chdir (chdir(argv[1] or chdir(entry->d_name), where entry is pointer to struct dirent )
Thanks
PS:
My code can display correct file attributions (drwx..., inode, etc) if provided with absolute paths. But with relative paths, only file name displays correctly.
I am writing a ls-like program in unix. I got some problem when dealing with relative path.
My program runs correctly in I give absolute path or do not give path (I use "." instead"). However, when provided with relative path, either in ../ format or in ~/ format, I got problems.
i.e.
MYCODE -l ../../foo
reports an error but ls -l ../../foo can go thought
or
MYCODE ~/ list all files in the ROOT directory instead of my home directory
I think it is sth due to chdir. Any help?
Pls provide an example. Many thanks.
Pls tell me in which step shall I use chdir (chdir(argv[1] or chdir(entry->d_name), where entry is pointer to struct dirent )
Thanks
PS:
My code can display correct file attributions (drwx..., inode, etc) if provided with absolute paths. But with relative paths, only file name displays correctly.
ASKER
I am supposed to use chdir, I think. I tired, but did not have good luck.
Any idea about using chdir?
Any idea about using chdir?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi Friedrich, I am asking C question, not apache question.
anyway, thanks.
anyway, thanks.
I understand libapr is a C library so I answered your question. The other point is that otherwise you have to handle the .., . and ~ expansions yourself.
Friedrich
Friedrich
what error you are getting.
try to print the current directory after changing the directory using _chdir.
and one more thing is you have to store the currentworking directory in buffer.
and then you have to write your ls functionalities, which uses _chdir
after then you have to change back to orginal directory. (hope you have done all these things.)
check the _chdir with single . or using .. seperately with out other directory information. check it's wotking correctly or not.
if it works, then problem is in other part.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
E.g ~ is expanded to the home directory of you user. You have to use something like glob
to mimix that behaviour or you have to write that on your own.
Regards
Friedrich