From 09db2e6c3788d7582b1862c3cab1617e49e2758e Mon Sep 17 00:00:00 2001 From: "Earle F. Philhower, III" Date: Sat, 11 Feb 2023 11:57:27 -0800 Subject: [PATCH] Apply SD.h fix from ESP8266 (#1171) Pull in the portion of the change correcting the flag setting from https://github.com/esp8266/Arduino/pull/8833 --- libraries/SD/src/SD.h | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/libraries/SD/src/SD.h b/libraries/SD/src/SD.h index 925d1ba00..fc1338d18 100644 --- a/libraries/SD/src/SD.h +++ b/libraries/SD/src/SD.h @@ -162,9 +162,23 @@ class SDClass { private: const char *getMode(uint8_t mode) { - bool read = (mode & O_READ) ? true : false; - bool write = (mode & O_WRITE) ? true : false; - bool append = (mode & O_APPEND) ? true : false; + bool read = false; + bool write = false; + + switch (mode & O_ACCMODE) { + case O_RDONLY: + read = true; + break; + case O_WRONLY: + write = true; + break; + case O_RDWR: + read = true; + write = true; + break; + } + const bool append = (mode & O_APPEND) > 0; + if (read & !write) { return "r"; } else if (!read & write & !append) {