Re: any routines for manipulating file/path names?
Wan-Teh Chang <[email protected]>
| Newsgroups | gmane.comp.mozilla.devel.nspr |
|---|---|
| Message-ID | <[email protected]> |
Seth Grover wrote: > > What I'm trying to do is write a portable "expand file name" routine. > In other words, if the program is running in /home/me/whatever and > there's a file called hello.txt, and I pass "./hello.txt" to this > function, it will resolve to /home/me/whatever/hello.txt. > > I was accomplishing this in APR by calling apr_filepath_get to get the > current working directory, then apr_filepath_merge to merge the given > file name with this directory (which basically either navigate the > relative path if the filename given is a relative path or ignore the > current working directory if the filename given is an absolute path). > > I've looked around the NSPR documentation and I'm not seeing anything > for dealing with path names at all. This is correct. > So my question(s): > > - are there routines in the NSPR to do this and I'm just not seeing them? > - if not, is there a platform-portable way to get the "current directory"? In practice, you can call the Unix function getcwd(): http://opengroup.org/onlinepubs/007908799/xsh/getcwd.html #include <unistd.h> char *getcwd(char *buf, size_t size); getcwd() is also available on Windows, except that you need to include <direct.h> instead and you may need to call this function as _getcwd, with an underscore in its name: http://msdn2.microsoft.com/en-us/library/sf98bd4y(VS.80).aspx This reminds me that there is a feature request to add the NSPR replacement for getcwd: https://bugzilla.mozilla.org/show_bug.cgi?id=280953 Wan-Teh