/* TS: FILE.TS */

/* FILE I/O */

#include<stdio.h>
#include<sys/stat.h>
#include<fcntl.h>

int load_block(char *file_name, char *t)
{
    int len = 0, i, handle;

    handle = open(file_name, O_RDONLY, 0);
    if (handle == -1) {
        close(handle);
        return -1;
    }
    else {
        while ((i = read(handle, t, 16384)) > 0) {
            t += i;
            len += i;
        }
        close(handle);
        return len;
    }
}
int save_block(char *file_name, char *t, int len)
{
    int i, handle;

    handle = creat(file_name, S_IREAD | S_IWRITE);
    if (handle == -1) {
        close(handle);
        return -1;
    }
    else {
        i = write(handle, t, len);
        close(handle);
        return (i == len) ? 1 : 0;
    }
}

/* TS-END */
