/* * Scan the JPEG file for Exif data and parse it. */ static int doit(FILE *fp, int n) { int mark, gotapp1, first, rc; unsigned int len, rlen; unsigned char *exifbuf; struct exiftags *t; long app1; gotapp1 = FALSE; first = 0; exifbuf = NULL; rc = 0; while (jpegscan(fp, &mark, &len, !(first++))) { if (mark != JPEG_M_APP1) { if (fseek(fp, len, SEEK_CUR)) exifdie((const char *)strerror(errno)); continue; } exifbuf = (unsigned char *)malloc(len); if (!exifbuf) exifdie((const char *)strerror(errno)); app1 = ftell(fp); rlen = fread(exifbuf, 1, len, fp); if (rlen != len) { fprintf(stderr, "%s: error reading JPEG (length " "mismatch)\n", fname); free(exifbuf); return (1); } t = exifscan(exifbuf, len, FALSE); if (t && t->props) { gotapp1 = TRUE; if (lflag) rc = listts(t, &lorder[n]); else rc = procall(fp, app1, t, exifbuf); } exiffree(t); free(exifbuf); } if (!gotapp1) { fprintf(stderr, "%s: couldn't find Exif data\n", fname); return (1); } return (rc); }
/* * Scan the JPEG file for Exif data and parse it. */ static int doit(FILE *fp, const char *fname) { int mark, gotapp1, first, rc; unsigned int len, rlen; unsigned char *exifbuf; struct exiftags *t; long app1; gotapp1 = FALSE; first = 0; exifbuf = NULL; rc = 0; while (jpegscan(fp, &mark, &len, !(first++))) { if (mark != JPEG_M_APP1) { if (fseek(fp, len, SEEK_CUR)) exifdie((const char *)strerror(errno)); continue; } exifbuf = (unsigned char *)malloc(len); if (!exifbuf) exifdie((const char *)strerror(errno)); app1 = ftell(fp); rlen = fread(exifbuf, 1, len, fp); if (rlen != len) { fprintf(stderr, "%s: error reading JPEG (length " "mismatch)\n", fname); free(exifbuf); return (1); } gotapp1 = TRUE; t = exifscan(exifbuf, len, FALSE); if (t && t->props) { if (bflag || com) rc = writecom(fp, fname, app1, findprop(t->props, tags, EXIF_T_USERCOMMENT), exifbuf, t->md.btiff); else rc = printcom(fname, findprop(t->props, tags, EXIF_T_USERCOMMENT), t->md.btiff); } else { fprintf(stderr, "%s: couldn't find Exif properties\n", fname); rc = 1; } exiffree(t); free(exifbuf); } if (!gotapp1) { fprintf(stderr, "%s: couldn't find Exif data\n", fname); return (1); } return (rc); }