File: container_open.c

package info (click to toggle)
emile 0.10-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 1,716 kB
  • ctags: 2,737
  • sloc: ansic: 18,908; makefile: 726; asm: 622; sh: 2
file content (49 lines) | stat: -rw-r--r-- 946 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*
 *
 * (c) 2005 Laurent Vivier <LaurentVivier@wanadoo.fr>
 *
 */

#include <stdio.h>

#include <stdlib.h>

#include "libcontainer.h"

container_FILE *container_open(device_io_t *device, char *path)
{
	container_FILE *file;
	int block_size = device->get_blocksize(device->data);
	unsigned long first, nbblocs;
	int ret;

	first = strtol(path, &path, 0);
	if (*path != ',')
		return NULL;
	path++;
	nbblocs = strtol(path, &path, 0);
	if (*path != 0)
		return NULL;
	file = (container_FILE *)malloc(sizeof(container_FILE) + block_size);
	if (file == NULL)
		return NULL;

	file->container = (struct emile_container*)malloc(block_size * nbblocs);
	if (file->container == NULL)
	{
		free(file);
		return NULL;
	}

	ret = device->read_sector(device->data, first, file->container, block_size * nbblocs);
	if (ret == -1)
	{
		free(file->container);
		free(file);
	}

	file->offset = 0;
	file->device = device;
	file->current_block = 0;
	return file;
}