In a Linux system, I'm trying to write a C program source.c which can behave differently according to the caller through a symbolic link. It compiles into an executable file source, and there are multiple files linked to it:
ln -s source link1
ln -s source link2
I want to make source output differently when I call link1 vs link2, but I can't find a way to recognize, in source.c, the filename of the caller.
I've read the readlink solution, but it only returns the source.
By convention,
argv[0]will contain the name used to invoke the program. You can use this to see which symlink it was called with.