File 30-basename-fix.dpatch of Package gramofile
# <30-basename-fix.dpatch> by Daniel Kobras <kobras@debian.org>
#
# Use the POSIX basename(3), get rid of private prototype that wasn't used
# anyway. Remove the now unneeded REDHAT50 define from the Makefile.
#
# Explanation: Previously, the code used glibc's basename but didn't realise
# it was a GNU extension. Alternatively, one could define _GNU_SOURCE, but
# I opted for the--hopefully--more portable POSIX version. (Unlike the GNU
# version, the POSIX version may potentially modify its argument.)
Index: bplaysrc/bplay.c
===================================================================
--- bplaysrc/bplay.c.orig 2012-04-20 15:49:48.068691577 +0200
+++ bplaysrc/bplay.c 2012-04-20 15:51:36.017084288 +0200
@@ -20,6 +20,10 @@
#include <sys/time.h>
#include <sys/resource.h>
+#ifdef linux
+#include <libgen.h>
+#endif
+
#ifndef __FreeBSD__
#include <sys/soundcard.h>
#else
@@ -53,16 +57,6 @@ int forked;
/* Prototypes */
-#ifdef linux
-/* This is in libc, but not in the header files. -- but it IS in
- Red Hat 5.0.... Libc6?
- well i'd guess its not in the headers because its nonstandard, i.e.
- (probably) only exists on linux... -nox */
-#ifndef REDHAT50
-extern char *basename(char *name);
-#endif
-#endif
-
void Usage(void);
void ErrDie(char *err);
void Die(char *err);
@@ -107,11 +101,14 @@ int main(int argc, char *argv[])
sndf_t filetype; /* The file type */
int mods; /* So user can override */
int optc; /* For getopt */
+ char *tmp = NULL; /* Do not clobber argv[0] */
init_curses();
#ifdef __GLIBC__
- progname = basename(argv[0]); /* For errors */
+ tmp = strdup(argv[0]); /* POSIX basename may modify its arg */
+ progname = basename(tmp); /* For errors */
+ free(tmp);
#else
progname = strrchr(argv[0], '/'); /* Replacement for e.g. FreeBSD */
if (!progname || !*++progname)