Than you Scott. I will have to fudge and probably write the api calls
in RPG since we are V5R3. I should have put that in the original post.
Chris Bipes
Director of Information Services
CrossCheck, Inc.
-----Original Message-----
From: midrange-l-bounces@xxxxxxxxxxxx
[mailto:midrange-l-bounces@xxxxxxxxxxxx] On Behalf Of Scott Klement
Sent: Wednesday, August 20, 2008 10:25 AM
To: Midrange Systems Technical Discussion
Subject: Re: ifs locks
Hi Chris,
Does anyone have a sample code in CL for checking and waiting for a
lock to clear for a file / directory in the IFS?
I assume you mean a stream file, right? I don't know of any way to wait
on a directory, since folks don't generally hold a lock on a directory.
So you'd have to wait until every object in the directory is unused.
Hmmm.. I've never attempted to do this in CL, only in RPG. But, as long
as you're able to use ILE CL in V5R4 or later, it should be possible in
CL.
Here's how I'd code it (this is off the top of my head, but should be
very close to being correct):
PGM
DCL VAR(&FILE) TYPE(*CHAR) LEN(500)
DCL VAR(&NULL) TYPE(*CHAR) LEN(1) VALUE(x'00')
DCL VAR(&FD) TYPE(*INT) LEN(4) VALUE(-1)
DCL VAR(&RC) TYPE(*INT) LEN(4) VALUE(-1)
DCL VAR(&FLAGS) TYPE(*INT) LEN(4) VALUE(0)
DCL VAR(&ERRPTR) TYPE(*PTR)
DCL VAR(&ERRNO) TYPE(*INT) LEN(4) +
STG(*BASED) BASPTR(&ERRPTR)
DCL VAR(&ERRDEC) TYPE(*DEC) LEN(4 0)
DCL VAR(&ERRCHR) TYPE(*CHAR) LEN(4)
DCL VAR(&ERRID) TYPE(*CHAR) LEN(7)
DCL VAR(&O_RDONLY) TYPE(*INT) LEN(4) VALUE(1)
DCL VAR(&O_NOSHARE) TYPE(*INT) LEN(4) VALUE(524288)
/* &O_RDONLY = Open the IFS file for reading only. +
&O_NOSHARE = Do not share the IFS file with anyone +
(the manual calls this O_SHARE_NONE) */
CHGVAR VAR(&FLAGS) VALUE(&O_RDONLY + &O_NOSHARE)
CHGVAR VAR(&FILE) VALUE('/tmp/test.txt' *CAT &NULL)
DOUNTIL (&ERRID *NE 'CPE3029')
CHGVAR VAR(&ERRID) VALUE(' ')
CALLPRC PRC('open') PARM((&FILE *BYREF) +
(&FLAGS *BYVAL)) +
RTNVAL(&FD)
IF (&FD *NE -1) DO
CHGVAR VAR(&ERRID) VALUE(' ')
CALLPRC PRC('close') PARM((&FD *BYVAL)) +
RTNVAL(&RC)
ENDDO
ELSE DO
CALLPRC PRC('__errno') RTNVAL(&ERRPTR)
CHGVAR VAR(&ERRDEC) VALUE(&ERRNO)
CHGVAR VAR(&ERRCHR) VALUE(&ERRDEC)
CHGVAR VAR(&ERRID) VALUE('CPE' *CAT &ERRCHR)
IF (&ERRID *EQ 'CPE3029') THEN(DLYJOB DLY(1))
ENDDO
ENDDO
IF (&ERRID *NE ' ') DO
SNDPGMMSG MSGID(&ERRID) MSGF(QCPFMSG) MSGTYPE(*ESCAPE)
RETURN
ENDDO
ENDPGM
Once again, I want to stress that this is ILE (not OPM) CL. And it
requires V5R4 or later to work properly. To compile it, you need to do
the following:
CRTCLMOD WAITIFS SRCFILE(xxx/xxx)
CRTPGM WAITIFS BNDDIR(QC2LE)
As an Amazon Associate we earn from qualifying purchases.