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

Re: Pointer math (merging ifs files)



Sender: Scott Klement <sk@xxxxxxxxxxxxxxxx>


Hi Magne,


Pointer math works by changing which byte in memory the pointer points to. So, if you have a pointer called u_data that points to a user space, if you ran the following code, X would point to the byte AFTER u_data. (the 2nd one in the space)

x = u_data + 1;

Likewise, if you had u_data + 5, it would be the 6th byte in the user space -- 5 bytes later than the original one. (The number you're adding is called an "offset", if you every run into that term.)


So, to put 3 IFS files into a user space, you should load one, then set a pointer to the next available spot, then read the second one, etc.


Set up the user space with the following APIs:

    CALL QUSCRTUS() -- create the usrspc
    CALL QUSCUSAT() -- change the usrspc to auto-extend
    CALL QUSPTRUS() -- get pointer to user space

(The auto-extend is important, unless you want to pre-calculate the length of the user space before calling QUSCRTUS)

Then do the following:

newPos = u_data

    xf = open(%trimr(stmf1): O_RDONLY+O_TEXTDATA);
    if (xf = -1);
       // error!
    endif;
    len = read(xf: newPos: st_size);
    close(xf);

    xf = open(%trimr(stmf2): O_RDONLY+O_TEXTDATA);
    if (xf = -1);
       // error!
    endif;
    newPos = newPos + len;
    len = read(xf: newPos: st_size);
    close(xf);

    xf = open(%trimr(stmf3): O_RDONLY+O_TEXTDATA);
    if (xf = -1);
       // error!
    endif;
    newPos = newPos + len;
    len = read(xf: newPos: st_size);
    close(xf);

See how that works? Just before reading the data into memory, you set the pointer to the new position in the user space. Just add the length of the previous file to jump over the space that it occupies in the user space.

You could even do this in a loop if you wanted. Keep in mind, of course, that there's a limit to how much data can be put in a user space (About 16mb)

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