× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.




On 11/01/2007, at 7:47 AM, Arco Simonse wrote:

I have a requirement to call the unixlike function getcwd() directly from a CL program.
I wonder if that is possible to do.

Yes, but only on a release of OS/400 where the CALLPRC command supports passing by value (*BYVAL). VRM530 and above, I think.

Real question is why? Just use the RTVCURDIR CL command.

Since in the first parameter of that function a pointer has to be declared to the pathvariable, I don't know how to code the CALLPRC to it. (if possible at all)

OS/400 VRM540 supports pointers in CL. However, if you remember that passing a variable by reference is exactly the same as passing a pointer by value you can do this on VRM530. See code below.

After reading the manual over and over I conclude that it is not possible to find out the address of the CL variable in the calling CL program in which I want to retrieve the data returned by the getcwd function. Am I right on this?

Prior to VRM540 you are correct.

Here is VRM530 code to do what you want:
             PGM
             DCL        VAR(&BUFFER) TYPE(*CHAR) LEN(256)
             DCL        VAR(&BUFSIZE) TYPE(*CHAR) LEN(4)
             CHGVAR     VAR(%BIN(&BUFSIZE)) VALUE(256)
             CALLPRC    PRC('getcwd') PARM((&BUFFER) (&BUFSIZE *BYVAL))
             SNDPGMMSG  MSG(&BUFFER)
             ENDPGM

That code will also work on VRM540 but here is a pointer version instead:
             PGM
             DCL        VAR(&BUFFER) TYPE(*CHAR) LEN(256)
             DCL        VAR(&BUFSIZE) TYPE(*CHAR) LEN(4)
             DCL        VAR(&PBUFFER) TYPE(*PTR) ADDRESS(&BUFFER)
             CHGVAR     VAR(%BIN(&BUFSIZE)) VALUE(256)
             CALLPRC    PRC('getcwd') PARM((&PBUFFER *BYVAL) +
                          (&BUFSIZE *BYVAL))
             SNDPGMMSG  MSG(&BUFFER)
             ENDPGM

You can't do any of this prior to VRM530 because you can't pass the buffer size by value. However, the correct solution is to forget the getcwd() function and use the CL RTVCURDIR command instead.

Regards,
Simon Coulter.
--------------------------------------------------------------------
   FlyByNight Software         OS/400, i5/OS Technical Specialists

   http://www.flybynight.com.au/
   Phone: +61 3 9419 0175   Mobile: +61 0411 091 400        /"\
   Fax:   +61 3 9419 0175                                   \ /
                                                             X
                 ASCII Ribbon campaign against HTML E-Mail  / \
--------------------------------------------------------------------



As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.