Older Newer
Mon, 04 Nov 2019 02:11:13 . . . . SyneRyder [Formatting and merging info from FMML that would be deleted]


Changes by last author:

Added:
= fsetpos =

== Syntax ==

int fsetpos(FILE * file, fpos_t * position)

== Arguments ==

:file

::A pointer to the file that you are working with (obtained with fopen).

:position

::A 64-bit pointer to the new position in the file you want to move to (obtained with fgetpos).

== Return ==

Returns zero if the operation completed successfully, non-zero otherwise.

== Description ==

Changes the current read/write position in the file to the new position, given by position. Not really intended for moving to random positions in a file, unless you've already obtained pointers to those positions previously using fgetpos. For random file seeking, you should use fseek instead.

Note that position is actually a 64-bit pointer, which FilterMeister doesn't yet support. If you need to use this, you should allocate your own memory for the pointer, or use the fact that the k0 & k1 variables are allocated next to each other in memory.

== Comments ==

Due to a bug in early versions of FilterMeister, fsetpos was sometimes used in place of fseek for seeking. It isn't recommended to do this, but if you need to use this workaround, here is more information on using fsetpos instead of fseek from the FMML FilterMeister Mailing List:

<code>

Where you have:

//fsetpos(SETTINGS_FILE, &mybyte);

//seek forward 37 bytes

you might like to try this instead:

k0 = 37;

k1 = 0;

fsetpos(SETTINGS_FILE, &k0);

Why are we doing things this way? It's because fsetpos actually

requires a 64-bit integer, but at the moment FilterMeister doesn't

support them. So instead, we abuse the fact that the k0 and k1

variables are stored next to each other, and "pretend" they make

a 64-bit integer. By giving the address of k0 (using &k0), the

function will take the memory address and read enough of memory

to make the 64-bit integer.

</code>

== Also see ==

:fread, fseek, fwrite, fclose