1 TESTFILE.
5 TEST-FILE PIC X(9) VALUE "test.file".
5 NULL-TERMINATE PIC X(1) VALUE LOW-VALUE.
1 OFLAG PIC X(4) VALUE X"1A".
1 OFLAG-READ PIC X(4) VALUE X"1".
1 OMODE PIC X(4) VALUE X"1C".
1 TEST-DATA PIC X(12) VALUE "Hello World!".
1 SIZE-TEST-DATA PIC S9(9) BINARY VALUE 12.
1 FILE-DESCRIPTOR PIC S9(9) BINARY.
1 BYTES-READ PIC S9(9) BINARY.
1 BYTES-WRITTEN PIC S9(9) BINARY.
1 RETURN-INT PIC S9(9) BINARY.
1 RETURN-PTR POINTER.
ᑍ
ᑍ Beginning of mainline
ᑍ
PROCEDURE DIVISION.
MAIN-LINE.
OPEN OUTPUT LISTING.
ᑍ
ᑍ Get and print the real user id with the getuid function.
ᑍ
CALL "getuid" GIVING RETURN-INT.
ᑍ
ᑍ Check for error and report status.
ᑍ
IF RETURN-INT = -1 MOVE "Error getting real user id"
TO LIST-LINE,
PERFORM ERROR-FOUND,
ELSE MOVE RETURN-INT TO USER,
WRITE LIST-LINE FROM REALID.
ᑍ
ᑍ Get the current working directory and store it in BUFFER
ᑍ
CALL "getcwd" USING BY VALUE ADDRESS OF BUFFER,
BY VALUE LENGTH-OF-BUFFER,
GIVING RETURN-PTR.
ᑍ
ᑍ Check for error and report status.
ᑍ
IF RETURN-PTR = NULL MOVE "Error getting real current dir"
TO LIST-LINE,
PERFORM ERROR-FOUND,
ELSE MOVE BUFFER TO INITIALDIR,
WRITE LIST-LINE FROM CURDIR.
ᑍ
ᑍ Create the file test.file for writing. If it does not exist,
ᑍ give the owner authority to read, write, and execute.
ᑍ
CALL "open" USING BY VALUE ADDRESS OF TESTFILE,
BY VALUE OFLAG,
BY VALUE OMODE,
GIVING FILE-DESCRIPTOR.
ᑍ
ᑍ Check for error and report status.
ᑍ
IF FILE-DESCRIPTOR = -1 MOVE "Could not create file"
TO LIST-LINE,
B-180 System API Programming V4R1