From: "Tracy Pierce" <[log in to unmask]>
> The blurb I was reading led me to believe they lived on the same plane as
> chmod().
> I don't have the HP C compiler (or any other), so no ccxllk.pub.sys, and
no
> ccstdrl.lib.sys.
> But I do have libcshr, libcansi, libmansi, and libcrand(.lib.sys). Is
there
> any way I can call them from Cobol (maybe painful)?
You should be able to call them from COBOL, with some difficulty.
The program below worked, but I had to link it with /lib/libc.a, which I
don't think you will have on your system. I linked it with this command
link from=./TESTOBJ;to=./TESTX;rl=/lib/libc.a;posix
So that would work if you had /lib/libc.a.
Since you don't, you should be able to, instead, replace the calls
call "stat" using file-name, stat-buffer giving retval
call "chmod" using file-name, \perm-mode\ giving retval
with
call "_px_stat" using file-name, stat-buffer, retval
call "_px_chmod" using file-name, \perm-mode\, retval
respectively and then you don't have to link with any C library, since
_px_stat and _px_chmod are in XL.PUB.SYS. This isn't documented anywhere
but it seems to work on all the systems I've tried it on.
Notes for the program below:
(1) Filename arguments for chmod and stat must be in the HFS POSIX
syntax.
("FRED" would work as well as "./FRED", but I wanted to emphasize the
difference)
(2) Filenames must be terminated with a null (LOW-VALUE)
(3) The file permission (mode) is, conveniently, the first element of the
"stat" struct, so it was no problem to define it in COBOL. I found the
length of the stat struct using sizeof in C, so I padded out the buffer to
the correct length, but you could define all the elements in COBOL if you
wanted them.
$CONTROL POST85
identification division.
program-id. chmodtest.
data division.
working-storage section.
01 file-name pic x(40) value "./FRED".
01 stat-buffer.
05 perm-mode pic s9(4) comp.
05 filler pic x(102).
01 cmd-buffer.
05 cmd-line pic x(72).
05 pic x value %015.
01 sh-cmd-buffer.
05 sh-cmd-whole.
10 pic x(12) value '/bin/sh "-c '.
10 pic x value "'".
10 sh-cmd-line pic x(72).
10 pic x value "'".
10 pic x value '"'.
05 pic x value %015.
01 e1 pic s9(4) comp.
01 e2 pic s9(4) comp.
01 e3 pic s9(4) comp value 1.
01 retval pic s9(9) comp.
01 errno EXTERNAL pic s9(9) comp.
procedure division.
main section.
main-para.
move "PURGE FRED" to cmd-line
perform do-cmd
move "BUILD FRED" to cmd-line
perform do-cmd
move "/bin/ls -l FRED" to sh-cmd-line
perform do-sh-cmd
inspect file-name replacing all spaces by low-values
call "stat" using file-name, stat-buffer
giving retval
if retval not = 0
display "return of stat = " retval
end-if
display "perm-mode for file = " perm-mode
move %0644 to perm-mode
call "chmod" using file-name, \perm-mode\
giving retval
if retval not = 0
display "return of chmod = " retval
end-if
move "ls -l FRED" to sh-cmd-line
perform do-sh-cmd
call "stat" using file-name, stat-buffer
giving retval
if retval not = 0
display "return of stat = " retval
end-if
display "perm-mode for file = " perm-mode
stop run.
do-cmd.
call intrinsic "HPCICOMMAND" using cmd-buffer,
e1, e2, e3
if e1 not = 0
display "Error on command " cmd-line
display " e1 = " e1
display " e2 = " e2.
do-sh-cmd.
call intrinsic "HPCICOMMAND" using sh-cmd-buffer
e1, e2, e3
if e1 not = 0
display "Error on command " sh-cmd-whole
display " e1 = " e1
display " e2 = " e2.
* To join/leave the list, search archives, change list settings, *
* etc., please visit http://raven.utc.edu/archives/hp3000-l.html *
|