How can my NLM determine where it was...
Articles and Tips: qna
01 Jan 2003
Q.
How can my NLM determine where it was loaded from? For example,
load SYS:\SYSTEM\MYNLM (get SYS:\SYSTEM back)
or
load SYS:\DIR1\DIR2\DIR3\MYNLM (get SYS:\DIR1\DIR2\DIR3)
A.
With NetWare 5 and above, you can use the LibC function getnlmloadpath (see http://developer.novell.com/ndk/doc/libc/libc_enu/data/aghl604.html#aghl604
).On previous versions of NetWare, your NLM should analyze argv[ 0] and if does not contain a complete path, it will find itself in the search paths using NWGetSearchPathElement(). Make sure you search scans regardless of attributes, because the NLM could be flagged with the Hidden attribute.
The program, however, must correctly handle the following situation: when a search path points to a root directory (NSSVOL1:\ in my case) and it is set as
SEARCH ADD NSSVOL1:
(note the missing backward slash "\"), the program will receive the following in argv[ 0]:
NSSVOL1:ARGV0.NLM (note the missing '\')
And here is a snippet of code from one of my NLMs that handle the various situations I've seen. This includes typing the access path with slashes and/or backslashes.
_splitpath(ppzArgv[0], szVolume, szDir, NULL, NULL); if ((szVolume[strlen(szVolume)-1] == ':') { if ((szDir[0] != '/') && (szDir[0] != '\\')) strcat(szVolume, "/"); } // I wish to use the result as a base path for other files, // so make sure the trailing (back)slash is there if ((szDir[strlen(szDir)-1] != '/') && (szDir[strlen(szDir)-1] !='\\')) strcat(szDir, "/"); strcpy(szLoadPath, szVolume); strcat(szLoadPath, szDir);
* Originally published in Novell AppNotes
Disclaimer
The origin of this information may be internal or external to Novell. While Novell makes all reasonable efforts to verify this information, Novell does not make explicit or implied claims to its validity.