/* Collection of code snippets by Arne Vajhøj */
/* (from articles on eksperten.dk / vajhoej.dk written sometime between 2004 and now) */
#include <stdio.h>

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

#define BLOCKSIZE 8192
#define BLOCKS 10
#define SHRMEMSIZ BLOCKS * BLOCKSIZE
#define MAXMSGSIZ 100
#define MAXMSGS SHRMEMSIZ / MAXMSGSIZ
#define DISKBLOCKSIZE 512

#define GLBSECNAM "M"

static union
{
   char dummy[SHRMEMSIZ];
   char msg[MAXMSGS][MAXMSGSIZ];
} __align(13) shrmem;

int main(int argc, char *argv[])
{
    $DESCRIPTOR(name, GLBSECNAM);
    void *range[2];
    long int stat;
    char dummy[2];
    /* create global section */
    range[0] = (char *)&shrmem;
    range[1] = (char *)&shrmem + sizeof(shrmem) - 1;
    stat = sys$crmpsc(range, 0, 0, SEC$M_PAGFIL | SEC$M_GBL | SEC$M_WRT | SEC$M_DZRO,
                      &name, 0, 0, 0, sizeof(shrmem) / DISKBLOCKSIZE, 0, 0, 0);
    if((stat & 1) == 0) printf("sys$crmpsc stat = %d\n", stat);
    /* wait for user input */
    printf("Press enter to exit");
    fgets(dummy, sizeof(dummy), stdin);
    return 0;
}
