[PATCH] Only -1 as open() return value indicates error
Hello, mostly purely theoretical, but we might get 0 as fd from open. I used the exact -1 check, because e.g. WinCE will also use other negative value as file descriptors (it basically just uses memory pointers cast to int as far as I know) and I don't see a good reason to check for >= 0 instead. Index: vm/vm.c =================================================================== --- vm/vm.c (revision 1243) +++ vm/vm.c (working copy) @@ -172,7 +172,7 @@ /* Read DVD name */ fd = open(device, O_RDONLY); - if (fd > 0) { + if (fd != -1) { off = lseek( fd, 32 * (off_t) DVD_VIDEO_LB_LEN, SEEK_SET ); if( off == ( 32 * (off_t) DVD_VIDEO_LB_LEN ) ) { off = read( fd, data, DVD_VIDEO_LB_LEN );
A similar fix was committed to my tree about a year ago. Let me know if it works for you. I intend to push that change to mplayerhq svn as soon as I can. Thanks E On Tue, Nov 6, 2012 at 10:21 AM, Reimar Döffinger <Reimar.Doeffinger@gmx.de> wrote:
Hello, mostly purely theoretical, but we might get 0 as fd from open. I used the exact -1 check, because e.g. WinCE will also use other negative value as file descriptors (it basically just uses memory pointers cast to int as far as I know) and I don't see a good reason to check for >= 0 instead.
Index: vm/vm.c =================================================================== --- vm/vm.c (revision 1243) +++ vm/vm.c (working copy) @@ -172,7 +172,7 @@
/* Read DVD name */ fd = open(device, O_RDONLY); - if (fd > 0) { + if (fd != -1) { off = lseek( fd, 32 * (off_t) DVD_VIDEO_LB_LEN, SEEK_SET ); if( off == ( 32 * (off_t) DVD_VIDEO_LB_LEN ) ) { off = read( fd, data, DVD_VIDEO_LB_LEN );
_______________________________________________ DVDnav-discuss mailing list DVDnav-discuss@mplayerhq.hu https://lists.mplayerhq.hu/mailman/listinfo/dvdnav-discuss
-- Erik Hovland erik@hovland.org http://hovland.org/
On Tue, Nov 06, 2012 at 10:40:50AM -0800, Erik Hovland wrote:
A similar fix was committed to my tree about a year ago. Let me know if it works for you. I intend to push that change to mplayerhq svn as soon as I can.
Well, to be pedantic you used >= 0. I have no idea if anyone ever tried to run dvdnav on WinCE or similar that actually have such an issue though... Reading more on it, WinCE actually only has fopen but no open, so possibly someone added their own hacky open() function that just maps to fopen().
participants (2)
-
Erik Hovland -
Reimar Döffinger