Issue #5 (alloc/free/list ops are done for exijpeg_data_t).
parent
60ba196e8b
commit
17a6f83cf6
@ -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…
Reference in New Issue