× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.




On 17/03/2005, at 4:56 AM, James Rich wrote:

I wrote (well copied from someone else) a little C program that does this:

int
main (int argc, char *argv[])
{
  FILE *infile;
  char buffer[LEN_BUF + 1];
  int len = LEN_BUF;

  infile = fopen ("/home/james/test.ps", "rb");
  len = fread (buffer, sizeof (char), LEN_BUF, infile);
  fclose (infile);
  return 0;
}

When I compile it with *IFSIO everything works just fine. But I need to make this part of an RPG program. So I change int main(int argc, char *argv[]) to int copy_ps_to_sf(FILE *infile), remove the FILE *infile declaration from the body of the function, and used CRTCMOD with *IFSIO. My RPG program opens the file and passes the file pointer as 10I 0. But now when this function runs I get:

read(): Operation not supported.

from perror. How can I read a file in C that I opened in RPG?

You should be able to do this but you must ensure you are using the same operations in RPG and C.


You say RPG is passing a 'file pointer' as 10I 0? That's not a pointer. It is a descriptor which suggests you are using the open() function in RPG. Note that the C example is using fopen() which does return a pointer (hence the * in the definition of FILE * infile; They ain't the same thing.

You cannot use fread() to process a file opened with open() because one uses descriptors and the other uses a pointer to a FILE structure. You can convert a descriptor to a FILE structure using the fdopen() function and then use fread(). See the C Runtime Library Reference for specific details--especially how to close the file if fdopen() fails.

You have a few choices:
a) Convert the descriptor to a FILE using fdopen() before issuing fread()
b) Modify the C example to use descriptor I/O. Change fread() to read() and fclose() to close(). Note that the parameters for the descriptor-based functions are different from the FILE-base functions so you'll need to alter them
c) Modify your RPG to use fopen() and pass the FILE pointer to C


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

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



As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
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.