1
0
mirror of https://gitlab.xiph.org/xiph/ezstream.git synced 2025-02-02 15:07:45 -05:00

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().


git-svn-id: https://svn.xiph.org/trunk/ezstream@12673 0101bb08-14d6-0310-b084-bc0e0c8e3800
This commit is contained in:
moritz 2007-03-07 21:01:16 +00:00
parent 928719013e
commit ca41d8cac8
9 changed files with 133 additions and 64 deletions

View File

@ -2,7 +2,7 @@ AUTOMAKE_OPTIONS = 1.9 foreign
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@

74
src/compat.c Normal file
View File

@ -0,0 +1,74 @@
/*
* Copyright (c) 2007 Moritz Grimm <gtgbr@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@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);
}

View File

@ -1,3 +1,19 @@
/*
* Copyright (c) 2007 Moritz Grimm <gtgbr@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 */
#ifdef WIN32
#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
# ifndef S_IEXEC
# define S_IEXEC S_IXUSR
# endif
# define basename local_basename
# define sleep(a) Sleep((a) * 1000)
#endif /* WIN32 */
/* Usually defined in <sys/stat.h>. */
#ifndef S_IEXEC
# define S_IEXEC S_IXUSR
#endif /* !S_IEXEC */
/* 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__ */

View File

@ -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;

View File

@ -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 @@ typedef struct tag_ID3Tag {
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,31 +137,6 @@ sig_handler(int sig)
}
#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)
{
@ -614,11 +576,7 @@ reconnectServer(shout_t *shout, int closeConn)
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);

View File

@ -35,15 +35,7 @@
#include "playlist.h"
#include "util.h"
#ifndef SIZE_T_MAX
# define SIZE_T_MAX UINT_MAX
#endif
#ifndef PATH_MAX
# define PATH_MAX 256
#endif
extern char *__progname;
extern char *__progname;
struct playlist {
char *filename;

View File

@ -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 @@ xstrdup(const char *str)
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));
}

View File

@ -22,5 +22,6 @@ void * xcalloc(size_t /* nmemb */, size_t /* size */);
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__ */

View File

@ -153,6 +153,9 @@
<Filter
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