[libdvdnav-devel] [Git][videolan/libdvdread][master] dvd_reader: Use realpath instead of chdir/getcwd
Jean-Baptiste Kempf (@jbk)
gitlab at videolan.org
Mon Jan 3 09:10:03 UTC 2022
Jean-Baptiste Kempf pushed to branch master at VideoLAN / libdvdread
Commits:
21e8964e by Hugo Beauzée-Luyssen at 2022-01-03T09:47:21+01:00
dvd_reader: Use realpath instead of chdir/getcwd
to compute a canonical path
- - - - -
1 changed file:
- src/dvd_reader.c
Changes:
=====================================
src/dvd_reader.c
=====================================
@@ -29,7 +29,7 @@
#include <stdio.h> /* fprintf */
#include <errno.h> /* errno, EIN* */
#include <string.h> /* memcpy, strlen */
-#include <unistd.h> /* chdir, getcwd */
+#include <unistd.h> /* pclose */
#include <limits.h> /* PATH_MAX */
#include <dirent.h> /* opendir, readdir */
#include <ctype.h> /* isalpha */
@@ -549,33 +549,18 @@ static dvd_reader_t *DVDOpenCommon( void *priv,
if( !(path_copy = strdup( path ) ) )
goto DVDOpen_error;
-#ifndef _WIN32 /* don't have fchdir, and getcwd( NULL, ... ) is strange */
+#ifndef _WIN32 /* win32 doesn't have realpath */
/* Also WIN32 does not have symlinks, so we don't need this bit of code. */
/* Resolve any symlinks and get the absolute dir name. */
{
- if( ( cdir = open( ".", O_RDONLY ) ) >= 0 ) {
- int retval;
- if( chdir( path_copy ) == -1 ) {
- goto DVDOpen_error;
- }
- new_path = malloc(PATH_MAX+1);
- if(!new_path) {
- goto DVDOpen_error;
- }
- if( getcwd( new_path, PATH_MAX ) == NULL ) {
- goto DVDOpen_error;
- }
- retval = fchdir( cdir );
- close( cdir );
- cdir = -1;
- if( retval == -1 ) {
+ new_path = realpath( path_copy, NULL );
+ if( new_path == NULL ) {
goto DVDOpen_error;
}
free(path_copy);
path_copy = new_path;
new_path = NULL;
- }
}
#endif
View it on GitLab: https://code.videolan.org/videolan/libdvdread/-/commit/21e8964e71bbc743123c458a3f1a4ff544d1ed6b
--
View it on GitLab: https://code.videolan.org/videolan/libdvdread/-/commit/21e8964e71bbc743123c458a3f1a4ff544d1ed6b
You're receiving this email because of your account on code.videolan.org.
More information about the libdvdnav-devel
mailing list