diff --git a/src/filesystem/SDL_filesystem.c b/src/filesystem/SDL_filesystem.c index e29e8ae46c..a0568ff95d 100644 --- a/src/filesystem/SDL_filesystem.c +++ b/src/filesystem/SDL_filesystem.c @@ -147,6 +147,9 @@ bool SDL_WatchPathForChanges(const char *path, SDL_FileWatchCallback cb, void *u CHECK_PARAM(!path) { return SDL_InvalidParamError("path"); } + CHECK_PARAM(path[0] == '\0') { + return SDL_InvalidParamError("path"); + } return SDL_SYS_WatchPathForChanges(path, cb, userdata); } diff --git a/src/filesystem/posix/SDL_sysfsops.c b/src/filesystem/posix/SDL_sysfsops.c index 4eaf9ada1b..4b9fdff624 100644 --- a/src/filesystem/posix/SDL_sysfsops.c +++ b/src/filesystem/posix/SDL_sysfsops.c @@ -475,8 +475,8 @@ bool SDL_SYS_WatchPathForChanges(const char *path, SDL_FileWatchCallback cb, voi inotify_fd = -1; return false; } - file_watch_thread = SDL_CreateThread(SDL_FileWatchThread, "SDL_FileWatch", NULL); SDL_SetAtomicInt(&quit_watch_file, 0); + file_watch_thread = SDL_CreateThread(SDL_FileWatchThread, "SDL_FileWatch", NULL); if (!file_watch_thread) { SDL_DestroyHashTable(watch_descriptor_table); watch_descriptor_table = NULL; @@ -495,7 +495,8 @@ bool SDL_SYS_WatchPathForChanges(const char *path, SDL_FileWatchCallback cb, voi watch_entry->callback = cb; watch_entry->user_data = user_data; SDL_memcpy(watch_entry->path, path, slen + 1); - // remove separator at the end of the path + // remove separator at the end of the path, it is added back when + // concatenating directory path and file name if (watch_entry->path[slen - 1] == '/') { watch_entry->path[slen - 1] = '\0'; } @@ -594,7 +595,7 @@ void SDL_SYS_QuitPathWatch(void) { #ifdef HAVE_INOTIFY if (inotify_fd >= 0) { - SDL_SetAtomicInt(&quit_watch_file, 0); + SDL_SetAtomicInt(&quit_watch_file, 1); SDL_WaitThread(file_watch_thread, NULL); close(inotify_fd); inotify_fd = -1;