C Language Development Kit/Functions/Format

From OptiWiki

Jump to: navigation, search
Description OPH100x:

This function deletes all files on the default drive.

Other terminals: This function deletes all files in the RAM disk and initializes the heap. WARNING: All data in the handheld terminal will be lost!

void format(void);
Arguments None
Returns None
Remarks OPH100x:

This function deletes all files on the default drive, but leaves the heap as it is. Use the function set_default_drive to select that drive. To clear the heap as well, use the function clearheap. Please note that a call to this function might corrupt the RAM disk, since this uses the same memory area, so a format of the RAM disk is then advised.

Other terminals: This function initializes the heap and initializes the file system. All memory blocks previously allocated with malloc() or far_malloc() are returned to the heap. Pointers pointing to these memory blocks will not be valid anymore. All files in the RAM disk will be cleared. Data in these files will be lost. format() can be used to initialize the heap when the heap gets corrupted.

If you only want to remove all files in the file system, use the functions findfirst(), findnext() and remove() to cycle through all the files and delete them.

If you want to clear the heap, release all pointer values that were returned by malloc() and far_malloc().

#include <stdio.h>
#include <stdlib.h>
#include "lib.h"
void main( void )
    static char data[20+1];
    FILE *fp;
    while( 1 )
        printf("\f1: mem = %lu", coreleft());
        far_malloc( 70000L );
        while( getchar() == EOF )
        printf("\f2: mem = %lu", coreleft());
        if( NULL != ( fp = fopen("TEST.DAT", "wb")))
            fwrite( data, 1, 20, fp);
        while( getchar() == EOF )
        printf("\f3: mem = %lu", coreleft());
        while( getchar() == EOF )
        printf("\f4: mem = %lu", coreleft());
        while( getchar() == EOF )

Personal tools