[libdvdnav-devel] Do not reinvent strdup

Jean-Baptiste Kempf git at videolan.org
Thu Jul 31 01:47:51 CEST 2014


libdvdnav | branch: master | Jean-Baptiste Kempf <jb at videolan.org> | Thu Jul 31 01:47:26 2014 +0200| [b077704654121cb1d08fbd3da5a3b9b58b67b53b] | committer: Jean-Baptiste Kempf

Do not reinvent strdup

Fixes builds for Hurd...

> http://git.videolan.org/gitweb.cgi/libdvdnav.git/?a=commit;h=b077704654121cb1d08fbd3da5a3b9b58b67b53b
---

 src/dvdnav.c          |    7 ++++---
 src/dvdnav_internal.h |    9 +--------
 2 files changed, 5 insertions(+), 11 deletions(-)

diff --git a/src/dvdnav.c b/src/dvdnav.c
index d8da517..33367db 100644
--- a/src/dvdnav.c
+++ b/src/dvdnav.c
@@ -162,9 +162,10 @@ dvdnav_status_t dvdnav_open(dvdnav_t** dest, const char *path) {
     return DVDNAV_STATUS_ERR;
   }
 
-  /* Set the path. FIXME: Is a deep copy 'right' */
-  strncpy(this->path, path, MAX_PATH_LEN - 1);
-  this->path[MAX_PATH_LEN - 1] = '\0';
+  /* Set the path. */
+  this->path = strdup(path);
+  if(!this->path)
+    return DVDNAV_STATUS_ERR;
 
   /* Pre-open and close a file so that the CSS-keys are cached. */
   this->file = DVDOpenFile(vm_get_dvd_reader(this->vm), 0, DVD_READ_MENU_VOBS);
diff --git a/src/dvdnav_internal.h b/src/dvdnav_internal.h
index 7161202..534ccb8 100644
--- a/src/dvdnav_internal.h
+++ b/src/dvdnav_internal.h
@@ -72,13 +72,6 @@ static inline int _private_gettimeofday( struct timeval *tv, void *tz )
 /* Maximum length of an error string */
 #define MAX_ERR_LEN 255
 
-/* Use the POSIX PATH_MAX if available */
-#ifdef PATH_MAX
-#define MAX_PATH_LEN PATH_MAX
-#else
-#define MAX_PATH_LEN 255 /* Arbitrary */
-#endif
-
 #ifndef DVD_VIDEO_LB_LEN
 #define DVD_VIDEO_LB_LEN 2048
 #endif
@@ -190,7 +183,7 @@ typedef struct dvdnav_vobu_s {
 
 struct dvdnav_s {
   /* General data */
-  char        path[MAX_PATH_LEN]; /* Path to DVD device/dir */
+  char       *path;               /* Path to DVD device/dir */
   dvd_file_t *file;               /* Currently opened file */
 
   /* Position data */



More information about the libdvdnav-devel mailing list