[xiph-commits] r12673 - in trunk/ezstream: src win32

moritz at svn.xiph.org moritz at svn.xiph.org
Wed Mar 7 13:01:23 PST 2007


Author: moritz
Date: 2007-03-07 13:01:16 -0800 (Wed, 07 Mar 2007)
New Revision: 12673

Added:
   trunk/ezstream/src/compat.c
Modified:
   trunk/ezstream/src/Makefile.am
   trunk/ezstream/src/compat.h
   trunk/ezstream/src/configfile.c
   trunk/ezstream/src/ezstream.c
   trunk/ezstream/src/playlist.c
   trunk/ezstream/src/util.c
   trunk/ezstream/src/util.h
   trunk/ezstream/win32/ezstream.vcproj
Log:
More code reorganization, move compatibility and utility functions out of
ezstream.c. Use a basename() function for Windows that behaves identical to
a modern Unix' basename().


Modified: trunk/ezstream/src/Makefile.am
===================================================================
--- trunk/ezstream/src/Makefile.am	2007-03-07 12:53:47 UTC (rev 12672)
+++ trunk/ezstream/src/Makefile.am	2007-03-07 21:01:16 UTC (rev 12673)
@@ -2,7 +2,7 @@
 
 bin_PROGRAMS =	ezstream
 
-ezstream_SOURCES = ezstream.c configfile.c playlist.c util.c
+ezstream_SOURCES = ezstream.c compat.c configfile.c playlist.c util.c
 ezstream_LDADD = @LIBOBJS@ @XIPH_LIBS@
     
 AM_CFLAGS =	@XIPH_CFLAGS@

Added: trunk/ezstream/src/compat.c
===================================================================
--- trunk/ezstream/src/compat.c	2007-03-07 12:53:47 UTC (rev 12672)
+++ trunk/ezstream/src/compat.c	2007-03-07 21:01:16 UTC (rev 12673)
@@ -0,0 +1,74 @@
+/*
+ * Copyright (c) 2007 Moritz Grimm <gtgbr at gmx.net>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#ifdef HAVE_SYS_TYPES_H
+# include <sys/types.h>
+#endif
+#include <errno.h>
+#include <limits.h>
+#include <string.h>
+
+#include "compat.h"
+
+/*
+ * Modified basename() implementation from OpenBSD, based on:
+ * $OpenBSD: basename.c,v 1.14 2005/08/08 08:05:33 espie Exp $
+ * Copyright (c) 1997, 2004 Todd C. Miller <Todd.Miller at courtesan.com>
+ */
+char *
+local_basename(const char *path)
+{
+	static char	 bname[PATH_MAX];
+	size_t		 len;
+	const char	*startp, *endp;
+
+	if (path == NULL || *path == '\0') {
+		bname[0] = '.';
+		bname[1] = '\0';
+		return (bname);
+	}
+
+	/* Strip any trailing slashes */
+	endp = path + strlen(path) - 1;
+	while (endp > path && *endp == PATH_SEPARATOR)
+		endp--;
+
+	/* All slashes become "\" */
+	if (endp == path && *endp == PATH_SEPARATOR) {
+		bname[0] = PATH_SEPARATOR;
+		bname[1] = '\0';
+		return (bname);
+	}
+
+	/* Find the start of the base */
+	startp = endp;
+	while (startp > path && *(startp - 1) != PATH_SEPARATOR)
+		startp--;
+
+	len = endp - startp + 1;
+	if (len >= sizeof(bname)) {
+		errno = ENAMETOOLONG;
+		return (NULL);
+	}
+	memcpy(bname, startp, len);
+	bname[len] = '\0';
+
+	return (bname);
+}

Modified: trunk/ezstream/src/compat.h
===================================================================
--- trunk/ezstream/src/compat.h	2007-03-07 12:53:47 UTC (rev 12672)
+++ trunk/ezstream/src/compat.h	2007-03-07 21:01:16 UTC (rev 12673)
@@ -1,3 +1,19 @@
+/*
+ * Copyright (c) 2007 Moritz Grimm <gtgbr at gmx.net>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
 #ifndef __COMPAT_H__
 #define __COMPAT_H__
 
@@ -13,8 +29,16 @@
 # endif /* WIN32 */
 #endif /* !PATH_SEPARATOR */
 
+#ifndef PATH_MAX
+# define PATH_MAX	256
+#endif /* !PATH_MAX */
+
+/* Sometimes defined through <limits.h>. */
+#ifndef SIZE_T_MAX
+# define SIZE_T_MAX	UINT_MAX
+#endif /* !SIZE_T_MAX */
+
 #ifdef WIN32
-
 # define _PATH_DEVNULL	"nul"
 
 # define pclose 	_pclose
@@ -31,12 +55,20 @@
 # define S_IXGRP	0
 # define S_IXOTH	0
 
-#else
+# define basename	local_basename
+# define sleep(a)	Sleep((a) * 1000)
+#endif /* WIN32 */
 
-# ifndef S_IEXEC
-#  define S_IEXEC	S_IXUSR
-# endif
+/* Usually defined in <sys/stat.h>. */
+#ifndef S_IEXEC
+# define S_IEXEC	S_IXUSR
+#endif /* !S_IEXEC */
 
-#endif /* WIN32 */
+/* For Solaris, possibly others (usually defined in <paths.h>.) */
+#ifndef _PATH_DEVNULL
+# define _PATH_DEVNULL	"/dev/null"
+#endif /* !_PATH_DEVNULL */
 
+char *	local_basename(const char *);
+
 #endif /* __COMPAT_H__ */

Modified: trunk/ezstream/src/configfile.c
===================================================================
--- trunk/ezstream/src/configfile.c	2007-03-07 12:53:47 UTC (rev 12672)
+++ trunk/ezstream/src/configfile.c	2007-03-07 21:01:16 UTC (rev 12673)
@@ -26,14 +26,11 @@
 #include <stdio.h>
 #include <string.h>
 
+#include "compat.h"
 #include "configfile.h"
 #include "strfctns.h"
 #include "util.h"
 
-#ifndef PATH_MAX
-# define PATH_MAX	256
-#endif
-
 extern char		*__progname;
 
 static EZCONFIG		 ezConfig;

Modified: trunk/ezstream/src/ezstream.c
===================================================================
--- trunk/ezstream/src/ezstream.c	2007-03-07 12:53:47 UTC (rev 12672)
+++ trunk/ezstream/src/ezstream.c	2007-03-07 21:01:16 UTC (rev 12673)
@@ -62,15 +62,6 @@
 #include "strfctns.h"
 #include "util.h"
 
-#ifndef PATH_MAX
-# define PATH_MAX	256
-#endif
-
-/* For Solaris, possibly others (usually defined in <paths.h>.) */
-#ifndef _PATH_DEVNULL
-#  define _PATH_DEVNULL "/dev/null"
-#endif /* _PATH_DEVNULL */
-
 #define STREAM_DONE	0
 #define STREAM_CONT	1
 #define STREAM_SKIP	2
@@ -112,10 +103,6 @@
 	char genre;
 } ID3Tag;
 
-#ifdef WIN32
-char *	basename(const char *);
-#endif
-int	strrcmp(const char *, const char *);
 int	urlParse(const char *, char **, int *, char **);
 void	replaceString(const char *, char *, size_t, const char *, const char *);
 void	setMetadata(shout_t *, const char *);
@@ -150,32 +137,7 @@
 }
 #endif /* HAVE_SIGNALS */
 
-#ifdef WIN32
-char *
-basename(const char *fileName)
-{
-	char	*pLast = strrchr(fileName, PATH_SEPARATOR);
-
-	if (pLast != NULL)
-		return (pLast + 1);
-
-	return (NULL);
-}
-#endif /* WIN32 */
-
 int
-strrcmp(const char *s, const char *sub)
-{
-	size_t	slen = strlen(s);
-	size_t	sublen = strlen(sub);
-
-	if (sublen > slen)
-		return (1);
-
-	return (memcmp(s + slen - sublen, sub, sublen));
-}
-
-int
 urlParse(const char *url, char **hostname, int *port, char **mountname)
 {
 	char		*p1, *p2, *p3;
@@ -614,11 +576,7 @@
 
 		printf("%s: Waiting 5s for %s to come back ...\n",
 		       __progname, pezConfig->URL);
-#ifdef WIN32
-		Sleep(5000);
-#else
 		sleep(5);
-#endif
 	};
 
 	printf("%s: Giving up\n", __progname);

Modified: trunk/ezstream/src/playlist.c
===================================================================
--- trunk/ezstream/src/playlist.c	2007-03-07 12:53:47 UTC (rev 12672)
+++ trunk/ezstream/src/playlist.c	2007-03-07 21:01:16 UTC (rev 12673)
@@ -35,16 +35,8 @@
 #include "playlist.h"
 #include "util.h"
 
-#ifndef SIZE_T_MAX
-# define SIZE_T_MAX	UINT_MAX
-#endif
+extern char	*__progname;
 
-#ifndef PATH_MAX
-# define PATH_MAX	256
-#endif
-
-extern char    *__progname;
-
 struct playlist {
 	char	 *filename;
 	char	**list;

Modified: trunk/ezstream/src/util.c
===================================================================
--- trunk/ezstream/src/util.c	2007-03-07 12:53:47 UTC (rev 12672)
+++ trunk/ezstream/src/util.c	2007-03-07 21:01:16 UTC (rev 12673)
@@ -33,7 +33,7 @@
 # define SIZE_T_MAX	UINT_MAX
 #endif
 
-extern char    *__progname;
+extern char	*__progname;
 
 void *
 xmalloc(size_t size)
@@ -137,3 +137,15 @@
 	memcpy(nstr, str, len);
 	return (nstr);
 }
+
+int
+strrcmp(const char *s, const char *sub)
+{
+	size_t	slen = strlen(s);
+	size_t	sublen = strlen(sub);
+
+	if (sublen > slen)
+		return (1);
+
+	return (memcmp(s + slen - sublen, sub, sublen));
+}

Modified: trunk/ezstream/src/util.h
===================================================================
--- trunk/ezstream/src/util.h	2007-03-07 12:53:47 UTC (rev 12672)
+++ trunk/ezstream/src/util.h	2007-03-07 21:01:16 UTC (rev 12673)
@@ -22,5 +22,6 @@
 void *	xrealloc(void *, size_t /* nmemb */, size_t /* size */);
 void	xfree(void *);
 char *	xstrdup(const char *);
+int	strrcmp(const char *, const char *);
 
 #endif /* __UTIL_H__ */

Modified: trunk/ezstream/win32/ezstream.vcproj
===================================================================
--- trunk/ezstream/win32/ezstream.vcproj	2007-03-07 12:53:47 UTC (rev 12672)
+++ trunk/ezstream/win32/ezstream.vcproj	2007-03-07 21:01:16 UTC (rev 12673)
@@ -154,6 +154,9 @@
 			Name="Source Files"
 			Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat">
 			<File
+				RelativePath="..\src\compat.c">
+			</File>
+			<File
 				RelativePath="..\src\configfile.c">
 				<FileConfiguration
 					Name="Release|Win32">



More information about the commits mailing list