-2

Specifically, I need to write a C program where I put inside the pathname of a symbolic link and on output I print only the name of that symbolic link(not the name of the file pointed by the link). What functions and structures I must look at to find this information?

closed as unclear what you're asking by Gilles, mdpc, Michael Homer, don_crissti, cuonglm Jul 11 '15 at 2:56

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 3
    Can you explain this in more detail? It sounds like you're saying you have the path of a symbolic link, and you want to print the name of that symbolic link - isn't that just "everything after the last / of the pathname" ? – godlygeek Jul 10 '15 at 16:07
  • 1
    I might not understand what you really want, and I am guessing you are misunderstanding how symlinks work. Please edit your question to improve it, e.g. give an example (or how you'll do that with commands, etc). – Basile Starynkevitch Jul 10 '15 at 17:00
  • Could you define what is the name of a symbolic link? A symbolic link is (almost) a name.... – Basile Starynkevitch Jul 10 '15 at 17:08
  • 1
    Programming questions are off-topic here, you want Stack Overflow. But don't repost: your question is not worth asking, unless you meant something different from what you wrote. The name of the symbolic link is the name that you pass to the function. – Gilles Jul 10 '15 at 22:37
1

You can also look into readlinkat(..), it handles more error scenario's than readlink(..)

  • readlink and readlinkat are both useless, they open the link and read the name IN the link. – Eugenio Jul 10 '15 at 16:24
1

It is operating system specific.

On Linux and POSIX, consider readlink & readlinkat & lstat (and stat for symlinks without existing targets) & symlink & unlink ...

Maybe realpath(3) & access(2) & faccessat & basename(3) might be helpful to you.

Perhaps POCO & Glib/GObject/GIO from GTK are offering wrappers working on both Windows & POSIX.

  • readlink and readlinkat read the name IN the link, I don't need that, lstat give me a struct stat that contain only the information that that file is a link(st_mode), I need a way to obtain only the name of the link. – Eugenio Jul 10 '15 at 16:23

Not the answer you're looking for? Browse other questions tagged or ask your own question.