[MPlayer-dev-eng] [PATCH] replace glibc basename by macro to

Diego Biurrun diego at biurrun.de
Tue Jan 21 02:26:38 CET 2003


Arpi writes:
 > > > I noticed some time ago that --enable-menu fails to compile on Cygwin
 > > > because menu_pt.c #includes libgen.h that is part of glibc and not
 > > > available under Cygwin.  I therefore ripped the macro mp_basename out of
 > > > mplayer.c and put it in menu_pt.c instead of libgen.h.  It compiles, it
 > > > works.  I probably got it all wrong, so please tell me what I have to do
 > > > differently.  Anyway, here is the patch.
 > > 
 > > According to my docs's, basename() is POSIX (IEEE Std 1003.1-2001).
 > > IMHO (as I am Not an MPlayer Developer), it would be better practice
 > > to define basename() conditionally on #ifndef HAVE_LIBGEN_H, after
 > > adding the appropriate test to "configure".
 > 
 > agree...

OK, here is a patch that does it...

 > or just use our impl. everywhere, then it will bevave the same way
 > everywhere. (at least linux manpage of dirname/basename mentions some
 > bugs around trailing '/' handling and other unclear issues.

That would be an alternative.  libgen.h is #included in
libmenu/menu_pt.c and TOOLS/subfont-c/subfont.c.  basename is also
used in mplayer.c as a macro called mp_basename.

How should we do this then?

1. Use this patch (and probably apply it to subfont.c also).
2. Use the macro everywhere.

In the second case should the macro be defined globally somewhere?
Where?

Diego


--- configure	20 Jan 2003 22:56:00 -0000	1.640
+++ configure	21 Jan 2003 01:26:18 -0000
@@ -2240,6 +2240,21 @@
 echores "$_sys_sysinfo"
 
 
+echocheck "basename()"
+cat > $TMPC << EOF
+#include <libgen.h>
+int main(void) { basename("test"); return 0; }
+EOF
+_basename=no
+cc_check && _basename=yes
+if test "$_basename" = yes ; then
+  _def_basename='#define HAVE_LIBGEN_H 1'
+else
+  _def_basename='#undef HAVE_LIBGEN_H'
+fi
+echores "$_basename"
+
+
 #########
 # VIDEO #
 #########
@@ -5063,6 +5078,9 @@
 
 /* Define this if your system has vsscanf */
 $_def_vsscanf
+
+/* Define this if your system has basename */
+$_def_basename
 
 /* LIRC (remote control, see www.lirc.org) support: */
 $_def_lirc
--- libmenu/menu_pt.c	28 Dec 2002 18:51:09 -0000	1.2
+++ libmenu/menu_pt.c	21 Jan 2003 01:26:18 -0000
@@ -2,7 +2,12 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
+
+#ifdef HAVE_LIBGEN_H
 #include <libgen.h>
+#else
+#define basename(s) (strrchr(s,'/')==NULL?(char*)s:(strrchr(s,'/')+1))
+#endif
 
 #include "../config.h"
 


More information about the MPlayer-dev-eng mailing list