Issue #5 (alloc/free/list ops are done for exijpeg_data_t).

main
Alexander Vdolainen 1 year ago
parent 60ba196e8b
commit 17a6f83cf6

@ -26,18 +26,30 @@
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <fcntl.h> #include <fcntl.h>
#include <getopt.h>
#include <string.h> #include <string.h>
#include <time.h> #include <time.h>
#include <utime.h>
#include <libexif/exif-data.h> #include <libexif/exif-data.h>
struct exijpeg_segment {
unsigned char *hd;
unsigned long length;
struct exijpeg_segment *next;
};
typedef struct __exijpeg_data_type { typedef struct __exijpeg_data_type {
unsigned char *data; unsigned char *data;
char *filename; char *filename;
size_t length;
int fd; int fd;
struct exijpeg_segment *segments;
struct exijpeg_segment *last;
} exijpeg_data_t; } 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 #endif

@ -11,6 +11,6 @@ AM_CFLAGS = -Wall -g
bin_PROGRAMS = exifdate bin_PROGRAMS = exifdate
exifdate_SOURCES = dtex.c exifdate.c exifdate_SOURCES = dtex.c jpeg.c exifdate.c
exifdate_LDADD = $(LIBS) $(LIBEXIF_LIBS) exifdate_LDADD = $(LIBS) $(LIBEXIF_LIBS)

@ -0,0 +1,93 @@
/*
* EXIF date tool
*
* (c) Alexander Vdolainen 2023 <alex@vapaa.xyz>
*
* 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 <http://www.gnu.org/licenses/>.";
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <string.h>
#include <time.h>
#include <libexif/exif-data.h>
#include <include/exijpeg.h>
#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;
}
Loading…
Cancel
Save