Online Expert Day - HPE Data Storage - Live Now
April 24/25 - Online Expert Day - HPE Data Storage - Live Now
Read more
Operating System - OpenVMS
Showing results for 
Search instead for 
Did you mean: 

translate_lnm() example

Frequent Advisor

translate_lnm() example

Hi, VMS users

I am tweaking some a legacy system and I want to define some logicals as input. I wrote a test_command_count.c to get the value of "TEST_COMMAND_COUNT" which I defined using:

define/job TEST_COMMAND_COUNT 1000

somehow translate_lnm() always fails. Can someone review my code and give some pointers?



#define STR_SS( dsc, carr ) struct dsc$descriptor_s dsc = {sizeof( carr ), DSC$K_DTYPE_T, DSC$K_CLASS_S, carr}
#define SD_SET_P( dscp, strp )\
*(DESC_t *) (dscp) = c$str_sd;\
(dscp)->dsc$a_pointer = strp; (dscp)->dsc$w_length = 65535-_LOCC(0,65535,strp );\

int main()
int sts;
int test_command_count;
char czLclTestCmdCntName[64];
char czLclTestCmdCntValue[64];

STR_SS (dscLclTestCmdCntName, czLclTestCmdCntName);
STR_SS (dscLclTestCmdCntValue, czLclTestCmdCntValue);

/* translate test_command_count to its value */
sprintf(czLclTestCmdCntName, "%s", "test_command_count");
SD_SET_P(&dscLclTestCmdCntName, czLclTestCmdCntName);
dscLclTestCmdCntValue.dsc$w_length = sizeof(czLclTestCmdCntValue);
sts = translate_lnm(&dscLclTestCmdCntName, LNT_ANY, &dscLclTestCmdCntValue);
if ( sts == SS$_NORMAL )
czLclTestCmdCntValue[dscLclTestCmdCntValue.dsc$w_length] = '\0';
} /* if sts == SS$_NORMAL */
printf("translate_lnm failed\n");
czLclTestCmdCntValue[0] = '\0';
} /* else sts == SS$_NORMAL */

printf("test_command_count=%d", test_command_count);
Ian Miller.
Honored Contributor

Re: translate_lnm() example

The length you are setting in the descriptor is wrong.


dscLclTestCmdCntValue.dsc$w_length = strlen(czLclTestCmdCntValue);

What status value does translate_lnm return?
Purely Personal Opinion
Frequent Advisor

Re: translate_lnm() example

translate_lnm() returns 444.
Honored Contributor

Re: translate_lnm() example

Ok, translate_lnm() is not OpenVMS code. It's local code.

As for the error, that's a missing or misspelled logical name, or you might conceivably have some case-sensitivity going on here depending on your specific process settings.

$ x=f$message(444)
$ sho symbol x
X = "%SYSTEM-F-NOLOGNAM, no logical name match"

As for the underlying call, there is a library of routines at, and I and many others have posted up examples of sys$trnlnm and of lib$get_logical.

The keyword added to a Google search can get you directly into a massive collection of OpenVMS source code at that site.

And given this is C code and presumably fairly recent OpenVMS version, the C call getenv("logicalname") works nicely.

This is not a valid test for success:

if ( sts == SS$_NORMAL )...

That statement tests for exactly one successful status, and misses any other successful conditions that might be returned. It treats other successful returns as failures. Details on the stsdef.h include module and on the low-bit tests and other such are in the OpenVMS FAQ at HL, and elsewhere, and in modules elsewhere.

If you look at the stuff I have posted over at the HL web site (other than the FAQ), I'm pretty sure I have this same sequence for a debugging logical name. Tere's a big wad of example C code available for download if you search for newuser or such over at

Frequent Advisor

Re: translate_lnm() example

getenv() works great!!!


Frequent Advisor

Re: translate_lnm() example

Hein van den Heuvel
Honored Contributor

Re: translate_lnm() example

Ye,... please consider saying thanks with "points".

That way we will know later which answers helped a little, and which helped a lot.

Hein (0 points for that!)