           <<< VMSZOO::DISK$NOTES:[NOTES$LIBRARY]VMS_POSIX.NOTE;2 >>>
                     -< POSIX for OpenVMS - Public forum >-
================================================================================
Note 1366.2            RMS functionality from POSIX shell                 2 of 2
MUCTEC::BECKER "Hartmut B., VMS & Languages, Munich" 90 lines   7-APR-1997 03:55
                                 -< example? >-
--------------------------------------------------------------------------------
You want an example? Try this.

Hth,
Hartmut

psx> cat x.c
#include        <stdio.h>
#include        <string.h>

#include        <descrip.h>
#include        <psldef.h>
#include        <rms.h>
#include        <secdef.h>
#include        <starlet.h>

int main (void) {

        int     status;
        struct  FAB     fblock;
        char    filename[]= "X.BIN";
        unsigned long inadr[2], retadr[2];
        int     i;
        $DESCRIPTOR (name, "name");

fblock = cc$rms_fab;
fblock.fab$b_acmodes = PSL$C_USER << FAB$V_CHAN_MODE;
fblock.fab$l_fna = filename;
fblock.fab$b_fns = strlen(filename);
fblock.fab$l_fop = FAB$M_UFO;
fblock.fab$b_rtv = 255;
fblock.fab$b_fac = FAB$M_PUT|FAB$M_GET;

status = sys$open (&fblock);
printf ("$open:\t%08x\n", status);
printf ("fab$l_stv:\t%08x\n", fblock.fab$l_stv);

inadr[0] = (unsigned long)inadr;
inadr[1] = (unsigned long)0;
status = sys$crmpsc     (inadr,         /* inadr */
                        retadr,         /* retadr */
                        PSL$C_USER,     /* acmode */
                        SEC$M_WRT|SEC$M_EXPREG|SEC$M_GBL,
                                        /* flags */
                        &name,          /* gsdnam */
                        0,              /* ident */
                        0,              /* relpag */
                        (unsigned short)fblock.fab$l_stv,
                                        /* chan */
                        fblock.fab$w_bls,               /* pagcnt */
                        0,              /* vbn */
                        0,              /* prot */
                        0);             /* pfc */
printf ("$crmpsc:\t%08x\n", status);

printf ("retadr:\t[%08x,%08x]\n", retadr[0], retadr[1]);

/* hack to modify disk file */
scanf ("%d", &i);
*(int *)retadr[0]= i;

status = sys$deltva     (retadr,                /* inadr */
                        0,              /* retadr */
                        0);             /* acmode */
printf ("$deltva:\t%08x\n", status);
status = sys$dassgn ((unsigned short)fblock.fab$l_stv);
printf ("$dassign:\t%08x\n", status);
}

psx> c89 -O x.c
psx> cp a.out x.bin
psx> od x.bin |more
0000000000    000003  000000  000000  000000  001410  000000  000440  000000
0000000020    000150  000000  000230  000000  000270  000000  000000  000000
0000000040    000000  000006  000000  000000  000000  000000  000000  000000
...
psx> a.out
$open:  00010001
fab$l_stv:      000000d0
$crmpsc:        00000619
retadr: [7b038000,7b03a3ff]
255
$deltva:        00000001
$dassign:       00000001
psx> od x.bin |more

0000000000    000377  000000  000000  000000  001410  000000  000440  000000
0000000020    000150  000000  000230  000000  000270  000000  000000  000000
0000000040    000000  000006  000000  000000  000000  000000  000000  000000
...
    
