Index: examples/thumb.c |
diff --git a/examples/thumb.c b/examples/thumb.c |
index 2718a0c44468e493c72d4409a0b545ed60b9fbed..3dc360e3a1ef036df3d84ac9caefbe5bc9575e1d 100644 |
--- a/examples/thumb.c |
+++ b/examples/thumb.c |
@@ -47,7 +47,7 @@ int main (int argc, char **argv) { |
int fd; |
uint32_t id = 0; |
uint64_t filesize; |
- uint8_t *imagedata = NULL; |
+ char *imagedata = NULL; |
char *path = NULL; |
char *rest; |
struct stat statbuff; |
@@ -81,8 +81,8 @@ int main (int argc, char **argv) { |
perror("stat"); |
exit(1); |
} |
- filesize = (uint64_t) statbuff.st_size; |
- imagedata = malloc(filesize * sizeof(uint16_t)); |
+ filesize = statbuff.st_size; |
+ imagedata = malloc(filesize); |
#ifdef __WIN32__ |
if ( (fd = open(path, O_RDONLY|O_BINARY) == -1) ) { |
@@ -91,9 +91,9 @@ int main (int argc, char **argv) { |
#endif |
printf("Couldn't open image file %s (%s)\n",path,strerror(errno)); |
return 1; |
- } |
- else { |
- read(fd, imagedata, filesize); |
+ } else { |
+ ret = read(fd, imagedata, filesize); |
+ if (ret == -1) perror("read thumb data"); |
close(fd); |
} |
@@ -105,16 +105,9 @@ int main (int argc, char **argv) { |
} |
LIBMTP_filesampledata_t *thumb = LIBMTP_new_filesampledata_t(); |
- |
- int i; |
- thumb->data = malloc(sizeof(uint16_t) * filesize); |
- for (i = 0; i < filesize; i++) { |
- thumb->data[i] = imagedata[i]; |
- } |
- |
+ thumb->data = imagedata; |
thumb->size = filesize; |
thumb->filetype = LIBMTP_FILETYPE_JPEG; |
- |
ret = LIBMTP_Send_Representative_Sample(device,id,thumb); |
if (ret != 0) { |
printf("Couldn't send thumbnail\n"); |
@@ -122,7 +115,6 @@ int main (int argc, char **argv) { |
LIBMTP_Clear_Errorstack(device); |
} |
- free(imagedata); |
LIBMTP_destroy_filesampledata_t(thumb); |
LIBMTP_Release_Device(device); |