Using the api fclear - IBM AS400

This is a discussion on Using the api fclear - IBM AS400 ; Can anyone help me. I need to use the c/400 function fclear in an RPGLE program... does anyone have examples of what i need to do....

+ Reply to Thread
Results 1 to 5 of 5

Thread: Using the api fclear

  1. Using the api fclear

    Can anyone help me. I need to use the c/400 function fclear in an
    RPGLE program... does anyone have examples of what i need to do.


  2. Re: Using the api fclear

    Kristi writes:

    > Can anyone help me. I need to use the c/400 function fclear in an
    > RPGLE program... does anyone have examples of what i need to do.


    If your asking for an example of how to call a C routine from
    within RPG, you may want to take a look at the free redbook from
    IBM here (See section 5):
    http://www.redbooks.ibm.com/abstracts/sg245402.html

    Carl.

  3. Re: Using the api fclear

    Kristi wrote:
    > Can anyone help me. I need to use the c/400 function fclear in an
    > RPGLE program... does anyone have examples of what i need to do.
    >


    Kristi, if you need help understanding how the function operates, then
    this won't help you - I'm not familiar with that function, and it looks
    quite complicated to understand exactly what it will do.

    But if you do understand how the function works, and just need help with
    the RPG coding details, then this may help.

    Does your RPG already have code for opening, closing the file? If not,
    you first need to find out how to do that. There is an excellent ebook
    here: http://www.scottklement.com/rpg/ifs_ebook/

    Assuming now that you have RPG code that opens the file etc, then you
    just need a prototype for fclear().

    If the extproc for your "open" function has the name 'open', then use
    this prototype:
    D fclear pr 10i 0 extproc('fclear')
    D handle 10i 0 value
    D bytes 10i 0 value
    or, if you have off_t defined as 10i 0:
    D fclear pr like(off_t)
    D extproc('fclear')
    D handle 10i 0 value
    D bytes like(off_t) value

    If the extproc for your "open" function has the name 'open64', then use
    this prototype:
    D fclear pr 20i 0 extproc('fclear64')
    D handle 10i 0 value
    D bytes 20i 0 value
    or, if you have off_t defined as 20i 0:
    D fclear pr like(off_t)
    D extproc('fclear64')
    D handle 10i 0 value
    D bytes like(off_t) value
    or, if you have off64_t defined as 20i 0:
    D fclear pr like(off64_t)
    D extproc('fclear64')
    D handle 10i 0 value
    D bytes like(off64_t) value

    myFileHandle = open (... parms ...);
    ...
    bytesCleared = fclear (myFileHandle : numBytes);
    if bytesCleared <> numBytes;
    ... an error occurred, check errno, close file etc ...

  4. Re: Using the api fclear

    il 15/06/2007 21.28, Scrive Kristi 40338664:
    > Can anyone help me. I need to use the c/400 function fclear in an
    > RPGLE program... does anyone have examples of what i need to do.
    >

    the C prototype is:
    off_t fclear(int file_descriptor, off_t nbyte);

    off_t is a data type defined differently whether _LARGE_FILES macro is
    defined or not, if defined off_t is a long long type (an 8 bytes
    integer), int (4 bytes integer)otherwise. Assume that in RPG you didn't.
    so you shoud prototype like this
    D fclear PR 10i 0 extproc(fclear)
    D fd 10i 0 value
    D nb 10i 0 value

    fd is the file descriptor returned by open function, so a very limited
    example would be

    D close PR 10i 0 extproc('close')
    D fd 10i 0 value
    D fclear PR 10i 0 extproc('fclear')
    D fd 10i 0 value
    D nb 10i 0 value
    D open PR 10i 0 extproc('open')
    D path * value options(*string)
    D flags 10I 0 value
    D mode 10U 0 value options(*nopass)
    D errno PR * extproc('__errno')
    D O_RDWR s 10i 0 inz(4)
    D O_APPEND s 10i 0 inz(256)
    D O_TEXTDATA s 10i 0 inz(16777216)
    D err s 10i 0 based(err_p)
    D fd s 10i 0
    D nb s 10i 0 inz(100)
    D rc s 10i 0
    D flag s 10i 0
    D filepath s 50a inz('/home/myhome/myfile.txt')
    C eval err_p = errno()
    C eval flag = %bitor(O_RDWR:O_TEXTDATA:O_APPEND)
    C eval fd = open(%trim(filepath):flag)
    C if fd >= 0 and err = 0
    C eval rc = fclear(fd:nb)
    C if rc = 0 and err = 0
    * the first 100 bytes were cleared basing on file ccsid, because of
    * O_TEXTDATA, even if O_APPEND was specified in opening options,
    * because of the offset assciated to fd was 0 as the file was just
    * opened and no i/o operation was previously made.
    C endif
    C callp(e) close(fd)
    C endif



    --
    Dr.Ugo Gagliardelli,Modena,ItalyCertifiedUindoscrasherAe joAlcoolInside
    Spaccamaroni andate a cagare/Spammers not welcome/Spammers vo merda
    Spamers iros a la mierda/Spamers allez vous faire foutre/Spammers loop
    schijten/Spammers macht Euch vom Acker/Spamerzy wypierdalac'

  5. Re: Using the api fclear

    Thank you all so much for your help.


+ Reply to Thread