diff --git a/CMakeLists.txt b/CMakeLists.txt index 6343562..fbd812c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,6 +5,6 @@ set(CMAKE_C_STANDARD 99) add_compile_definitions(__STDC_FORMAT_MACROS=1) add_library(libdicformat SHARED include/dicformat/consts.h include/dicformat/enums.h include/dic.h include/dicformat.h - include/dicformat/decls.h include/dicformat/structs.h src/identify.c src/open.c include/dicformat/context.h src/close.c include/dicformat/errors.h) + include/dicformat/decls.h include/dicformat/structs.h src/identify.c src/open.c include/dicformat/context.h src/close.c include/dicformat/errors.h src/read.c) include_directories(include include/dicformat) \ No newline at end of file diff --git a/include/dicformat/decls.h b/include/dicformat/decls.h index 8c72e6a..77f172b 100644 --- a/include/dicformat/decls.h +++ b/include/dicformat/decls.h @@ -41,5 +41,7 @@ void *open(const char *filepath); int close(void *context); +unsigned char *read_media_tag(void *context, int tag); + #endif //LIBDICFORMAT_DECLS_H diff --git a/src/read.c b/src/read.c new file mode 100644 index 0000000..37c923e --- /dev/null +++ b/src/read.c @@ -0,0 +1,65 @@ +// /*************************************************************************** +// The Disc Image Chef +// ---------------------------------------------------------------------------- +// +// Filename : open.c +// Author(s) : Natalia Portillo +// +// Component : libdicformat. +// +// --[ Description ] ---------------------------------------------------------- +// +// Handles opening DiscImageChef format disk images. +// +// --[ License ] -------------------------------------------------------------- +// +// This library is free software; you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation; either version 2.1 of the +// License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, see . +// +// ---------------------------------------------------------------------------- +// Copyright © 2011-2019 Natalia Portillo +// ****************************************************************************/ + +#include +#include + +unsigned char *read_media_tag(void *context, int tag) +{ + if(context == NULL) + { + errno = EINVAL; + return NULL; + } + + dicformatContext *ctx = context; + + // TODO: Cast this field without casting the whole structure, as this can buffer overflow + // Not a libdicformat context + if(ctx->magic != DIC_MAGIC) + { + errno = EINVAL; + return NULL; + } + + dataLinkedList *item = ctx->mediaTagsHead; + + while(item != NULL) + { + if(item->type == tag) + return item->data; + + item = item->next; + } + + return NULL; +} \ No newline at end of file