cedric pushed a commit to branch master.

http://git.enlightenment.org/core/efl.git/commit/?id=0497b9685c782c24fba84a1d5391edaa8d5ce10a

commit 0497b9685c782c24fba84a1d5391edaa8d5ce10a
Author: Vincent Torri <vincent dot torri at gmail dot com>
Date:   Thu Dec 3 11:42:08 2015 +0100

    efl: add binary mode to open() calls
    
    This allows better compatibility with Windows
    
    Signed-off-by: Cedric BAIL <ced...@osg.samsung.com>
---
 src/bin/eeze/eeze_scanner.c                                |  6 +++++-
 src/bin/efreet/efreet_icon_cache_create.c                  |  6 +++++-
 src/examples/ecore/ecore_con_url_download_example.c        |  6 +++++-
 src/lib/ecore/ecore.c                                      |  8 ++++++--
 src/lib/ecore_evas/ecore_evas.c                            |  8 ++++++--
 src/modules/ecore_buffer/shm/ecore_buffer_shm.c            |  6 +++++-
 src/modules/ecore_evas/engines/extn/ecore_evas_extn_buf.c  |  6 +++++-
 .../evas/image_loaders/generic/evas_image_load_generic.c   |  6 +++++-
 src/tests/ecore/ecore_test_ecore_file.c                    | 14 +++++++++-----
 src/tests/eet/eet_suite.c                                  |  6 +++++-
 src/tests/eina/eina_test_file.c                            | 14 +++++++++-----
 src/tests/eio/eio_test_file.c                              |  8 ++++++--
 12 files changed, 71 insertions(+), 23 deletions(-)

diff --git a/src/bin/eeze/eeze_scanner.c b/src/bin/eeze/eeze_scanner.c
index 416f9ea..8fefe30 100644
--- a/src/bin/eeze/eeze_scanner.c
+++ b/src/bin/eeze/eeze_scanner.c
@@ -20,6 +20,10 @@
 #define ERR(...)            EINA_LOG_DOM_ERR(es_log_dom, __VA_ARGS__)
 #define CRI(...)            EINA_LOG_DOM_CRIT(es_log_dom, __VA_ARGS__)
 
+#ifndef O_BINARY
+# define O_BINARY 0
+#endif
+
 static int es_log_dom = -1;
 static Ecore_Con_Server *svr = NULL;
 static Eet_Data_Descriptor *es_edd = NULL;
@@ -186,7 +190,7 @@ cdrom_timer(Eeze_Scanner_Device *dev)
    /* cdrom already mounted, no need to poll */
    if (dev->mounted) return EINA_TRUE;
    devpath = eeze_udev_syspath_get_devpath(dev->device);
-   fd = open(devpath, O_RDONLY);
+   fd = open(devpath, O_RDONLY | O_BINARY);
    if (fd < 0)
      {
         Eina_List *l;
diff --git a/src/bin/efreet/efreet_icon_cache_create.c 
b/src/bin/efreet/efreet_icon_cache_create.c
index 8ed0fe6..920e28e 100644
--- a/src/bin/efreet/efreet_icon_cache_create.c
+++ b/src/bin/efreet/efreet_icon_cache_create.c
@@ -22,6 +22,10 @@ static int _efreet_icon_cache_log_dom = -1;
 #include "efreet_private.h"
 #include "efreet_cache_private.h"
 
+#ifndef O_BINARY
+# define O_BINARY 0
+#endif
+
 static Eina_Array *exts = NULL;
 static Eina_Array *extra_dirs = NULL;
 static Eina_Array *strs = NULL;
@@ -676,7 +680,7 @@ cache_lock_file(void)
     int lockfd;
 
     snprintf(file, sizeof(file), "%s/efreet/icon_data.lock", 
efreet_cache_home_get());
-    lockfd = open(file, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);
+    lockfd = open(file, O_CREAT | O_BINARY | O_RDWR, S_IRUSR | S_IWUSR);
     if (lockfd < 0) return -1;
     efreet_fsetowner(lockfd);
 
diff --git a/src/examples/ecore/ecore_con_url_download_example.c 
b/src/examples/ecore/ecore_con_url_download_example.c
index 98c7b57..dcf634e 100644
--- a/src/examples/ecore/ecore_con_url_download_example.c
+++ b/src/examples/ecore/ecore_con_url_download_example.c
@@ -10,6 +10,10 @@
 #include <Ecore.h>
 #include <Ecore_Con.h>
 
+#ifndef O_BINARY
+# define O_BINARY 0
+#endif
+
 struct _request
 {
    long size;
@@ -68,7 +72,7 @@ main(int argc, const char *argv[])
         return -1;
      }
 
-   fd = open(filename, O_CREAT | O_WRONLY | O_TRUNC, 0644);
+   fd = open(filename, O_CREAT | O_BINARY | O_WRONLY | O_TRUNC, 0644);
 
    if (fd == -1)
      {
diff --git a/src/lib/ecore/ecore.c b/src/lib/ecore/ecore.c
index d9fc9d9..e5a4c4c 100644
--- a/src/lib/ecore/ecore.c
+++ b/src/lib/ecore/ecore.c
@@ -35,6 +35,10 @@
 #include <malloc.h>
 #endif
 
+#ifndef O_BINARY
+# define O_BINARY 0
+#endif
+
 static Ecore_Version _version = { VMAJ, VMIN, VMIC, VREV };
 EAPI Ecore_Version *ecore_version = &_version;
 
@@ -777,11 +781,11 @@ _ecore_fps_debug_init(void)
    tmp = eina_environment_tmp_get();
    pid = (int)getpid();
    snprintf(buf, sizeof(buf), "%s/.ecore_fps_debug-%i", tmp, pid);
-   _ecore_fps_debug_fd = open(buf, O_CREAT | O_TRUNC | O_RDWR, 0644);
+   _ecore_fps_debug_fd = open(buf, O_CREAT | O_BINARY | O_TRUNC | O_RDWR, 
0644);
    if (_ecore_fps_debug_fd < 0)
      {
         unlink(buf);
-        _ecore_fps_debug_fd = open(buf, O_CREAT | O_TRUNC | O_RDWR, 0644);
+        _ecore_fps_debug_fd = open(buf, O_CREAT | O_BINARY | O_TRUNC | O_RDWR, 
0644);
      }
    if (_ecore_fps_debug_fd >= 0)
      {
diff --git a/src/lib/ecore_evas/ecore_evas.c b/src/lib/ecore_evas/ecore_evas.c
index befa11b..076b3f5 100644
--- a/src/lib/ecore_evas/ecore_evas.c
+++ b/src/lib/ecore_evas/ecore_evas.c
@@ -34,6 +34,10 @@
 #include "ecore_evas_extn.h"
 #include "ecore_evas_win32.h"
 
+#ifndef O_BINARY
+# define O_BINARY 0
+#endif
+
 EAPI Eina_Bool _ecore_evas_app_comp_sync = EINA_FALSE;
 EAPI int _ecore_evas_log_dom = -1;
 static int _ecore_evas_init_count = 0;
@@ -2973,11 +2977,11 @@ _ecore_evas_fps_debug_init(void)
 
    snprintf(buf, sizeof(buf), "%s/.ecore_evas_fps_debug-%i",
             eina_environment_tmp_get(), (int)getpid());
-   _ecore_evas_fps_debug_fd = open(buf, O_CREAT | O_TRUNC | O_RDWR, 0644);
+   _ecore_evas_fps_debug_fd = open(buf, O_CREAT | O_BINARY | O_TRUNC | O_RDWR, 
0644);
    if (_ecore_evas_fps_debug_fd < 0)
      {
         unlink(buf);
-        _ecore_evas_fps_debug_fd = open(buf, O_CREAT | O_TRUNC | O_RDWR, 0644);
+        _ecore_evas_fps_debug_fd = open(buf, O_CREAT | O_BINARY | O_TRUNC | 
O_RDWR, 0644);
      }
    if (_ecore_evas_fps_debug_fd >= 0)
      {
diff --git a/src/modules/ecore_buffer/shm/ecore_buffer_shm.c 
b/src/modules/ecore_buffer/shm/ecore_buffer_shm.c
index 75900ea..6440071 100644
--- a/src/modules/ecore_buffer/shm/ecore_buffer_shm.c
+++ b/src/modules/ecore_buffer/shm/ecore_buffer_shm.c
@@ -14,6 +14,10 @@
 #include <Ecore.h>
 #include <Ecore_Buffer.h>
 
+#ifndef O_BINARY
+# define O_BINARY 0
+#endif
+
 typedef struct _Ecore_Buffer_Shm_Data Ecore_Buffer_Shm_Data;
 
 struct _Ecore_Buffer_Shm_Data {
@@ -102,7 +106,7 @@ _ecore_buffer_shm_buffer_export(Ecore_Buffer_Module_Data 
bmdata EINA_UNUSED, Eco
    Ecore_Buffer_Shm_Data* b = bdata;
    int fd;
 
-   fd = open(b->file, O_RDWR | O_CLOEXEC);
+   fd = open(b->file, O_RDWR | O_BINARY | O_CLOEXEC);
    if (id) *id = fd;
 
    return EXPORT_TYPE_FD;
diff --git a/src/modules/ecore_evas/engines/extn/ecore_evas_extn_buf.c 
b/src/modules/ecore_evas/engines/extn/ecore_evas_extn_buf.c
index 245534f..28ffcc3 100644
--- a/src/modules/ecore_evas/engines/extn/ecore_evas_extn_buf.c
+++ b/src/modules/ecore_evas/engines/extn/ecore_evas_extn_buf.c
@@ -1,5 +1,9 @@
 #include "ecore_evas_extn_engine.h"
 
+#ifndef O_BINARY
+# define O_BINARY 0
+#endif
+
 struct _Extnbuf
 {
    const char *file, *lock;
@@ -165,7 +169,7 @@ _extnbuf_lock_file_set(Extnbuf *b, const char *file)
      }
    b->lock = eina_stringshare_add(file);
    if (!b->lock) goto err;
-   b->lockfd = open(b->lock, O_RDWR);
+   b->lockfd = open(b->lock, O_RDWR | O_BINARY);
    if (b->lockfd >= 0) return EINA_TRUE;
 err:
    if (b->lock) eina_stringshare_del(b->lock);
diff --git a/src/modules/evas/image_loaders/generic/evas_image_load_generic.c 
b/src/modules/evas/image_loaders/generic/evas_image_load_generic.c
index 78488d1..3bca7c5 100644
--- a/src/modules/evas/image_loaders/generic/evas_image_load_generic.c
+++ b/src/modules/evas/image_loaders/generic/evas_image_load_generic.c
@@ -16,6 +16,10 @@
 #include <fcntl.h>
 #include <ctype.h>
 
+#ifndef O_BINARY
+# define O_BINARY 0
+#endif
+
 typedef struct _Evas_Loader_Internal Evas_Loader_Internal;
 struct _Evas_Loader_Internal
 {
@@ -329,7 +333,7 @@ getdata:
 
              // open
              if (tmpfname)
-                fd = open(tmpfname, O_RDONLY, S_IRUSR);
+                fd = open(tmpfname, O_RDONLY | O_BINARY, S_IRUSR);
 #ifdef HAVE_SHM_OPEN
              else if (shmfname)
                 fd = shm_open(shmfname, O_RDONLY, S_IRUSR);
diff --git a/src/tests/ecore/ecore_test_ecore_file.c 
b/src/tests/ecore/ecore_test_ecore_file.c
index 1e2d801..28ffb83 100644
--- a/src/tests/ecore/ecore_test_ecore_file.c
+++ b/src/tests/ecore/ecore_test_ecore_file.c
@@ -15,6 +15,10 @@
 
 #include "ecore_suite.h"
 
+#ifndef O_BINARY
+# define O_BINARY 0
+#endif
+
 #define MAXSIZE 256
 
 void
@@ -242,7 +246,7 @@ START_TEST(ecore_test_ecore_file_operations)
    src_file = get_tmp_file();
    fail_if(!src_file);
    fail_if(ecore_file_remove(src_file) != EINA_TRUE);
-   fd = open(src_file, O_RDWR|O_CREAT, 0700);
+   fd = open(src_file, O_RDWR | O_BINARY | O_CREAT, 0700);
    fail_if(fd < 0);
    fail_if(close(fd) != 0);
    fail_if(ecore_file_can_exec(src_file) != EINA_TRUE);
@@ -295,7 +299,7 @@ START_TEST(ecore_test_ecore_file_operations)
    src_file = get_tmp_file();
    fail_if(!src_file);
    fail_if(ecore_file_remove(src_file) != EINA_TRUE);
-   fd = open(src_file, O_RDWR|O_CREAT, 0400);
+   fd = open(src_file, O_RDWR | O_BINARY | O_CREAT, 0400);
    fail_if(fd < 0);
    fail_if(close(fd) != 0);
    fail_if(ecore_file_can_read(src_file) != EINA_TRUE);
@@ -306,7 +310,7 @@ START_TEST(ecore_test_ecore_file_operations)
    src_file = get_tmp_file();
    fail_if(!src_file);
    fail_if(ecore_file_remove(src_file) != EINA_TRUE);
-   fd = open(src_file, O_RDWR|O_CREAT, 0200);
+   fd = open(src_file, O_RDWR | O_BINARY | O_CREAT, 0200);
    fail_if(fd < 0);
    fail_if(close(fd) != 0);
    fail_if(ecore_file_can_read(src_file) != EINA_FALSE);
@@ -316,7 +320,7 @@ START_TEST(ecore_test_ecore_file_operations)
    src_file = get_tmp_file();
    fail_if(!src_file);
    fail_if(ecore_file_remove(src_file) != EINA_TRUE);
-   fd = open(src_file, O_RDWR|O_CREAT, 0100);
+   fd = open(src_file, O_RDWR | O_BINARY | O_CREAT, 0100);
    fail_if(fd < 0);
    fail_if(close(fd) != 0);
    fail_if(ecore_file_can_read(src_file) != EINA_FALSE);
@@ -355,7 +359,7 @@ START_TEST(ecore_test_ecore_file_path)
    src_file = get_tmp_file();
    fail_if(!src_file);
    fail_if(ecore_file_remove(src_file) != EINA_TRUE);
-   fd = open(src_file, O_RDWR|O_CREAT, 0700);
+   fd = open(src_file, O_RDWR | O_BINARY | O_CREAT, 0700);
    fail_if(fd < 0);
    fail_if(close(fd) != 0);
    fail_if(ecore_file_can_exec(src_file) != EINA_TRUE);
diff --git a/src/tests/eet/eet_suite.c b/src/tests/eet/eet_suite.c
index 673294b..e7737a7 100644
--- a/src/tests/eet/eet_suite.c
+++ b/src/tests/eet/eet_suite.c
@@ -17,6 +17,10 @@
 
 #include "eet_suite.h"
 
+#ifndef O_BINARY
+# define O_BINARY 0
+#endif
+
 static char _key_pem[PATH_MAX] = "";
 static char _cert_pem[PATH_MAX] = "";
 static char _key_enc[PATH_MAX] = "";
@@ -1775,7 +1779,7 @@ START_TEST(eet_identity_simple)
    eet_clearcache();
 
    /* Corrupting the file. */
-   fd = open(file, O_WRONLY);
+   fd = open(file, O_WRONLY | O_BINARY);
    fail_if(fd < 0);
 
    fail_if(lseek(fd, 200, SEEK_SET) != 200);
diff --git a/src/tests/eina/eina_test_file.c b/src/tests/eina/eina_test_file.c
index 617ce88..c307b92 100644
--- a/src/tests/eina/eina_test_file.c
+++ b/src/tests/eina/eina_test_file.c
@@ -38,6 +38,10 @@
 # define PATH_SEP_C '/'
 #endif
 
+#ifndef O_BINARY
+# define O_BINARY 0
+#endif
+
 static int default_dir_rights = 0777;
 const int file_min_offset = 1;
 
@@ -353,12 +357,12 @@ START_TEST(eina_file_map_new_test)
    strcpy(test_file2_path, (char *)test_dirname);
    strcat(test_file2_path, test_file2_name_part);
    
-   fd = open(test_file_path, O_WRONLY | O_CREAT | O_TRUNC, S_IWUSR | S_IRUSR);
+   fd = open(test_file_path, O_WRONLY | O_BINARY | O_CREAT | O_TRUNC, S_IWUSR 
| S_IRUSR);
    fail_if(fd == 0);   
    fail_if(write(fd, eina_map_test_string, strlen(eina_map_test_string)) != 
(ssize_t) strlen(eina_map_test_string));
    close(fd);
 
-   fd = open(test_file2_path, O_WRONLY | O_CREAT | O_TRUNC, S_IWUSR | S_IRUSR);
+   fd = open(test_file2_path, O_WRONLY | O_BINARY | O_CREAT | O_TRUNC, S_IWUSR 
| S_IRUSR);
    fail_if(fd == 0);
    fail_if(write(fd, big_buffer, big_buffer_size - file_min_offset) != 
big_buffer_size - file_min_offset);
    close(fd);
@@ -566,7 +570,7 @@ START_TEST(eina_test_file_xattr)
    eina_init();
    test_file_path = get_full_path(XATTR_TEST_DIR, filename);
 
-   fd = open(test_file_path, O_RDONLY | O_CREAT | O_TRUNC, S_IRWXU | S_IRWXG | 
S_IRWXO);
+   fd = open(test_file_path, O_RDONLY | O_BINARY | O_CREAT | O_TRUNC, S_IRWXU 
| S_IRWXG | S_IRWXO);
    fail_if(fd == 0);
    close(fd);
 
@@ -699,12 +703,12 @@ START_TEST(eina_test_file_statat)
    test_file1_path = get_full_path(test_dirname, "example1.txt");
    test_file2_path = get_full_path(test_dirname, "example2.txt");
 
-   fd = open(test_file1_path, O_WRONLY | O_CREAT | O_TRUNC, S_IWUSR | S_IRUSR);
+   fd = open(test_file1_path, O_WRONLY | O_BINARY | O_CREAT | O_TRUNC, S_IWUSR 
| S_IRUSR);
    fail_if(fd == 0);
    fail_if(write(fd, template, template_size) != template_size);
    close(fd);
 
-   fd = open(test_file2_path, O_WRONLY | O_CREAT | O_TRUNC, S_IWUSR | S_IRUSR);
+   fd = open(test_file2_path, O_WRONLY | O_BINARY | O_CREAT | O_TRUNC, S_IWUSR 
| S_IRUSR);
    fail_if(fd == 0);
    fail_if(write(fd, template, template_size) != template_size);
    close(fd);
diff --git a/src/tests/eio/eio_test_file.c b/src/tests/eio/eio_test_file.c
index f0e231c..c17246e 100644
--- a/src/tests/eio/eio_test_file.c
+++ b/src/tests/eio/eio_test_file.c
@@ -14,6 +14,10 @@
 
 #include "eio_suite.h"
 
+#ifndef O_BINARY
+# define O_BINARY 0
+#endif
+
 static unsigned int default_rights = 0755;
 static int test_count = 0;
 static const char *good_dirs[] =
@@ -154,7 +158,7 @@ create_test_dirs(Eina_Tmpstr *test_dirname)
    for (i = 0; i != count; ++i)
      {
         Eina_Tmpstr *filename = get_full_path(test_dirname, files[i]);
-        fd = open(filename, O_RDWR|O_CREAT, default_rights);
+        fd = open(filename, O_RDWR | O_BINARY | O_CREAT, default_rights);
         fail_if(fd < 0);
         fail_if(close(fd) != 0);
         eina_tmpstr_del(filename);
@@ -163,7 +167,7 @@ create_test_dirs(Eina_Tmpstr *test_dirname)
    for (i = 0; i != count; ++i)
      {
         Eina_Tmpstr *filename = get_full_path(nested_dirname, files[i]);
-        fd = open(filename, O_RDWR|O_CREAT, default_rights);
+        fd = open(filename, O_RDWR | O_BINARY | O_CREAT, default_rights);
         fail_if(fd < 0);
         fail_if(close(fd) != 0);
         eina_tmpstr_del(filename);

-- 


Reply via email to