summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorpeterbud <peterbudai@hotmail.com>2016-11-19 23:47:21 +0100
committerMarcus Meissner <marcus@jet.franken.de>2016-11-19 23:47:21 +0100
commit230e2554f8541df8c324ee889b75a6ce848aacf9 (patch)
treeb60e1dbc771449d5d04ebff08f08fc3068449fd2 /examples
parent835f2d7b2ab5a7879e1cb4e289777a4443094a32 (diff)
downloadlibgphoto2-230e2554f8541df8c324ee889b75a6ce848aacf9.tar.gz
add O_BINARY flag for open() calls to write images in binary mode on Windows
Diffstat (limited to 'examples')
-rw-r--r--examples/best-iso.c9
-rw-r--r--examples/lunkwill-canon-capture.c2
-rw-r--r--examples/preview.c2
-rw-r--r--examples/sample-capture.c2
-rw-r--r--examples/sample-photobooth.c4
-rw-r--r--examples/sample-tether.c2
-rw-r--r--examples/sample-trigger-capture.c2
-rw-r--r--examples/samples.h6
8 files changed, 20 insertions, 9 deletions
diff --git a/examples/best-iso.c b/examples/best-iso.c
index e46220672..84204b3f9 100644
--- a/examples/best-iso.c
+++ b/examples/best-iso.c
@@ -14,6 +14,11 @@
#include <string.h>
#include <gphoto2/gphoto2.h>
+#if !defined (O_BINARY)
+ /*To have portable binary open() on *nix and on Windows */
+ #define O_BINARY 0
+#endif
+
#define DEBUG
static int aperture;
@@ -229,7 +234,7 @@ camera_tether(Camera *camera, GPContext *context) {
path = (CameraFilePath*)evtdata;
printf("File added on the camera: %s/%s\n", path->folder, path->name);
- fd = open(path->name, O_CREAT | O_WRONLY, 0644);
+ fd = open(path->name, O_CREAT | O_WRONLY | O_BINARY, 0644);
retval = gp_file_new_from_fd(&file, fd);
printf(" Downloading %s...\n", path->name);
retval = gp_camera_file_get(camera, path->folder, path->name,
@@ -400,7 +405,7 @@ main(int argc, char **argv) {
printf("Pathname on the camera: %s/%s\n", camera_file_path.folder, camera_file_path.name);
- fd = open("capture.jpg", O_CREAT | O_WRONLY, 0644);
+ fd = open("capture.jpg", O_CREAT | O_WRONLY | O_BINARY, 0644);
retval = gp_file_new_from_fd(&file, fd);
if (retval != GP_OK) printf(" gp_file_new failed: %d\n", retval);
diff --git a/examples/lunkwill-canon-capture.c b/examples/lunkwill-canon-capture.c
index 630c2918c..f7f4280e6 100644
--- a/examples/lunkwill-canon-capture.c
+++ b/examples/lunkwill-canon-capture.c
@@ -107,7 +107,7 @@ capture_to_file(Camera *canon, GPContext *canoncontext, char *fn) {
printf("Pathname on the camera: %s/%s\n", camera_file_path.folder, camera_file_path.name);
- fd = open(fn, O_CREAT | O_WRONLY, 0644);
+ fd = open(fn, O_CREAT | O_WRONLY | O_BINARY, 0644);
retval = gp_file_new_from_fd(&canonfile, fd);
printf(" Retval: %d\n", retval);
retval = gp_camera_file_get(canon, camera_file_path.folder, camera_file_path.name,
diff --git a/examples/preview.c b/examples/preview.c
index 4157cf0d6..162e59664 100644
--- a/examples/preview.c
+++ b/examples/preview.c
@@ -100,7 +100,7 @@ capture_to_file(Camera *canon, GPContext *canoncontext, char *fn) {
printf("Pathname on the camera: %s/%s\n", camera_file_path.folder, camera_file_path.name);
- fd = open(fn, O_CREAT | O_WRONLY, 0644);
+ fd = open(fn, O_CREAT | O_WRONLY | O_BINARY, 0644);
retval = gp_file_new_from_fd(&canonfile, fd);
printf(" Retval: %d\n", retval);
retval = gp_camera_file_get(canon, camera_file_path.folder, camera_file_path.name,
diff --git a/examples/sample-capture.c b/examples/sample-capture.c
index 952b434c7..a3a932871 100644
--- a/examples/sample-capture.c
+++ b/examples/sample-capture.c
@@ -77,7 +77,7 @@ capture_to_file(Camera *camera, GPContext *context, char *fn) {
printf("Pathname on the camera: %s/%s\n", camera_file_path.folder, camera_file_path.name);
- fd = open(fn, O_CREAT | O_WRONLY, 0644);
+ fd = open(fn, O_CREAT | O_WRONLY | O_BINARY, 0644);
retval = gp_file_new_from_fd(&file, fd);
printf(" Retval: %d\n", retval);
retval = gp_camera_file_get(camera, camera_file_path.folder, camera_file_path.name,
diff --git a/examples/sample-photobooth.c b/examples/sample-photobooth.c
index 65327152e..180e4e366 100644
--- a/examples/sample-photobooth.c
+++ b/examples/sample-photobooth.c
@@ -43,7 +43,7 @@ capture_to_file(Camera *camera, GPContext *context, char *fn) {
strcpy (s+1, t+1);
}
- fd = open(fn, O_CREAT | O_WRONLY, 0644);
+ fd = open (fn, O_CREAT | O_WRONLY | O_BINARY, 0644);
if (fd == -1)
return GP_ERROR;
@@ -205,7 +205,7 @@ main(int argc, char **argv) {
sprintf(output_file, "image-%04d.jpg", capturecnt++);
}
- fd = open(output_file, O_CREAT | O_WRONLY, 0644);
+ fd = open (output_file, O_CREAT | O_WRONLY | O_BINARY, 0644);
retval = gp_file_new_from_fd(&file, fd);
retval = gp_camera_file_get(camera, path->folder, path->name,
GP_FILE_TYPE_NORMAL, file, context);
diff --git a/examples/sample-tether.c b/examples/sample-tether.c
index 7721ec550..3b6f863b8 100644
--- a/examples/sample-tether.c
+++ b/examples/sample-tether.c
@@ -41,7 +41,7 @@ camera_tether(Camera *camera, GPContext *context) {
path = (CameraFilePath*)evtdata;
printf("File added on the camera: %s/%s\n", path->folder, path->name);
- fd = open(path->name, O_CREAT | O_WRONLY, 0644);
+ fd = open (path->name, O_CREAT | O_WRONLY | O_BINARY, 0644);
retval = gp_file_new_from_fd(&file, fd);
printf(" Downloading %s...\n", path->name);
retval = gp_camera_file_get(camera, path->folder, path->name,
diff --git a/examples/sample-trigger-capture.c b/examples/sample-trigger-capture.c
index baa968905..aa94dd3db 100644
--- a/examples/sample-trigger-capture.c
+++ b/examples/sample-trigger-capture.c
@@ -101,7 +101,7 @@ wait_event_and_download (Camera *camera, int waittime, GPContext *context) {
if (-1 == stat(queue[0].path.name, &stbuf))
fd = creat(queue[0].path.name, 0644);
else
- fd = open(queue[0].path.name, O_RDWR, 0644);
+ fd = open(queue[0].path.name, O_RDWR | O_BINARY, 0644);
if (fd == -1) {
perror(queue[0].path.name);
return GP_ERROR;
diff --git a/examples/samples.h b/examples/samples.h
index 9132c6cb3..b7c0197a9 100644
--- a/examples/samples.h
+++ b/examples/samples.h
@@ -13,4 +13,10 @@ int canon_enable_capture (Camera *camera, int onoff, GPContext *context);
extern int camera_auto_focus (Camera *list, GPContext *context, int onoff);
extern int camera_eosviewfinder (Camera *list, GPContext *context, int onoff);
extern int camera_manual_focus (Camera *list, int tgt, GPContext *context);
+
+#if !defined (O_BINARY)
+ /*To have portable binary open() on *nix and on Windows */
+ #define O_BINARY 0
+#endif
+
#endif