int
main(void) {
    int fd = safe_open("/test/testfile", O_RDWR | O_TRUNC);
    struct stat *stat = safe_fstat(fd);
    assert(stat->st_size == 0 && stat->st_blocks == 0);

    safe_seek(fd, sizeof(buffer) * 1024 * 2, LSEEK_SET);

    int i;
    for (i = 0; i < sizeof(buffer); i ++) {
        buffer[i] = i;
    }
    safe_write(fd, buffer, sizeof(buffer));
    memset(buffer, 0, sizeof(buffer));

    safe_seek(fd, -sizeof(buffer), LSEEK_END);
    safe_read(fd, buffer, sizeof(buffer));

    for (i = 0; i < sizeof(buffer); i ++) {
        assert(buffer[i] == (unsigned char)i);
    }

    fd = safe_open("/test/testfile", O_RDWR | O_TRUNC);
    stat = safe_fstat(fd);
    assert(stat->st_size == 0 && stat->st_blocks == 0);
    printf("sfs_filetest2 pass.\n");
    return 0;
}
Beispiel #2
0
void read_odsf (parser_state_t *ps, sup_header_t h)
{
	sup_ods_first_t odsf;

	if (h.packet_len < sizeof(odsf))
		die(ps->fh, sizeof(h), "Undersized ODSF packet.");

	safe_read(&odsf, sizeof(odsf), ps->fh, "ODSF structure");
	conv_sup_ods_first(&odsf);

	if ((odsf.magic_len & 0x80000000) && (odsf.magic_len & 0x40000000))
	{
		printf("ODS first\n\todsf type = single\n");
	}
	else if (odsf.magic_len & 0x80000000)
	{
		printf("ODS first\n\todsf type = multi\n");
	}
	else
	{
		fseek(ps->fh, -sizeof(odsf), SEEK_CUR);
		read_odsn(ps, h);
		return;
	}

	ps->total_object_sizes += odsf.width * odsf.height;
	(ps->images)++;
	printf("\tpicture   = %u\n", odsf.picture);
	printf("\tpalette   = %u\n", odsf.palette);
	printf("\tlength    = %u (incl. + 4)\n", odsf.magic_len & 0x3fffffff);
	printf("\twidth     = %u\n", odsf.width);
	printf("\theight    = %u\n", odsf.height);

	safe_seek(ps->fh, h.packet_len - sizeof(odsf), "OSDF data");
}
Beispiel #3
0
void read_odsn (parser_state_t *ps, sup_header_t h)
{
	sup_ods_next_t odsn;

	if (h.packet_len < sizeof(odsn))
		die(ps->fh, sizeof(h), "Undersized ODSN packet.");

	safe_read(&odsn, sizeof(odsn), ps->fh, "ODSN structure");
	conv_sup_ods_next(&odsn);
	if (odsn.m != 0 || (odsn.last != 0 && odsn.last != 64))
		die(ps->fh, sizeof(odsn), "Invalid ODSN magic.");
	printf("ODS next\n");
	printf("\tpicture = %u\n", odsn.picture);
	printf("\tlast    = %s (%u)\n", odsn.last ? "yes" : "no", odsn.last);

	safe_seek(ps->fh, h.packet_len - sizeof(odsn), "ODSN data");
}