Re: Absolute paths

kevin lyda <> writes:

> trying to get the path of the current executable is a unix faq and the
> short answer is "you can't.  don't do it."  the slightly longer answer
> is "that's not the way to make your code location independent."

Those are the frequent answers, but there are programs that do it, and
do it reasonably well (like tetex).  You can't do it 100% of the time,
but if you assume that argv[0] was passed in by a shell doing normal
shell-like things, you can do it.

It won't work if people run your executable and pass in
/var/spool/mail/ats as argv[0], but who cares about them, anyway?

Alan Shutko <> - In a variety of flavors!
89 days, 1 hours, 19 minutes, 58 seconds till we run away.
Sex only concerns the three people involved.

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]