Subject: windows: fops write support
authorJoel Winarske <joel.winarske@gmail.com>
Wed, 19 Apr 2017 21:55:21 +0000 (14:55 -0700)
committerAndy Green <andy@warmcat.com>
Wed, 19 Apr 2017 23:24:09 +0000 (07:24 +0800)
lib/libwebsockets.h
lib/lws-plat-win.c

index a291946..f673c1e 100644 (file)
@@ -84,6 +84,9 @@ struct sockaddr_in;
 
 #define LWS_INVALID_FILE INVALID_HANDLE_VALUE
 #define LWS_O_RDONLY _O_RDONLY
+#define LWS_O_WRONLY _O_WRONLY
+#define LWS_O_CREAT _O_CREAT
+#define LWS_O_TRUNC _O_TRUNC
 
 #if !defined(__MINGW32__) && (!defined(_MSC_VER) || _MSC_VER < 1900) /* Visual Studio 2015 already defines this in <stdio.h> */
 #define lws_snprintf _snprintf
@@ -106,6 +109,9 @@ struct sockaddr_in;
 
 #define LWS_INLINE inline
 #define LWS_O_RDONLY O_RDONLY
+#define LWS_O_WRONLY O_WRONLY
+#define LWS_O_CREAT O_CREAT
+#define LWS_O_TRUNC O_TRUNC
 
 #if !defined(LWS_WITH_ESP8266) && !defined(OPTEE_TA) && !defined(LWS_WITH_ESP32)
 #include <poll.h>
index b8dd4f0..2c74a18 100644 (file)
@@ -538,8 +538,8 @@ _lws_plat_file_open(const struct lws_plat_file_ops *fops, const char *filename,
                ret = CreateFileW(buf, GENERIC_READ, FILE_SHARE_READ,
                          NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
        } else {
-               lwsl_err("%s: open for write not implemented\n", __func__);
-               goto bail;
+               ret = CreateFileW(buf, GENERIC_WRITE, 0, NULL,
+                         CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
        }
 
        if (ret == LWS_INVALID_FILE)
@@ -603,16 +603,18 @@ LWS_VISIBLE int
 _lws_plat_file_write(lws_fop_fd_t fop_fd, lws_filepos_t *amount,
                         uint8_t* buf, lws_filepos_t len)
 {
-       (void)fop_fd;
-       (void)amount;
-       (void)buf;
-       (void)len;
+       DWORD _amount;
 
-       fop_fd->pos += len;
+       if (!WriteFile((HANDLE)fop_fd->fd, buf, (DWORD)len, &_amount, NULL)) {
+               *amount = 0;
 
-       lwsl_err("%s: not implemented yet on this platform\n", __func__);
+               return 1;
+       }
 
-       return -1;
+       fop_fd->pos += _amount;
+       *amount = (unsigned long)_amount;
+
+       return 0;
 }
 
 LWS_VISIBLE int