# SDL: Added detail about why a file couldn't be opened (thanks mgerhardy!) (44927)

**URL:** <https://discourse.libsdl.org/t/sdl-added-detail-about-why-a-file-couldnt-be-opened-thanks-mgerhardy-44927/53414>\
**Category:** SDL Commits\
**Created:** [August 6, 2024, 12:50pm UTC](https://discourse.libsdl.org/t/sdl-added-detail-about-why-a-file-couldnt-be-opened-thanks-mgerhardy-44927/53414 "2024-08-06T12:50:02Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![SDLPushPostBot](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/sdlpushpostbot/32/4370_2.png) [@SDLPushPostBot](https://discourse.libsdl.org/u/SDLPushPostBot)\
**Post date:** [August 6, 2024, 12:50pm UTC](https://discourse.libsdl.org/t/sdl-added-detail-about-why-a-file-couldnt-be-opened-thanks-mgerhardy-44927/53414/1 "2024-08-06T12:50:02Z")

</div>

> <https://github.com/libsdl-org/SDL/commit/44927fe5e3765e5a1e20eb74461f7f63e24f68d0>
>
> Fixes https://github.com/libsdl-org/SDL/issues/10484
> 
> (cherry picked from commit… 15120133202da5980c17b4bf363b5fdb6f32de6b)

```diff
From 44927fe5e3765e5a1e20eb74461f7f63e24f68d0 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Tue, 6 Aug 2024 05:45:48 -0700
Subject: [PATCH] Added detail about why a file couldn't be opened (thanks
 mgerhardy!)

Fixes https://github.com/libsdl-org/SDL/issues/10484

(cherry picked from commit 15120133202da5980c17b4bf363b5fdb6f32de6b)
---
 src/file/SDL_iostream.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/src/file/SDL_iostream.c b/src/file/SDL_iostream.c
index ef1d21d240c57..d10de2da7954d 100644
--- a/src/file/SDL_iostream.c
+++ b/src/file/SDL_iostream.c
@@ -26,6 +26,7 @@
 
 #ifdef HAVE_STDIO_H
 #include <stdio.h>
+#include <errno.h>
 #include <sys/stat.h>
 #endif
 #ifdef HAVE_LIMITS_H
@@ -565,7 +566,7 @@ SDL_IOStream *SDL_IOFromFile(const char *file, const char *mode)
         FILE *fp = fdopen(fd, mode);
         if (!fp) {
             close(fd);
- SDL_SetError("Unable to open file descriptor (%d) from URI %s", fd, file);
+ SDL_SetError("Unable to open file descriptor (%d) from URI %s: %s", fd, file, strerror(errno));
             return NULL;
         }
 
@@ -655,7 +656,7 @@ SDL_IOStream *SDL_IOFromFile(const char *file, const char *mode)
         #endif
 
         if (!fp) {
- SDL_SetError("Couldn't open %s", file);
+ SDL_SetError("Couldn't open %s: %s", file, strerror(errno));
         } else if (!IsRegularFileOrPipe(fp)) {
             fclose(fp);
             fp = NULL;

```
