Code:
- // Build 500 stream files in the /rob directory.
- //
- // To compile:
- // CRTBNDRPG IFS500 SRCFILE(xxx/QRPGLESRC) DBGVIEW(*LIST)
- //
- H DFTACTGRP(*NO) ACTGRP(*NEW) BNDDIR('QC2LE')
-
- D/copy ROUTINES/QPROTOSRC,IFSIO_H
- D/copy ROUTINES/QPROTOSRC,ERRNO_H
-
- D fd S 10I 0
- D wrdata S 24A
- D rddata S 48A
- D flags S 10U 0
- D mode S 10U 0
- D ErrMsg S 250A
- D Msg S 50A
- D Len S 10I 0
-
- D FileNameDs ds 15
- D FilePrefix 6a inz('/rob/F')
- D FileNumber 5S 0
- D FileNumberA 5a overlay(FileNumber)
- D FileSuffix 4a inz('.txt')
-
- //***************************************************************
- // Example of writing data to a stream file
- //***************************************************************
- /FREE
- flags = O_WRONLY + O_CREAT + O_TRUNC + O_CODEPAGE;
-
- mode = S_IRUSR + S_IWUSR
- + S_IRGRP
- + S_IROTH;
- for FileNumber = 1 to 500;
- // Open the file once to create it with code page 819.
- // Close it.
- // Reopen it to get automatic translation.
- fd = open(FileNameDs: flags: mode: 819);
- if fd < 0;
- ErrMsg = %str(strerror(errno));
- die('open() for output: ' + ErrMsg);
- endif;
- callp close(fd);
- // Now re-open the file in text mode. Since it was assigned a
- // code page of 819, and we're opening it in text mode, OS/400
- // will automatically translate to/from ASCII for us.
- fd = open(FileNameDs:
- O_WRONLY+O_TEXTDATA);
- if fd < 0;
- die('open(): ' + %str(strerror(errno)));
- endif;
-
- // Write some data
- wrdata = FileNumberA;
- if write(fd: %addr(wrdata): %size(wrdata))<1;
- ErrMsg = %str(strerror(errno));
- callp close(fd);
- die('open(): ' + ErrMsg);
- endif;
-
- // close the file
- callp close(fd);
- EndFor; // for FileNumber = 1 to somenumber
-
- *inlr = *on;
- return;
-
- /DEFINE ERRNO_LOAD_PROCEDURE
- /END-FREE
- /COPY ROUTINES/QPROTOSRC,ERRNO_H // Build 500 stream files in the /rob directory.
- //
- // To compile:
- // CRTBNDRPG IFS500 SRCFILE(xxx/QRPGLESRC) DBGVIEW(*LIST)
- //
- H DFTACTGRP(*NO) ACTGRP(*NEW) BNDDIR('QC2LE')
-
- D/copy ROUTINES/QPROTOSRC,IFSIO_H
- D/copy ROUTINES/QPROTOSRC,ERRNO_H
-
- D fd S 10I 0
- D wrdata S 24A
- D rddata S 48A
- D flags S 10U 0
- D mode S 10U 0
- D ErrMsg S 250A
- D Msg S 50A
- D Len S 10I 0
-
- D FileNameDs ds 15
- D FilePrefix 6a inz('/rob/F')
- D FileNumber 5S 0
- D FileNumberA 5a overlay(FileNumber)
- D FileSuffix 4a inz('.txt')
-
- //***************************************************************
- // Example of writing data to a stream file
- //***************************************************************
- /FREE
- flags = O_WRONLY + O_CREAT + O_TRUNC + O_CODEPAGE;
-
- mode = S_IRUSR + S_IWUSR
- + S_IRGRP
- + S_IROTH;
- for FileNumber = 1 to 500;
- // Open the file once to create it with code page 819.
- // Close it.
- // Reopen it to get automatic translation.
- fd = open(FileNameDs: flags: mode: 819);
- if fd < 0;
- ErrMsg = %str(strerror(errno));
- die('open() for output: ' + ErrMsg);
- endif;
- callp close(fd);
- // Now re-open the file in text mode. Since it was assigned a
- // code page of 819, and we're opening it in text mode, OS/400
- // will automatically translate to/from ASCII for us.
- fd = open(FileNameDs:
- O_WRONLY+O_TEXTDATA);
- if fd < 0;
- die('open(): ' + %str(strerror(errno)));
- endif;
-
- // Write some data
- wrdata = FileNumberA;
- if write(fd: %addr(wrdata): %size(wrdata))<1;
- ErrMsg = %str(strerror(errno));
- callp close(fd);
- die('open(): ' + ErrMsg);
- endif;
-
- // close the file
- callp close(fd);
- EndFor; // for FileNumber = 1 to somenumber
-
- *inlr = *on;
- return;
-
- /DEFINE ERRNO_LOAD_PROCEDURE
- /END-FREE
- /COPY ROUTINES/QPROTOSRC,ERRNO_H
|
|