[MPlayer-dev-eng] [PATCH] Kill some _LARGEFILE_SOURCE #ifdefs

Tobias Diedrich ranma at tdiedrich.de
Thu Jun 30 00:59:05 CEST 2005


I think everyone agrees that #ifdefs in code are best avoided. :-)
While I was looking at some code I noticed some unnecessary 
ifdefs related to largefile support.
Some can be avoided by casting to off_t, as in:

|-#ifdef _LARGEFILE_SOURCE
|-       newpos &= ~((long long) (STREAM_BUFFER_SIZE - 1));  /* sector boundary */
|-#else
|-       newpos &= ~(STREAM_BUFFER_SIZE - 1);  /* sector boundary */
|-#endif
|+       newpos &= ~((off_t) (STREAM_BUFFER_SIZE - 1));  /* sector boundary */

And for some format strings I think the simplest solution is to
always cast to long long:

|-#ifdef _LARGEFILE_SOURCE
|   mp_msg(MSGT_STREAM,MSGL_V,"stream_seek: WARNING! Can't seek to 0x%llX !\n",(long long)(pos+newpos));
|-#else
|-  mp_msg(MSGT_STREAM,MSGL_V,"stream_seek: WARNING! Can't seek to 0x%X !\n",(pos+newpos));
|-#endif

-- 
Tobias						PGP: http://9ac7e0bc.uguu.de
-------------- next part --------------
Index: libmpdemux/cache2.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/cache2.c,v
retrieving revision 1.26
diff -u -r1.26 cache2.c
--- libmpdemux/cache2.c	26 Jul 2004 22:06:30 -0000	1.26
+++ libmpdemux/cache2.c	29 Jun 2005 17:35:44 -0000
@@ -362,11 +362,7 @@
 //  stream->buf_pos=stream->buf_len=0;
 //  return 1;
 
-#ifdef _LARGEFILE_SOURCE
   mp_msg(MSGT_CACHE,MSGL_V,"cache_stream_seek: WARNING! Can't seek to 0x%llX !\n",(long long)(pos+newpos));
-#else
-  mp_msg(MSGT_CACHE,MSGL_V,"cache_stream_seek: WARNING! Can't seek to 0x%X !\n",(pos+newpos));
-#endif
   return 0;
 }
 
Index: libmpdemux/demux_mpg.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/demux_mpg.c,v
retrieving revision 1.59
diff -u -r1.59 demux_mpg.c
--- libmpdemux/demux_mpg.c	25 Jun 2005 13:25:27 -0000	1.59
+++ libmpdemux/demux_mpg.c	29 Jun 2005 17:35:44 -0000
@@ -653,11 +653,7 @@
 	    if(newpos<demuxer->movi_start) newpos=demuxer->movi_start;
 	}
 
-#ifdef _LARGEFILE_SOURCE
-        newpos&=~((long long)STREAM_BUFFER_SIZE-1);  /* sector boundary */
-#else
-        newpos&=~(STREAM_BUFFER_SIZE-1);  /* sector boundary */
-#endif
+        newpos&=~((off_t)STREAM_BUFFER_SIZE-1);  /* sector boundary */
         stream_seek(demuxer->stream,newpos);
 
         // re-sync video:
Index: libmpdemux/demux_ts.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/demux_ts.c,v
retrieving revision 1.33
diff -u -r1.33 demux_ts.c
--- libmpdemux/demux_ts.c	6 Jun 2005 20:49:55 -0000	1.33
+++ libmpdemux/demux_ts.c	29 Jun 2005 17:35:44 -0000
@@ -3074,11 +3074,7 @@
 	if(newpos < demuxer->movi_start)
   		newpos = demuxer->movi_start;	//begininng of stream
 
-#ifdef _LARGEFILE_SOURCE
-	newpos &= ~((long long) (STREAM_BUFFER_SIZE - 1));  /* sector boundary */
-#else
-	newpos &= ~(STREAM_BUFFER_SIZE - 1);  /* sector boundary */
-#endif
+	newpos &= ~((off_t) (STREAM_BUFFER_SIZE - 1));  /* sector boundary */
 
 	stream_seek(demuxer->stream, newpos);
 	for(i = 0; i < 8192; i++)
Index: libmpdemux/stream.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/stream.c,v
retrieving revision 1.78
diff -u -r1.78 stream.c
--- libmpdemux/stream.c	29 May 2005 12:53:59 -0000	1.78
+++ libmpdemux/stream.c	29 Jun 2005 17:35:44 -0000
@@ -248,33 +248,20 @@
 
   switch(s->type){
   case STREAMTYPE_STREAM:
-#ifdef _LARGEFILE_SOURCE
-    newpos=pos&(~((long long)STREAM_BUFFER_SIZE-1));break;
-#else
-    newpos=pos&(~(STREAM_BUFFER_SIZE-1));break;
-#endif
+    newpos=pos&(~((off_t)STREAM_BUFFER_SIZE-1));break;
   default:
     // Round on sector size
     if(s->sector_size)
       newpos=(pos/s->sector_size)*s->sector_size;
     else { // Otherwise on the buffer size
-#ifdef _LARGEFILE_SOURCE
-      newpos=pos&(~((long long)STREAM_BUFFER_SIZE-1));break;
-#else
-      newpos=pos&(~(STREAM_BUFFER_SIZE-1));break;
-#endif
+      newpos=pos&(~((off_t)STREAM_BUFFER_SIZE-1));break;
     }
     break;
   }
 
 if(verbose>=3){
-#ifdef _LARGEFILE_SOURCE
   printf("s->pos=%llX  newpos=%llX  new_bufpos=%llX  buflen=%X  \n",
     (long long)s->pos,(long long)newpos,(long long)pos,s->buf_len);
-#else
-  printf("s->pos=%X  newpos=%X  new_bufpos=%X  buflen=%X  \n",
-    (unsigned int)s->pos,newpos,pos,s->buf_len);
-#endif
 }
   pos-=newpos;
 
@@ -333,11 +320,7 @@
   
 //  if(pos==s->buf_len) printf("XXX Seek to last byte of file -> EOF\n");
   
-#ifdef _LARGEFILE_SOURCE
   mp_msg(MSGT_STREAM,MSGL_V,"stream_seek: WARNING! Can't seek to 0x%llX !\n",(long long)(pos+newpos));
-#else
-  mp_msg(MSGT_STREAM,MSGL_V,"stream_seek: WARNING! Can't seek to 0x%X !\n",(pos+newpos));
-#endif
   return 0;
 }
 
Index: libmpdemux/stream_file.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/stream_file.c,v
retrieving revision 1.8
diff -u -r1.8 stream_file.c
--- libmpdemux/stream_file.c	14 May 2005 12:50:59 -0000	1.8
+++ libmpdemux/stream_file.c	29 Jun 2005 17:35:44 -0000
@@ -139,11 +139,7 @@
     stream->type = STREAMTYPE_FILE;
   }
 
-#ifdef _LARGEFILE_SOURCE
   mp_msg(MSGT_OPEN,MSGL_V,"[file] File size is %lld bytes\n", (long long)len);
-#else
-  mp_msg(MSGT_OPEN,MSGL_V,"[file] File size is %u bytes\n", (unsigned int)len);
-#endif 
 
   stream->fd = f;
   stream->fill_buffer = fill_buffer;
Index: libmpdemux/stream_ftp.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/stream_ftp.c,v
retrieving revision 1.4
diff -u -r1.4 stream_ftp.c
--- libmpdemux/stream_ftp.c	17 Aug 2003 11:07:18 -0000	1.4
+++ libmpdemux/stream_ftp.c	29 Jun 2005 17:35:45 -0000
@@ -307,11 +307,7 @@
   if(!s->fd) return 0;
 
   if(newpos > 0) {
-#ifdef _LARGEFILE_SOURCE
-    snprintf(str,255,"REST %lld\r\n",newpos);
-#else
-    snprintf(str,255,"REST %u\r\n",newpos);
-#endif 
+    snprintf(str,255,"REST %lld\r\n",(long long)newpos);
 
     resp = FtpSendCmd(str,p,rsp_txt);
     if(resp != 3) {


More information about the MPlayer-dev-eng mailing list