From 17a6f83cf6408de542ad44ebf4dd3886da3feb33 Mon Sep 17 00:00:00 2001 From: Alexander Vdolainen Date: Sat, 1 Jul 2023 22:07:35 +0300 Subject: [PATCH] Issue #5 (alloc/free/list ops are done for exijpeg_data_t). --- include/exijpeg.h | 18 +++++++-- src/Makefile.am | 2 +- src/jpeg.c | 93 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 109 insertions(+), 4 deletions(-) create mode 100644 src/jpeg.c diff --git a/include/exijpeg.h b/include/exijpeg.h index f216927..f74ca14 100644 --- a/include/exijpeg.h +++ b/include/exijpeg.h @@ -26,18 +26,30 @@ #include #include #include -#include #include #include -#include #include +struct exijpeg_segment { + unsigned char *hd; + unsigned long length; + struct exijpeg_segment *next; +}; + typedef struct __exijpeg_data_type { unsigned char *data; char *filename; + size_t length; int fd; - + struct exijpeg_segment *segments; + struct exijpeg_segment *last; } exijpeg_data_t; +exijpeg_data_t *exijpeg_data_alloc(void); + +void exijpeg_data_free(exijpeg_data_t *); + +int exijpeg_data_add_segment(exijpeg_data_t *, unsigned char *, unsigned long); + #endif diff --git a/src/Makefile.am b/src/Makefile.am index 45cba3c..a65917b 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -11,6 +11,6 @@ AM_CFLAGS = -Wall -g bin_PROGRAMS = exifdate -exifdate_SOURCES = dtex.c exifdate.c +exifdate_SOURCES = dtex.c jpeg.c exifdate.c exifdate_LDADD = $(LIBS) $(LIBEXIF_LIBS) diff --git a/src/jpeg.c b/src/jpeg.c new file mode 100644 index 0000000..a3ed06f --- /dev/null +++ b/src/jpeg.c @@ -0,0 +1,93 @@ +/* + * EXIF date tool + * + * (c) Alexander Vdolainen 2023 + * + * this is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published + * by the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * this 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see ."; + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include + +#if 0 +struct exijpeg_segment { + unsigned char *hd; + unsigned long length; + struct exijpeg_segment *next; +}; + +typedef struct __exijpeg_data_type { + unsigned char *data; + char *filename; + size_t length; + int fd; + struct exijpeg_segment *segments; + struct exijpeg_segment *last; +} exijpeg_data_t; +#endif + +exijpeg_data_t *exijpeg_data_alloc(void) +{ + exijpeg_data_t *r = malloc(sizeof(exijpeg_data_t)); + + if(r) memset(r, 0, sizeof(exijpeg_data_t)); + + return r; +} + +void exijpeg_data_free(exijpeg_data_t *s) +{ + struct exijpeg_segment *c = NULL; + if(!s) return; + + if(s->filename) free(s->filename); + if(s->segments) { + for(c = s->segments; c != NULL; c = c->next) free(c); + } + + return; +} + +int exijpeg_data_add_segment(exijpeg_data_t *s, unsigned char *d, unsigned long l) +{ + struct exijpeg_segment *n = NULL; + + if(!s || !d) return -1; + if(!(n = malloc(sizeof(struct exijpeg_segment)))) return -1; + else { + n->hd = d; + n->length = l; + n->next = NULL; + } + if(!(s->segments)) { + s->segments = n; + s->last = n; + } else { + s->last->next = n; + s->last = n; + } + + return 0; +}