diff options
Diffstat (limited to 'flang/runtime/io-error.cpp')
| -rw-r--r-- | flang/runtime/io-error.cpp | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/flang/runtime/io-error.cpp b/flang/runtime/io-error.cpp index c8f6675c60a6..b006b82f6224 100644 --- a/flang/runtime/io-error.cpp +++ b/flang/runtime/io-error.cpp @@ -16,6 +16,7 @@ #include <cstring> namespace Fortran::runtime::io { +RT_OFFLOAD_API_GROUP_BEGIN void IoErrorHandler::SignalError(int iostatOrErrno, const char *msg, ...) { // Note that IOMSG= alone without IOSTAT=/END=/EOR=/ERR= does not suffice @@ -44,12 +45,17 @@ void IoErrorHandler::SignalError(int iostatOrErrno, const char *msg, ...) { if (ioStat_ <= 0) { ioStat_ = iostatOrErrno; // priority over END=/EOR= if (msg && (flags_ & hasIoMsg)) { +#if !defined(RT_DEVICE_COMPILATION) char buffer[256]; va_list ap; va_start(ap, msg); std::vsnprintf(buffer, sizeof buffer, msg, ap); - ioMsg_ = SaveDefaultCharacter(buffer, std::strlen(buffer) + 1, *this); va_end(ap); +#else + const char *buffer = "not implemented yet: IOSTAT with varargs"; +#endif + ioMsg_ = SaveDefaultCharacter( + buffer, Fortran::runtime::strlen(buffer) + 1, *this); } } return; @@ -58,15 +64,23 @@ void IoErrorHandler::SignalError(int iostatOrErrno, const char *msg, ...) { } // I/O error not caught! if (msg) { +#if !defined(RT_DEVICE_COMPILATION) va_list ap; va_start(ap, msg); CrashArgs(msg, ap); va_end(ap); +#else + Crash("not implemented yet: IOSTAT with varargs"); +#endif } else if (const char *errstr{IostatErrorString(iostatOrErrno)}) { Crash(errstr); } else { +#if !defined(RT_DEVICE_COMPILATION) Crash("I/O error (errno=%d): %s", iostatOrErrno, std::strerror(iostatOrErrno)); +#else + Crash("I/O error (errno=%d)", iostatOrErrno); +#endif } } @@ -85,8 +99,6 @@ void IoErrorHandler::Forward( } } -void IoErrorHandler::SignalErrno() { SignalError(errno); } - void IoErrorHandler::SignalEnd() { SignalError(IostatEnd); } void IoErrorHandler::SignalEor() { SignalError(IostatEor); } @@ -97,6 +109,10 @@ void IoErrorHandler::SignalPendingError() { SignalError(error); } +RT_OFFLOAD_API_GROUP_END + +void IoErrorHandler::SignalErrno() { SignalError(errno); } + bool IoErrorHandler::GetIoMsg(char *buffer, std::size_t bufferLength) { const char *msg{ioMsg_.get()}; if (!msg) { @@ -132,7 +148,7 @@ bool IoErrorHandler::GetIoMsg(char *buffer, std::size_t bufferLength) { ToFortranDefaultCharacter(buffer, bufferLength, msg); return true; } else if (ok) { - std::size_t copied{std::strlen(buffer)}; + std::size_t copied{Fortran::runtime::strlen(buffer)}; if (copied < bufferLength) { std::memset(buffer + copied, ' ', bufferLength - copied); } |
