Path: utzoo!attcan!uunet!auspex!guy From: guy@auspex.UUCP (Guy Harris) Newsgroups: comp.unix.wizards Subject: Re: name of current dir in kernel Keywords: kernel device driver Message-ID: <510@auspex.UUCP> Date: 25 Nov 88 19:52:56 GMT References: <558@4gl.UUCP> Reply-To: guy@auspex.UUCP (Guy Harris) Organization: Auspex Systems, Santa Clara Lines: 21 >What i am looking for is an EASY and FAST way to get the name of the >current directory of the program that is running. The kernel generally does not keep that information around. On many systems, "getwd" runs "pwd", which basically starts at the current directory, looks at that directory's parent to see what the name of the current directory is in that parent directory, and repeats the process until it hits the root directory. Other systems have a library routine that encapsulates "pwd"s algorithm. This is not quick, in general. You may be able to speed it up by: 1) noting that some shells set up an environment variable that purports to be the current directory; you can get that variable, "stat" both it and "." and make sure it really *is* the current directory, and if so use its value 2) getting the current directory only once and remembering it; if your program executes a "chdir" system call, it can either recompute the current directory or attempt to combine the argument to "chdir" with the remembered current directory.