diff options
author | Jorg Schuler <jcsjcs@users.sourceforge.net> | 2006-05-30 14:09:44 +0000 |
---|---|---|
committer | Jorg Schuler <jcsjcs@users.sourceforge.net> | 2006-05-30 14:09:44 +0000 |
commit | 355d9e38ac7d87b345e70d8d9a7ee78a30ba8c17 (patch) | |
tree | 64cc40dc42c33925c6183222667354276479c362 /src/db-parse-context.c | |
parent | 58503e6e5b6ef315f37fe859baaf0f5216fc8f5c (diff) | |
download | libgpod-355d9e38ac7d87b345e70d8d9a7ee78a30ba8c17.tar.gz libgpod-355d9e38ac7d87b345e70d8d9a7ee78a30ba8c17.tar.xz libgpod-355d9e38ac7d87b345e70d8d9a7ee78a30ba8c17.zip |
***** merged photo-support branch back to MAIN. branch is tagged
photo-support-merged_00
ipod.py will need minor patching (flag2, flag3).
git-svn-id: https://gtkpod.svn.sf.net/svnroot/gtkpod/libgpod/trunk@1292 f01d2545-417e-4e96-918e-98f8d0dbbcb6
Diffstat (limited to 'src/db-parse-context.c')
-rw-r--r-- | src/db-parse-context.c | 30 |
1 files changed, 27 insertions, 3 deletions
diff --git a/src/db-parse-context.c b/src/db-parse-context.c index 6268d21..0adbe30 100644 --- a/src/db-parse-context.c +++ b/src/db-parse-context.c @@ -104,12 +104,16 @@ db_parse_context_get_remaining_length (DBParseContext *ctx) DBParseContext * db_parse_context_get_sub_context (DBParseContext *ctx, off_t offset) { + DBParseContext *sub_ctx; + if (offset >= ctx->total_len) { return NULL; } - return db_parse_context_new (&ctx->buffer[offset], + sub_ctx = db_parse_context_new (&ctx->buffer[offset], ctx->total_len - offset, ctx->byte_order); + sub_ctx->db = ctx->db; + return sub_ctx; } @@ -163,17 +167,30 @@ db_parse_context_get_m_header_internal (DBParseContext *ctx, const char *id, off } DBParseContext * -db_parse_context_new_from_file (const char *filename, guint byte_order) +db_parse_context_new_from_file (const char *filename, Itdb_DB *db) { int fd; struct stat stat_buf; int result; unsigned char *buffer; DBParseContext *ctx; + Itdb_Device *device; buffer = NULL; ctx = NULL; + switch (db->db_type) { + case DB_TYPE_ITUNES: + device = db->db.itdb->device; + break; + case DB_TYPE_PHOTO: + device = db->db.photodb->device; + break; + default: + g_return_val_if_reached (NULL); + } + g_return_val_if_fail (device, NULL); + fd = open (filename, O_RDONLY); if (fd == -1) { g_print ("Failed to open %s: %s\n", @@ -206,10 +223,17 @@ db_parse_context_new_from_file (const char *filename, guint byte_order) goto error; } - ctx = db_parse_context_new (buffer, stat_buf.st_size, byte_order); + if (device->byte_order == 0) + itdb_device_autodetect_endianess (device); + + ctx = db_parse_context_new (buffer, + stat_buf.st_size, device->byte_order); + if (ctx == NULL) { munmap (buffer, stat_buf.st_size); } + ctx->db = db; + error: close (fd); return ctx; |