Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!auspex!guy From: guy@auspex.auspex.com (Guy Harris) Newsgroups: comp.sys.sgi Subject: Re: "getcwd" vs. "getwd" (was Re: Re GNU emacs 18.55) Message-ID: <4005@auspex.auspex.com> Date: 2 Sep 90 22:00:01 GMT References: <9008291653.AA10471@dinorah.wustl.edu> <3997@auspex.auspex.com> <1990Sep2.043003.13513@odin.corp.sgi.com> Organization: Auspex Systems, Santa Clara Lines: 24 >The original poster is correct; in 3.3, getcwd does call getwd. The >getwd call is not completely the same as BSD 4.3, it uses the POSIX >PATH_MAX (as does getcwd), instead of MAXPATHLEN; it won't return >anything longer. getcwd calls getwd with a buffer of size PATH_MAX, >then checks the length to see if it is too long (for the error check), >and strncpy's it if not. > >This is still faster than the 'standard' S5 getcwd, which does a popen >on /bin/pwd, and appears to have been done as part of some performance >tuning. I would have made "getwd()" a wrapper around "getcwd()" instead (pass PATH_MAX or MAXINT or whatever as the buffer size), and shoved the "getwd()" code into "getcwd()" in favor of the "popen()" code. A little less clumsy - no "strncpy()" needed - and a little less likely to surprise folks who have code that calls "getcwd()" and - for whatever reason - has its own routine named "getwd()". I'm not certain whether POSIX would actually *require* that "getcwd()" not drag in any routines with names that aren't part of the POSIX standard and don't begin with "_" (as the ANSI C standard does for routines it specifies, for quite good reason), but even if it isn't the law, it's still a good idea....