On 04/08/2010, at 7:44 AM, Darryl Freinkel wrote:

fd = open( %trimr(path)
: O_APPEND + O_TRUNC + O_CCSID + O_TextData + O_WrOnly
: M_RDONLY
: 819
: 0 );


You need to return to the open documentation and read it properly.

Parameter 1: Path - seems OK presuming your are correctly null- terminating or the prototype is doing that for you.

Parameter 2: Open flags - Specifying both O_APPEND and O_TRUNC is a bit pointless; if you truncate there will be no data in the file so writes will happen at the end anyway. You don't specify O_CREAT so this file must already exist otherwise you'll get errno 3025. If it already exists then parameter 4 controls the data encoding.

Parameter 3: Mode - You haven't shown what value constant M_RDONLY actually is but presuming it is some combination of *R for file owner, group, or public then probably OK but ignored unless O_CREAT is specified.

Parameter 4: Conversion ID - The CCSID for O_CSSID. This value is the CCSID in which the system will provide data read from the file and in which the system will expect data written to the file. If the file does not exist then the system will expect you to provide data in this CCSID. If the file does exist the system will convert between job CCSID and this CCSID for you.

Parameter 5: Text conversion ID - The CCSID used if O_TEXT_CREAT is specified. Ignored in your example.

Aside from he missing O_CREAT your problem appears to be caused by your use of parameter 4.

If the file does not exist then if created (only if O_CREAT specified) the file will be tagged with CCSID 819 **AND** your program must supply data in CCSID 819. No data conversion will be done by the system

If the file already exists then the system will expect your program to supply the data in the CCSID 819 and the system will convert from 819 to the CCSID of the file.

What is happening is either:
a) The file has CCSID 819, you are writing EBCDIC data (CCSID 37) to the file, the system does no conversion, and the data looks like crap
or
b) The file has a CCSID other than 819, you are writing EBCDIC data (CCSID 37 to the file, the OS is converting from 819 (because you told it that's how you'd supply data) to the file CCSID, and the data looks like crap

You have three choices (not all of which are available on earlier releases):

1) Use the iconv APIs to convert the data into 819 before writing to the file
2) Open the file with O_CREAT to create the file with CCSID 819, close the file, then open again specifying 0 for parameter 4. This will make the system convert the data from your job CCSID to the file CCSID allowing you to write the data in your job CCSID (likely EBCDIC 37)
3) Specify O_TEXT_CREAT and leave parameter 5 at 0. This will allow you to write data in your job CCSID and the system will convert it to the file CCSID

Regards,
Simon Coulter.
--------------------------------------------------------------------
FlyByNight Software OS/400, i5/OS Technical Specialists

http://www.flybynight.com.au/
Phone: +61 2 6657 8251 Mobile: +61 0411 091 400 /"\
Fax: +61 2 6657 8251 \ /
X
ASCII Ribbon campaign against HTML E-Mail / \
--------------------------------------------------------------------




As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.