ref: 78aa2362a55bfb147a995a7df2ec5691ef280aa8
parent: 013a0cb2aa0b73d9d5e6748d4bccc0f04720433e
author: Sigrid Solveig Haflínudóttir <[email protected]>
date: Thu Mar 14 16:11:15 EDT 2024
readtags example: seek to the image offset and back
--- a/examples/readtags.c
+++ b/examples/readtags.c
@@ -42,10 +42,14 @@
return;
char *raw = malloc(size);
Aux *aux = ctx->aux;
- if(read(aux->fd, raw, size) != size || (f != NULL && f(raw, &size) != 0)){
+ int prevoffset = lseek(aux->fd, 0, 1);
+ if(lseek(aux->fd, offset, 0) != offset ||
+ read(aux->fd, raw, size) != size ||
+ (f != NULL && f(raw, &size) != 0)){
fprintf(stderr, "failed to read the image\n");
exit(1);
}
+ lseek(aux->fd, prevoffset, 0);
write(1, raw, size);
exit(0);
return;
@@ -107,7 +111,8 @@
}
for(i = 1; i < argc; i++){
- printf("*** %s\n", argv[i]);
+ if(!image)
+ printf("*** %s\n", argv[i]);
if((aux.fd = open(argv[i], O_RDONLY)) < 0)
perror("failed to open");
else{