[libdvdnav-devel] [Git][videolan/libdvdread][master] 2 commits: file: regroup the platform filesystem functions in a single file

Jean-Baptiste Kempf (@jbk) gitlab at videolan.org
Fri Jul 17 09:43:25 UTC 2026



Jean-Baptiste Kempf pushed to branch master at VideoLAN / libdvdread


Commits:
34ea1d34 by Saifelden Mohamed Ismail at 2026-07-16T17:18:22+03:00
file: regroup the platform filesystem functions in a single file

- - - - -
abac4e27 by Saifelden Mohamed Ismail at 2026-07-16T17:18:36+03:00
file: keep the default filesystem helpers internal

- - - - -


9 changed files:

- − src/file/dir_posix.c
- − src/file/dir_win32.c
- src/file/file_posix.c
- src/file/file_win32.c
- − src/file/filesystem.c
- src/file/filesystem.h
- − src/file/stat_posix.c
- − src/file/stat_win32.c
- src/meson.build


Changes:

=====================================
src/file/dir_posix.c deleted
=====================================
@@ -1,79 +0,0 @@
-/*
- * This file is part of libdvdread
- * Copyright (C) 2022 VideoLAN
- *
- * This file is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This file is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library. If not, see
- * <http://www.gnu.org/licenses/>.
- */
-
-#include "config.h"
-
-#include <stdlib.h>
-#include <string.h>
-#if HAVE_DIRENT_H
-#include <dirent.h>
-#endif
-
-#if defined(__GLIBC__) && defined(__GLIBC_MINOR__)
-#  if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 24)
-#    define USE_READDIR
-#    include <errno.h>
-#  endif
-#endif
-
-#include <dvdread/dvd_filesystem.h>
-#include "filesystem.h"
-
-void *dir_open_default(dvd_reader_filesystem_h *fs, const char* dirname)
-{
-    if (!fs)
-        return NULL;
-
-    return opendir(dirname);
-}
-
-int dir_read_default(void *dir, dvd_dirent_t *entry)
-{
-    struct dirent *p_e;
-
-#ifdef USE_READDIR
-    errno = 0;
-    p_e = readdir((DIR*)dir);
-    if (!p_e && errno) {
-        return -errno;
-    }
-#else /* USE_READDIR */
-    int result;
-    struct dirent e;
-
-    result = readdir_r((DIR*)dir, &e, &p_e);
-    if (result) {
-        return -result;
-    }
-#endif /* USE_READDIR */
-
-    if (p_e == NULL) {
-        return 1;
-    }
-    strncpy(entry->d_name, p_e->d_name, sizeof(entry->d_name));
-    entry->d_name[sizeof(entry->d_name) - 1] = 0;
-
-    return 0;
-}
-
-void dir_close_default(void *dir)
-{
-    if (dir)
-        closedir((DIR *)dir);
-}


=====================================
src/file/dir_win32.c deleted
=====================================
@@ -1,96 +0,0 @@
-/*
- * This file is part of libdvdread
- * Copyright (C) 2022 VideoLAN
- *
- * This file is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This file is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library. If not, see
- * <http://www.gnu.org/licenses/>.
- */
-
-#include <io.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdio.h>
-
-#include <windows.h>
-#include "../msvc/contrib/win32_cs.h"
-
-
-#include <dvdread/dvd_filesystem.h>
-#include "filesystem.h"
-
-
-typedef struct {
-  intptr_t handle;
-  struct _wfinddata_t went;
-} win32_dir_t;
-
-
-void *dir_open_default(dvd_reader_filesystem_h *fs, const char* dirname)
-{
-    if (!fs)
-        return NULL;
-
-    char    *filespec;
-    wchar_t *wfilespec;
-    win32_dir_t *d = calloc(1, sizeof(*d));
-
-    if (!d) {
-        return NULL;
-    }
-
-    filespec = malloc(strlen(dirname) + 3);
-    if (!filespec) {
-        goto fail;
-    }
-    sprintf(filespec, "%s\\*", dirname);
-
-    wfilespec = _utf8_to_wchar(filespec);
-    free(filespec);
-    if (!wfilespec) {
-        goto fail;
-    }
-
-    d->handle = _wfindfirst(wfilespec, &d->went);
-    free(wfilespec);
-    if (d->handle != -1) {
-        return d;
-    }
-
-    fail:
-        free(d);
-        return NULL;
-}
-
-int dir_read_default(void *dir, dvd_dirent_t *entry)
-{
-    win32_dir_t *wdir = (win32_dir_t*)dir;
-    if (wdir->went.name[0]) {
-        if (!WideCharToMultiByte(CP_UTF8, 0, wdir->went.name, -1, entry->d_name, sizeof(entry->d_name), NULL, NULL))
-            entry->d_name[0] = 0; /* allow reading next */
-        wdir->went.name[0] = 0;
-        _wfindnext(wdir->handle, &wdir->went);
-        return 0;
-    }
-    /* end of directory, use a positive value so callers can tell it apart from an error */
-    return 1;
-}
-
-void dir_close_default(void *dir)
-{
-    if (dir) {
-        win32_dir_t *wdir = (win32_dir_t*)dir;
-        _findclose(wdir->handle);
-        free(wdir);
-    }
-}


=====================================
src/file/file_posix.c
=====================================
@@ -17,15 +17,26 @@
  * <http://www.gnu.org/licenses/>.
  */
 
+#include "config.h"
 
 #include <stdlib.h>
 #include <unistd.h>
 #include <stdio.h>
+#include <string.h>
 #include <errno.h>
 
 
 #include <sys/stat.h>
 #include <fcntl.h>
+#if HAVE_DIRENT_H
+#include <dirent.h>
+#endif
+
+#if defined(__GLIBC__) && defined(__GLIBC_MINOR__)
+#  if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 24)
+#    define USE_READDIR
+#  endif
+#endif
 
 #include <dvdread/dvd_filesystem.h>
 
@@ -43,7 +54,7 @@
 #endif
 
 
-void *file_open_default(dvd_reader_filesystem_h *fs, const char* filename)
+static void *file_open_default(dvd_reader_filesystem_h *fs, const char* filename)
 {
     if (!fs)
         return NULL;
@@ -80,7 +91,7 @@ void *file_open_default(dvd_reader_filesystem_h *fs, const char* filename)
     return handle;
 }
 
-ssize_t file_read_default(void *file, char *buf, size_t size)
+static ssize_t file_read_default(void *file, char *buf, size_t size)
 {
     if (size == 0) {
         return 0;
@@ -89,12 +100,12 @@ ssize_t file_read_default(void *file, char *buf, size_t size)
     return read(*(int*)file, buf, size);
 }
 
-off64_t file_seek_default(void *file, off64_t offset, int whence)
+static off64_t file_seek_default(void *file, off64_t offset, int whence)
 {
     return lseek(*(int*)file, offset, whence);
 }
 
-int file_close_default(void *file)
+static int file_close_default(void *file)
 {
     if (file) {
         int ret = close(*(int*)file);
@@ -103,3 +114,81 @@ int file_close_default(void *file)
     }
     return 0;
 }
+
+static void *dir_open_default(dvd_reader_filesystem_h *fs, const char* dirname)
+{
+    if (!fs)
+        return NULL;
+
+    return opendir(dirname);
+}
+
+static int dir_read_default(void *dir, dvd_dirent_t *entry)
+{
+    struct dirent *p_e;
+
+#ifdef USE_READDIR
+    errno = 0;
+    p_e = readdir((DIR*)dir);
+    if (!p_e && errno) {
+        return -errno;
+    }
+#else /* USE_READDIR */
+    int result;
+    struct dirent e;
+
+    result = readdir_r((DIR*)dir, &e, &p_e);
+    if (result) {
+        return -result;
+    }
+#endif /* USE_READDIR */
+
+    if (p_e == NULL) {
+        return 1;
+    }
+    strncpy(entry->d_name, p_e->d_name, sizeof(entry->d_name));
+    entry->d_name[sizeof(entry->d_name) - 1] = 0;
+
+    return 0;
+}
+
+static void dir_close_default(void *dir)
+{
+    if (dir)
+        closedir((DIR *)dir);
+}
+
+static int stat_default(dvd_reader_filesystem_h *fs, const char *path, dvdstat_t* statbuf)
+{
+    if (!fs)
+        return -1;
+
+    struct stat posixstatbuf;
+    int ret = stat(path, &posixstatbuf);
+    if (ret == 0) {
+        statbuf->size = posixstatbuf.st_size;
+        statbuf->st_mode = posixstatbuf.st_mode;
+    }
+    return ret;
+}
+
+static void default_filesystem_close(dvd_reader_filesystem_h *fs) {
+  free(fs);
+}
+
+dvd_reader_filesystem_h* InitInternalFilesystem(void) {
+  dvd_reader_filesystem_h* fs = calloc( 1, sizeof(dvd_reader_filesystem_h));
+  if (!fs) {
+    return NULL;
+  }
+  fs->close = default_filesystem_close;
+  fs->stat = stat_default;
+  fs->dir_open = dir_open_default;
+  fs->dir_read = dir_read_default;
+  fs->dir_close = dir_close_default;
+  fs->file_open = file_open_default;
+  fs->file_read = file_read_default;
+  fs->file_seek = file_seek_default;
+  fs->file_close = file_close_default;
+  return fs;
+}


=====================================
src/file/file_win32.c
=====================================
@@ -17,14 +17,19 @@
  * <http://www.gnu.org/licenses/>.
  */
 
+#include <io.h>
 #include <stdlib.h>
 #include <unistd.h>
 #include <stdio.h>
+#include <string.h>
 #include <errno.h>
 
 #include <sys/stat.h>
 #include <fcntl.h>
 
+/* mingw sys/stat.h defines stat as a macro, keep the struct member usable */
+#undef stat
+
 #include <windows.h>
 #include "../msvc/contrib/win32_cs.h"
 
@@ -32,7 +37,7 @@
 #include "filesystem.h"
 
 
-void *file_open_default(dvd_reader_filesystem_h *fs, const char* filename)
+static void *file_open_default(dvd_reader_filesystem_h *fs, const char* filename)
 {
     if (!fs)
         return NULL;
@@ -62,7 +67,7 @@ void *file_open_default(dvd_reader_filesystem_h *fs, const char* filename)
     return handle;
 }
 
-ssize_t file_read_default(void *file, char *buf, size_t size)
+static ssize_t file_read_default(void *file, char *buf, size_t size)
 {
     if (size == 0) {
         return 0;
@@ -71,12 +76,12 @@ ssize_t file_read_default(void *file, char *buf, size_t size)
     return read(*(int*)file, buf, size);
 }
 
-off64_t file_seek_default(void *file, off64_t offset, int whence)
+static off64_t file_seek_default(void *file, off64_t offset, int whence)
 {
     return _lseeki64(*(int*)file, offset, whence);
 }
 
-int file_close_default(void *file)
+static int file_close_default(void *file)
 {
     if (file) {
         int ret = close(*(int*)file);
@@ -85,3 +90,116 @@ int file_close_default(void *file)
     }
     return 0;
 }
+
+typedef struct {
+  intptr_t handle;
+  struct _wfinddata_t went;
+} win32_dir_t;
+
+static void *dir_open_default(dvd_reader_filesystem_h *fs, const char* dirname)
+{
+    if (!fs)
+        return NULL;
+
+    char    *filespec;
+    wchar_t *wfilespec;
+    win32_dir_t *d = calloc(1, sizeof(*d));
+
+    if (!d) {
+        return NULL;
+    }
+
+    filespec = malloc(strlen(dirname) + 3);
+    if (!filespec) {
+        goto fail;
+    }
+    sprintf(filespec, "%s\\*", dirname);
+
+    wfilespec = _utf8_to_wchar(filespec);
+    free(filespec);
+    if (!wfilespec) {
+        goto fail;
+    }
+
+    d->handle = _wfindfirst(wfilespec, &d->went);
+    free(wfilespec);
+    if (d->handle != -1) {
+        return d;
+    }
+
+    fail:
+        free(d);
+        return NULL;
+}
+
+static int dir_read_default(void *dir, dvd_dirent_t *entry)
+{
+    win32_dir_t *wdir = (win32_dir_t*)dir;
+    if (wdir->went.name[0]) {
+        if (!WideCharToMultiByte(CP_UTF8, 0, wdir->went.name, -1, entry->d_name, sizeof(entry->d_name), NULL, NULL))
+            entry->d_name[0] = 0; /* allow reading next */
+        wdir->went.name[0] = 0;
+        _wfindnext(wdir->handle, &wdir->went);
+        return 0;
+    }
+    /* end of directory, use a positive value so callers can tell it apart from an error */
+    return 1;
+}
+
+static void dir_close_default(void *dir)
+{
+    if (dir) {
+        win32_dir_t *wdir = (win32_dir_t*)dir;
+        _findclose(wdir->handle);
+        free(wdir);
+    }
+}
+
+static int stat_default(dvd_reader_filesystem_h *fs, const char *path, dvdstat_t* statbuf)
+{
+    if (!fs)
+        return -1;
+
+    struct _stat64 win32statbuf;
+
+    wchar_t *wpath, *it;
+
+    wpath = _utf8_to_wchar(path);
+    if (!wpath) {
+        return -1;
+    }
+
+    /* need to strip possible trailing \\ */
+    for (it = wpath; *it; it++)
+        if ((*it == '\\' || *it == '/') && *(it+1) == 0)
+        *it = 0;
+
+    int ret = _wstat64(wpath, &win32statbuf);
+    free(wpath);
+    if (ret == 0) {
+        statbuf->size = win32statbuf.st_size;
+        statbuf->st_mode = win32statbuf.st_mode;
+    }
+    return ret;
+}
+
+static void default_filesystem_close(dvd_reader_filesystem_h *fs) {
+  free(fs);
+}
+
+dvd_reader_filesystem_h* InitInternalFilesystem(void) {
+  dvd_reader_filesystem_h* fs = calloc( 1, sizeof(dvd_reader_filesystem_h));
+  if (!fs) {
+    return NULL;
+  }
+  fs->close = default_filesystem_close;
+  fs->stat = stat_default;
+  fs->dir_open = dir_open_default;
+  fs->dir_read = dir_read_default;
+  fs->dir_close = dir_close_default;
+  fs->file_open = file_open_default;
+  fs->file_read = file_read_default;
+  fs->file_seek = file_seek_default;
+  fs->file_close = file_close_default;
+  return fs;
+}


=====================================
src/file/filesystem.c deleted
=====================================
@@ -1,42 +0,0 @@
-/*
- * This file is part of libdvdread.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation; either version 2.1 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
- */
-
-#include "filesystem.h"
-
-#include <stdlib.h>
-
-static void default_filesystem_close(dvd_reader_filesystem_h *fs) {
-  free(fs);
-}
-
-dvd_reader_filesystem_h* InitInternalFilesystem(void) {
-  dvd_reader_filesystem_h* fs = calloc( 1, sizeof(dvd_reader_filesystem_h));
-  if (!fs) {
-    return NULL;
-  }
-  fs->close = default_filesystem_close;
-  fs->stat = stat_default;
-  fs->dir_open = dir_open_default;
-  fs->dir_read = dir_read_default;
-  fs->dir_close = dir_close_default;
-  fs->file_open = file_open_default;
-  fs->file_read = file_read_default;
-  fs->file_seek = file_seek_default;
-  fs->file_close = file_close_default;
-  return fs;
-}


=====================================
src/file/filesystem.h
=====================================
@@ -21,18 +21,6 @@
 
 #include "dvdread/dvd_filesystem.h"
 
-/* default filesystem operations, each platform provides its own */
-void   *file_open_default(dvd_reader_filesystem_h *fs, const char* filename);
-ssize_t file_read_default(void *file, char *buf, size_t size);
-off64_t file_seek_default(void *file, off64_t offset, int whence);
-int     file_close_default(void *file);
-
-void   *dir_open_default(dvd_reader_filesystem_h *fs, const char* dirname);
-int     dir_read_default(void *dir, dvd_dirent_t *entry);
-void    dir_close_default(void *dir);
-
-int     stat_default(dvd_reader_filesystem_h *fs, const char *path, dvdstat_t* statbuf);
-
 /* set up the internal filesystem bundled with libdvdread */
 dvd_reader_filesystem_h* InitInternalFilesystem(void);
 


=====================================
src/file/stat_posix.c deleted
=====================================
@@ -1,38 +0,0 @@
-/*
- * This file is part of libdvdread
- * Copyright (C) 2022 VideoLAN
- *
- * This file is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This file is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library. If not, see
- * <http://www.gnu.org/licenses/>.
- */
-
-#include <stdlib.h>
-#include <sys/stat.h>
-
-#include <dvdread/dvd_filesystem.h>
-#include "filesystem.h"
-
-int stat_default(dvd_reader_filesystem_h *fs, const char *path, dvdstat_t* statbuf)
-{
-    if (!fs)
-        return -1;
-
-    struct stat posixstatbuf;
-    int ret = stat(path, &posixstatbuf);
-    if (ret == 0) {
-        statbuf->size = posixstatbuf.st_size;
-        statbuf->st_mode = posixstatbuf.st_mode;
-    }
-    return ret;
-}


=====================================
src/file/stat_win32.c deleted
=====================================
@@ -1,56 +0,0 @@
-/*
- * This file is part of libdvdread
- * Copyright (C) 2022 VideoLAN
- *
- * This file is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This file is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library. If not, see
- * <http://www.gnu.org/licenses/>.
- */
-
-#include <stdlib.h>
-#include <sys/stat.h>
-
-#include <windows.h>
-#include "../msvc/contrib/win32_cs.h"
-
-#include <dvdread/dvd_filesystem.h>
-#include "filesystem.h"
-
-
-int stat_default(dvd_reader_filesystem_h *fs, const char *path, dvdstat_t* statbuf)
-{
-    if (!fs)
-        return -1;
-
-    struct _stat64 win32statbuf;
-
-    wchar_t *wpath, *it;
-
-    wpath = _utf8_to_wchar(path);
-    if (!wpath) {
-        return -1;
-    }
-
-    /* need to strip possible trailing \\ */
-    for (it = wpath; *it; it++)
-        if ((*it == '\\' || *it == '/') && *(it+1) == 0)
-        *it = 0;
-
-    int ret = _wstat64(wpath, &win32statbuf);
-    free(wpath);
-    if (ret == 0) {
-        statbuf->size = win32statbuf.st_size;
-        statbuf->st_mode = win32statbuf.st_mode;
-    }
-    return ret;
-}


=====================================
src/meson.build
=====================================
@@ -13,22 +13,13 @@ dvdread_src = files(
     'md5.c',
     'nav_print.c',
     'nav_read.c',
-    'file/filesystem.c',
 )
 
 # Platform-specific filesystem implementation
 if host_machine.system() == 'windows'
-    dvdread_src += files(
-        'file/dir_win32.c',
-        'file/file_win32.c',
-        'file/stat_win32.c',
-    )
+    dvdread_src += files('file/file_win32.c')
 else
-    dvdread_src += files(
-        'file/dir_posix.c',
-        'file/file_posix.c',
-        'file/stat_posix.c',
-    )
+    dvdread_src += files('file/file_posix.c')
 endif
 
 #



View it on GitLab: https://code.videolan.org/videolan/libdvdread/-/compare/97c3d8f6157ecb745a55be9886308dabe1daad24...abac4e274fa2dfcb9dfc6451cfb59618f196b854

-- 
View it on GitLab: https://code.videolan.org/videolan/libdvdread/-/compare/97c3d8f6157ecb745a55be9886308dabe1daad24...abac4e274fa2dfcb9dfc6451cfb59618f196b854
You're receiving this email because of your account on code.videolan.org. Manage all notifications: https://code.videolan.org/-/profile/notifications | Help: https://code.videolan.org/help




More information about the libdvdnav-devel mailing list