From:	SMTP%"RELAY-INFO-VAX@CRVAX.SRI.COM" 23-JUN-1994 18:13:16.34
To:	EVERHART
CC:	
Subj:	Re: RAB's XAB's, FILE's and FAB's

Date: Thu, 23 Jun 1994 13:54:27 +0100
From: Arne Vajhoej <ARNE@kopc.hhs.dk>
Subject: Re: RAB's XAB's, FILE's and FAB's
To: jimhowes@FREENET2.SCRI.FSU.EDU, INFO-VAX@SRI.COM
Message-id: <01HDVSZM7JUA90MWS0@kopc.hhs.dk>
X-VMS-To: KOPC::IN%"jimhowes@FREENET2.SCRI.FSU.EDU"
X-VMS-Cc: IN::"INFO-VAX@SRI.COM"
MIME-version: 1.0
Content-type: TEXT/PLAIN; CHARSET=ISO-8859-1
Content-transfer-encoding: 8BIT

> How do I get from a FILE * in C (or even a int (returned from open() )
> to the address of a RAB
> So far I've worked out that on AXP/VMS I can use (*fp)[0x0d] (from
> FILE,
> and on VMS use something like myrabaddr = (RAB *)&((long *)*fp)[61]
> 
> Neither of these look very 'official', and could of course be mere
> coincedences - Anyone got anything better.

If you are using VAX C, then the following works:

----
#include <stdio.h>
#include <rab.h>
#include <fab.h>
#include <nam.h>
/* must be linked with VAXCRTL.OLB and not VAXCRTL.EXE */
extern int _fstat(int, struct FAB **, struct NAM **, struct RAB **);

struct FAB *fabptr;
struct RAB *rabptr;
struct NAM *namptr;

FILE *fp;

fp = fopen(...);

_fstat(fileno(fp),&fabptr,&namptr,&rabptr);
----

It do not work with DEC C on AXP (and probbaly not with DEC C on VAX
either).

> I need to get the RAB to do a SYS$FLUSH(RAB,sun,err) on a file
> (fflush() only flushes the RTL buffers, not the RMS buffers)

You are lucky. That can be done otherwise.

The following works:

----
#include <stdio.h>
extern int fsync(int fd);
...
FILE *fp;
int fd;
...
fp = fopen(...);
...
fflush(fp);      /* flush VAXCRTL buffer to RMS */
fd = fileno(fp); /* convert fp to fd            */
fsync(fd);       /* flush RMS buffer to disk    */
----

Works on both VAX and AXP (it is even in DEC C's online help !).

                                                          Arne

Arne Vajhøj                             local DECNET:  KO::ARNE
Computer Department                     PSI:           PSI%238310013040::ARNE
Business School of Southern Denmark     Internet:      ARNE@KO.HHS.DK


