]> granicus.if.org Git - esp-idf/commitdiff
syscall write: Should return number of bytes written
authorAngus Gratton <angus@espressif.com>
Wed, 5 Oct 2016 22:51:51 +0000 (09:51 +1100)
committerAngus Gratton <angus@espressif.com>
Thu, 6 Oct 2016 07:35:08 +0000 (18:35 +1100)
Fixes bug where sometimes output truncates after a newline, or large
chunks of large output buffers are lost.

components/esp32/syscalls.c

index 350f5f41053d4a9d2bd6b6966495033071e51b2f..537efed1d48c5ad74eca06e1eb5bf5946e595f0f 100644 (file)
@@ -143,7 +143,7 @@ int _open_r(struct _reent *r, const char * path, int flags, int mode) {
 }
 
 ssize_t _write_r(struct _reent *r, int fd, const void * data, size_t size) {
-    const char* p = (const char*) data;
+    const char *data_c = (const char *)data;
     if (fd == STDOUT_FILENO) {
         static _lock_t stdout_lock; /* lazily initialised */
         /* Even though newlib does stream locking on stdout, we need
@@ -160,14 +160,13 @@ ssize_t _write_r(struct _reent *r, int fd, const void * data, size_t size) {
            which aren't fully valid.)
         */
         _lock_acquire_recursive(&stdout_lock);
-        while(size--) {
+        for (size_t i = 0; i < size; i++) {
 #if CONFIG_NEWLIB_STDOUT_ADDCR
-            if (*p=='\n') {
+            if (data_c[i]=='\n') {
                 uart_tx_one_char('\r');
             }
 #endif
-            uart_tx_one_char(*p);
-            ++p;
+            uart_tx_one_char(data_c[i]);
         }
         _lock_release_recursive(&stdout_lock);
     }