[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Open a stream file with a specific CCSID



Sender: Scott Klement <sk@xxxxxxxxxxxxxxxx>


How do I open a stream file with a specific CCSID?

C* Open a stream file
c                   eval      fd = open('/tmp/testwrite.pdf':
c                                      O_WRONLY+O_TRUNC+O_CREAT: 511)

The IFSIO_H says that the needed flags are added together.
But how do I get CCSID=1281 when the constant is 32?

The constant tells the API that you want to assign a CCSID. It expects you to pass an additional parameter to the API that tells it what the CCSID is.


Note also that the CCSID will not be assigned unless the file doesn't exist and the open() API has to create it. To make sure that the file doesn't exist prior to calling the open() API, you should delete it with the unlink() API.

For example, the following code creates a file called /tmp/testwrite.pdf and assigns it a CCSID of 1281:

c callp unlink('/tmp/testwrite.pdf')

     c                   eval      fd = open( '/tmp/testwrite.pdf'
     c                                      : O_WRONLY+O_CREAT+O_CCSID
     c                                      : 511
     c                                      : 1281 )

Note that the data that you write is assumed to already be in CCSID 1281 -- the API won't automatically translate it for you unless the file already exists on disk, and you specify O_TEXTDATA. So, if you want it to translate from your current job's CCSID to 1281, you have to do the following:

c callp unlink('/tmp/testwrite.pdf')

** open the file once to create it with a CCSID of 1281:

     c                   eval      fd = open( '/tmp/testwrite.pdf'
     c                                      : O_WRONLY+O_CREAT+O_CCSID
     c                                      : 511
     c                                      : 1281 )

c callp close(fd)

      ** open the file a second time to perform translation with
      ** O_TEXTDATA
     c                   eval      fd = open( '/tmp/testwrite.pdf'
     c                                      : O_WRONLY+O_TEXTDATA )

This "two opens" technique was the only way to force translation to a newly created file in V5R1 and earlier. In V5R2, they added a new option called O_TEXT_CREAT that let you do the translation in a single call to open():

     c                   eval      fd = open( '/tmp/testwrite.pdf'
     c                                      : O_WRONLY + O_CREAT + O_CCSID
     c                                        + O_TEXTDATA + O_TEXT_CREAT
     c                                      : 511
     c                                      : 1281
     c                                      : 0 )

Note that CCSIDs in files stored in the IFS first became available in V5R1. However, the above techniques (other than O_TEXT_CREAT) will work on previous versions of OS/400 if you use O_CODEPAGE instead of O_CCSID.

Good Luck!

-----------------------------------------------------------------------
This is the FTPAPI mailing list.  To unsubsribe from the list send mail
to majordomo@xxxxxxxxxxxxx with the body: unsubscribe ftpapi mymailaddr
-----------------------------------------------------------------------