### 例 5-5　例 5-4をAlphaシステムで実行するのに必要なソース・コードの変更

         #include  <ssdef.h>
         #include  <stdio.h>
         #include  <stsdef.h>
         #include  <string.h>
         #include  <stdlib.h>
         #include  <descrip.h>
         #include  <dvidef.h>
         #include  <rms.h>
         #include  <secdef.h>
         #include  <syidef.h> 【1】

         char buffer[512];  【2】
         char *filename = "maptest.dat";
         struct FAB fab;

         long  cpu_pagesize;  【3】

         struct itm {                      /* item list */
             short int     buflen;  /* length of buffer in bytes */
             short int  item_code;  /* symbolic item code */
             long          bufadr;  /* address of return value buffer */
             long       retlenadr;  /* address of return value buffer length */
           } itmlst[2];  【4】

         main( argc, argv )
         int argc;
         char *argv[];
         {
              int    i;
              int    status = 0;
              long   flags = SEC$M_EXPREG;
              long   inadr[2];
              long   retadr[2];
              int    fileChannel;
              char  *mapped_section;

         /********  create disk file to be mapped *************/

              fab = cc$rms_fab;
              fab.fab$l_fna = filename;
              fab.fab$b_fns = strlen( filename );
              fab.fab$l_fop = FAB$M_CIF | FAB$M_UFO;  /* must be UFO */

              status = sys$create( &fab );

              if( status & STS$M_SUCCESS )
                 printf("%s opened\n",filename);
              else
              {
                 exit( status );
              }

              fileChannel = fab.fab$l_stv;

         /**********  obtain the page size at run time  ****************/

              itmlst[0].buflen =  4;
              itmlst[0].item_code = SYI$_PAGE_SIZE;
              itmlst[0].bufadr =  &cpu_pagesize;
              itmlst[0].retlenadr = &cpu_pagesize_len;
              itmlst[1].buflen = 0;
              itmlst[1].item_code = 0;

        【5】 status = sys$getsyiw( 0, 0, 0, &itmlst, 0, 0, 0 );

              if( status & STS$M_SUCCESS )
              {
                   printf("getsyi succeeds, page size = %d\n",cpu_pagesize);
              }
              else
              {
                   printf("getsyi fails\n");
                   exit( status );
              }

         /**********  create and map the section  ****************/

              inadr[0] = &buffer[0];
              inadr[1] = &buffer[cpu_pagesize - 1];  【6】

              printf("address of buffer = %u\n", inadr[0] );

              status = SYS$CRMPSC(&inadr, /* inadr=address target for map */
                                 &retadr, /* retadr= what was actually mapped */
                                       0, /* acmode  */
                                       0, /* no flags to set  */
                                       0, /* gsdnam, only for global sections */
                                       0, /* ident, only for global sections */
                                       0, /* relpag, only for global sections */
                             fileChannel, /* returned by SYS$CREATE */
                                       0, /* pagcnt = size of sect. file used */
                                       0, /* vbn = first block of file used */
                                       0, /* prot = default okay */
                                       0); /* page fault cluster size */

              if( status & STS$M_SUCCESS )
              {
                   printf("section mapped\n");
                   printf("start address returned =%u\n",retadr[0]);
              }
              else
              {
                   printf("map failed\n");
                   exit( status );
              }
         }

[ 本文に戻る ]