mirror of
https://gitlab.xiph.org/xiph/ezstream.git
synced 2025-01-03 14:56:35 -05:00
Untangle compatibility code
* update to latest strlc*(3) and strtonum(3) functions * isolate local_basename()
This commit is contained in:
parent
00017d2165
commit
739a08b5b9
@ -1,4 +1,4 @@
|
||||
AUTOMAKE_OPTIONS = 1.10 foreign
|
||||
AUTOMAKE_OPTIONS = 1.10 foreign subdir-objects
|
||||
ACLOCAL_AMFLAGS = -I m4
|
||||
|
||||
SUBDIRS = build-aux compat doc examples m4 src win32
|
||||
|
@ -1,4 +1,4 @@
|
||||
AUTOMAKE_OPTIONS = 1.10 foreign
|
||||
AUTOMAKE_OPTIONS = 1.10 foreign subdir-objects
|
||||
|
||||
EXTRA_DIST = config.rpath
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
AUTOMAKE_OPTIONS = 1.10 foreign
|
||||
AUTOMAKE_OPTIONS = 1.10 foreign subdir-objects
|
||||
|
||||
SUBDIRS = sys
|
||||
|
||||
|
32
compat/compat.h
Normal file
32
compat/compat.h
Normal file
@ -0,0 +1,32 @@
|
||||
#ifndef __COMPAT_H__
|
||||
#define __COMPAT_H__
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif /* HAVE_CONFIG_H */
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#ifndef HAVE_GETOPT
|
||||
extern int opterr;
|
||||
extern int optind;
|
||||
extern int optopt;
|
||||
extern int optreset;
|
||||
extern char *optarg;
|
||||
|
||||
int getopt(int, char * const *, const char *);
|
||||
#endif /* !HAVE_GETOPT */
|
||||
|
||||
#ifndef HAVE_STRLCAT
|
||||
size_t strlcat(char *, const char *, size_t);
|
||||
#endif /* !HAVE_STRLCAT */
|
||||
|
||||
#ifndef HAVE_STRLCPY
|
||||
size_t strlcpy(char *, const char *, size_t);
|
||||
#endif /* !HAVE_STRLCPY */
|
||||
|
||||
#ifndef HAVE_STRTONUM
|
||||
long long strtonum(const char *, long long, long long, const char **);
|
||||
#endif /* !HAVE_STROTONUM */
|
||||
|
||||
#endif /* __COMPAT_H__ */
|
@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: getopt_long.c,v 1.23 2007/10/31 12:34:57 chl Exp $ */
|
||||
/* $OpenBSD: getopt_long.c,v 1.26 2013/06/08 22:47:56 millert Exp $ */
|
||||
/* $NetBSD: getopt_long.c,v 1.15 2002/01/31 22:43:40 tv Exp $ */
|
||||
|
||||
/*
|
||||
@ -49,21 +49,19 @@
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif /* HAVE_CONFIG_H */
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <getopt.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "ezstream.h"
|
||||
#include "compat.h"
|
||||
|
||||
int local_getopt(int, char * const *, const char *);
|
||||
|
||||
#ifndef HAVE_GETOPT
|
||||
|
||||
int opterr = 1; /* if error message should be printed */
|
||||
int optind = 1; /* index into parent argv vector */
|
||||
int optopt = '?'; /* character checked for validity */
|
||||
int optreset; /* reset getopt */
|
||||
char *optarg; /* argument associated with option */
|
||||
int opterr = 1; /* if error message should be printed */
|
||||
int optind = 1; /* index into parent argv vector */
|
||||
int optopt = '?'; /* character checked for validity */
|
||||
int optreset; /* reset getopt */
|
||||
char *optarg; /* argument associated with option */
|
||||
|
||||
#define PRINT_ERROR ((opterr) && (*options != ':'))
|
||||
|
||||
@ -72,13 +70,16 @@ char *optarg; /* argument associated with option */
|
||||
#define FLAG_LONGONLY 0x04 /* operate as getopt_long_only */
|
||||
|
||||
/* return values */
|
||||
#define BADCH (int)'?'
|
||||
#define BADARG ((*options == ':') ? (int)':' : (int)'?')
|
||||
#define INORDER (int)1
|
||||
#define BADCH (int)'?'
|
||||
#define BADARG ((*options == ':') ? (int)':' : (int)'?')
|
||||
#define INORDER (int)1
|
||||
|
||||
#define EMSG ""
|
||||
#define EMSG ""
|
||||
|
||||
static int getopt_internal(int, char * const *, const char *, int);
|
||||
static int getopt_internal(int, char * const *, const char *,
|
||||
const struct option *, int *, int);
|
||||
static int parse_long_options(char * const *, const char *,
|
||||
const struct option *, int *, int, int);
|
||||
static int gcd(int, int);
|
||||
static void permute_args(int, int, int, char * const *);
|
||||
|
||||
@ -89,8 +90,12 @@ static int nonopt_start = -1; /* first non option argument (for permute) */
|
||||
static int nonopt_end = -1; /* first option after non options (for permute) */
|
||||
|
||||
/* Error messages */
|
||||
static const char recargchar[] = "option requires an argument -- %c\n";
|
||||
static const char illoptchar[] = "unknown option -- %c\n";
|
||||
static const char recargchar[] = "option requires an argument -- %c";
|
||||
static const char recargstring[] = "option requires an argument -- %s";
|
||||
static const char ambig[] = "ambiguous option -- %.*s";
|
||||
static const char noarg[] = "option doesn't take an argument -- %.*s";
|
||||
static const char illoptchar[] = "unknown option -- %c";
|
||||
static const char illoptstring[] = "unknown option -- %s";
|
||||
|
||||
/*
|
||||
* Compute the greatest common divisor of a and b.
|
||||
@ -147,33 +152,147 @@ permute_args(int panonopt_start, int panonopt_end, int opt_end,
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* parse_long_options --
|
||||
* Parse long options in argc/argv argument vector.
|
||||
* Returns -1 if short_too is set and the option does not match long_options.
|
||||
*/
|
||||
static int
|
||||
parse_long_options(char * const *nargv, const char *options,
|
||||
const struct option *long_options, int *idx, int short_too, int flags)
|
||||
{
|
||||
char *current_argv, *has_equal;
|
||||
size_t current_argv_len;
|
||||
int i, match, exact_match, second_partial_match;
|
||||
|
||||
current_argv = place;
|
||||
match = -1;
|
||||
exact_match = 0;
|
||||
second_partial_match = 0;
|
||||
|
||||
optind++;
|
||||
|
||||
if ((has_equal = strchr(current_argv, '=')) != NULL) {
|
||||
/* argument found (--option=arg) */
|
||||
current_argv_len = has_equal - current_argv;
|
||||
has_equal++;
|
||||
} else
|
||||
current_argv_len = strlen(current_argv);
|
||||
|
||||
for (i = 0; long_options[i].name; i++) {
|
||||
/* find matching long option */
|
||||
if (strncmp(current_argv, long_options[i].name,
|
||||
current_argv_len))
|
||||
continue;
|
||||
|
||||
if (strlen(long_options[i].name) == current_argv_len) {
|
||||
/* exact match */
|
||||
match = i;
|
||||
exact_match = 1;
|
||||
break;
|
||||
}
|
||||
/*
|
||||
* If this is a known short option, don't allow
|
||||
* a partial match of a single character.
|
||||
*/
|
||||
if (short_too && current_argv_len == 1)
|
||||
continue;
|
||||
|
||||
if (match == -1) /* first partial match */
|
||||
match = i;
|
||||
else if ((flags & FLAG_LONGONLY) ||
|
||||
long_options[i].has_arg != long_options[match].has_arg ||
|
||||
long_options[i].flag != long_options[match].flag ||
|
||||
long_options[i].val != long_options[match].val)
|
||||
second_partial_match = 1;
|
||||
}
|
||||
if (!exact_match && second_partial_match) {
|
||||
/* ambiguous abbreviation */
|
||||
if (PRINT_ERROR)
|
||||
warnx(ambig, (int)current_argv_len, current_argv);
|
||||
optopt = 0;
|
||||
return (BADCH);
|
||||
}
|
||||
if (match != -1) { /* option found */
|
||||
if (long_options[match].has_arg == no_argument
|
||||
&& has_equal) {
|
||||
if (PRINT_ERROR)
|
||||
warnx(noarg, (int)current_argv_len,
|
||||
current_argv);
|
||||
/*
|
||||
* XXX: GNU sets optopt to val regardless of flag
|
||||
*/
|
||||
if (long_options[match].flag == NULL)
|
||||
optopt = long_options[match].val;
|
||||
else
|
||||
optopt = 0;
|
||||
return (BADARG);
|
||||
}
|
||||
if (long_options[match].has_arg == required_argument ||
|
||||
long_options[match].has_arg == optional_argument) {
|
||||
if (has_equal)
|
||||
optarg = has_equal;
|
||||
else if (long_options[match].has_arg ==
|
||||
required_argument) {
|
||||
/*
|
||||
* optional argument doesn't use next nargv
|
||||
*/
|
||||
optarg = nargv[optind++];
|
||||
}
|
||||
}
|
||||
if ((long_options[match].has_arg == required_argument)
|
||||
&& (optarg == NULL)) {
|
||||
/*
|
||||
* Missing argument; leading ':' indicates no error
|
||||
* should be generated.
|
||||
*/
|
||||
if (PRINT_ERROR)
|
||||
warnx(recargstring,
|
||||
current_argv);
|
||||
/*
|
||||
* XXX: GNU sets optopt to val regardless of flag
|
||||
*/
|
||||
if (long_options[match].flag == NULL)
|
||||
optopt = long_options[match].val;
|
||||
else
|
||||
optopt = 0;
|
||||
--optind;
|
||||
return (BADARG);
|
||||
}
|
||||
} else { /* unknown option */
|
||||
if (short_too) {
|
||||
--optind;
|
||||
return (-1);
|
||||
}
|
||||
if (PRINT_ERROR)
|
||||
warnx(illoptstring, current_argv);
|
||||
optopt = 0;
|
||||
return (BADCH);
|
||||
}
|
||||
if (idx)
|
||||
*idx = match;
|
||||
if (long_options[match].flag) {
|
||||
*long_options[match].flag = long_options[match].val;
|
||||
return (0);
|
||||
} else
|
||||
return (long_options[match].val);
|
||||
}
|
||||
|
||||
/*
|
||||
* getopt_internal --
|
||||
* Parse argc/argv argument vector. Called by user level routines.
|
||||
*/
|
||||
static int
|
||||
getopt_internal(int nargc, char * const *nargv, const char *options, int flags)
|
||||
getopt_internal(int nargc, char * const *nargv, const char *options,
|
||||
const struct option *long_options, int *idx, int flags)
|
||||
{
|
||||
char *oli; /* option letter list index */
|
||||
int optchar;
|
||||
int optchar, short_too;
|
||||
static int posixly_correct = -1;
|
||||
|
||||
if (options == NULL)
|
||||
return (-1);
|
||||
|
||||
/*
|
||||
* Disable GNU extensions if POSIXLY_CORRECT is set or options
|
||||
* string begins with a '+'.
|
||||
*/
|
||||
if (posixly_correct == -1)
|
||||
posixly_correct = (getenv("POSIXLY_CORRECT") != NULL);
|
||||
if (posixly_correct || *options == '+')
|
||||
flags &= ~FLAG_PERMUTE;
|
||||
else if (*options == '-')
|
||||
flags |= FLAG_ALLARGS;
|
||||
if (*options == '+' || *options == '-')
|
||||
options++;
|
||||
|
||||
/*
|
||||
* XXX Some GNU programs (like cvs) set optind to 0 instead of
|
||||
* XXX using optreset. Work around this braindamage.
|
||||
@ -181,6 +300,19 @@ getopt_internal(int nargc, char * const *nargv, const char *options, int flags)
|
||||
if (optind == 0)
|
||||
optind = optreset = 1;
|
||||
|
||||
/*
|
||||
* Disable GNU extensions if POSIXLY_CORRECT is set or options
|
||||
* string begins with a '+'.
|
||||
*/
|
||||
if (posixly_correct == -1 || optreset)
|
||||
posixly_correct = (getenv("POSIXLY_CORRECT") != NULL);
|
||||
if (*options == '-')
|
||||
flags |= FLAG_ALLARGS;
|
||||
else if (posixly_correct || *options == '+')
|
||||
flags &= ~FLAG_PERMUTE;
|
||||
if (*options == '+' || *options == '-')
|
||||
options++;
|
||||
|
||||
optarg = NULL;
|
||||
if (optreset)
|
||||
nonopt_start = nonopt_end = -1;
|
||||
@ -260,6 +392,28 @@ start:
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Check long options if:
|
||||
* 1) we were passed some
|
||||
* 2) the arg is not just "-"
|
||||
* 3) either the arg starts with -- we are getopt_long_only()
|
||||
*/
|
||||
if (long_options != NULL && place != nargv[optind] &&
|
||||
(*place == '-' || (flags & FLAG_LONGONLY))) {
|
||||
short_too = 0;
|
||||
if (*place == '-')
|
||||
place++; /* --foo long option */
|
||||
else if (*place != ':' && strchr(options, *place) != NULL)
|
||||
short_too = 1; /* could be short option too */
|
||||
|
||||
optchar = parse_long_options(nargv, options, long_options,
|
||||
idx, short_too, flags);
|
||||
if (optchar != -1) {
|
||||
place = EMSG;
|
||||
return (optchar);
|
||||
}
|
||||
}
|
||||
|
||||
if ((optchar = (int)*place++) == (int)':' ||
|
||||
(optchar == (int)'-' && *place != '\0') ||
|
||||
(oli = strchr(options, optchar)) == NULL) {
|
||||
@ -273,10 +427,27 @@ start:
|
||||
if (!*place)
|
||||
++optind;
|
||||
if (PRINT_ERROR)
|
||||
fprintf(stderr, illoptchar, optchar);
|
||||
warnx(illoptchar, optchar);
|
||||
optopt = optchar;
|
||||
return (BADCH);
|
||||
}
|
||||
if (long_options != NULL && optchar == 'W' && oli[1] == ';') {
|
||||
/* -W long-option */
|
||||
if (*place) /* no space */
|
||||
/* NOTHING */;
|
||||
else if (++optind >= nargc) { /* no arg */
|
||||
place = EMSG;
|
||||
if (PRINT_ERROR)
|
||||
warnx(recargchar, optchar);
|
||||
optopt = optchar;
|
||||
return (BADARG);
|
||||
} else /* white space */
|
||||
place = nargv[optind];
|
||||
optchar = parse_long_options(nargv, options, long_options,
|
||||
idx, 0, flags);
|
||||
place = EMSG;
|
||||
return (optchar);
|
||||
}
|
||||
if (*++oli != ':') { /* doesn't take argument */
|
||||
if (!*place)
|
||||
++optind;
|
||||
@ -288,7 +459,7 @@ start:
|
||||
if (++optind >= nargc) { /* no arg */
|
||||
place = EMSG;
|
||||
if (PRINT_ERROR)
|
||||
fprintf(stderr, recargchar, optchar);
|
||||
warnx(recargchar, optchar);
|
||||
optopt = optchar;
|
||||
return (BADARG);
|
||||
} else
|
||||
@ -301,8 +472,6 @@ start:
|
||||
return (optchar);
|
||||
}
|
||||
|
||||
#endif /* !HAVE_GETOPT */
|
||||
|
||||
/*
|
||||
* getopt --
|
||||
* Parse argc/argv argument vector.
|
||||
@ -310,11 +479,8 @@ start:
|
||||
* [eventually this will replace the BSD getopt]
|
||||
*/
|
||||
int
|
||||
local_getopt(int nargc, char * const *nargv, const char *options)
|
||||
getopt(int nargc, char * const *nargv, const char *options)
|
||||
{
|
||||
#ifdef HAVE_GETOPT
|
||||
return (getopt(nargc, nargv, options));
|
||||
#else /* HAVE_GETOPT */
|
||||
|
||||
/*
|
||||
* We don't pass FLAG_PERMUTE to getopt_internal() since
|
||||
@ -324,6 +490,31 @@ local_getopt(int nargc, char * const *nargv, const char *options)
|
||||
* before dropping privileges it makes sense to keep things
|
||||
* as simple (and bug-free) as possible.
|
||||
*/
|
||||
return (getopt_internal(nargc, nargv, options, 0));
|
||||
#endif /* HAVE_GETOPT */
|
||||
return (getopt_internal(nargc, nargv, options, NULL, NULL, 0));
|
||||
}
|
||||
|
||||
/*
|
||||
* getopt_long --
|
||||
* Parse argc/argv argument vector.
|
||||
*/
|
||||
int
|
||||
getopt_long(int nargc, char * const *nargv, const char *options,
|
||||
const struct option *long_options, int *idx)
|
||||
{
|
||||
|
||||
return (getopt_internal(nargc, nargv, options, long_options, idx,
|
||||
FLAG_PERMUTE));
|
||||
}
|
||||
|
||||
/*
|
||||
* getopt_long_only --
|
||||
* Parse argc/argv argument vector.
|
||||
*/
|
||||
int
|
||||
getopt_long_only(int nargc, char * const *nargv, const char *options,
|
||||
const struct option *long_options, int *idx)
|
||||
{
|
||||
|
||||
return (getopt_internal(nargc, nargv, options, long_options, idx,
|
||||
FLAG_PERMUTE|FLAG_LONGONLY));
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
/* $OpenBSD: strlcat.c,v 1.13 2005/08/08 08:05:37 espie Exp $ */
|
||||
/* $OpenBSD: strlcat.c,v 1.14 2015/01/15 03:54:12 millert Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
|
||||
* Copyright (c) 1998, 2015 Todd C. Miller <Todd.Miller@courtesan.com>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
@ -16,47 +16,42 @@
|
||||
* 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 <sys/types.h>
|
||||
#include <string.h>
|
||||
#include "strfctns.h"
|
||||
|
||||
#include "compat.h"
|
||||
|
||||
/*
|
||||
* Appends src to string dst of size siz (unlike strncat, siz is the
|
||||
* full size of dst, not space left). At most siz-1 characters
|
||||
* will be copied. Always NUL terminates (unless siz <= strlen(dst)).
|
||||
* Returns strlen(src) + MIN(siz, strlen(initial dst)).
|
||||
* Appends src to string dst of size dsize (unlike strncat, dsize is the
|
||||
* full size of dst, not space left). At most dsize-1 characters
|
||||
* will be copied. Always NUL terminates (unless dsize <= strlen(dst)).
|
||||
* Returns strlen(src) + MIN(dsize, strlen(initial dst)).
|
||||
* If retval >= siz, truncation occurred.
|
||||
*/
|
||||
size_t
|
||||
local_strlcat(char *dst, const char *src, size_t siz)
|
||||
strlcat(char *dst, const char *src, size_t dsize)
|
||||
{
|
||||
char *d = dst;
|
||||
const char *s = src;
|
||||
size_t n = siz;
|
||||
const char *odst = dst;
|
||||
const char *osrc = src;
|
||||
size_t n = dsize;
|
||||
size_t dlen;
|
||||
|
||||
/* Find the end of dst and adjust bytes left but don't go past end */
|
||||
while (n-- != 0 && *d != '\0')
|
||||
d++;
|
||||
dlen = d - dst;
|
||||
n = siz - dlen;
|
||||
/* Find the end of dst and adjust bytes left but don't go past end. */
|
||||
while (n-- != 0 && *dst != '\0')
|
||||
dst++;
|
||||
dlen = dst - odst;
|
||||
n = dsize - dlen;
|
||||
|
||||
if (n == 0)
|
||||
return(dlen + strlen(s));
|
||||
while (*s != '\0') {
|
||||
if (n != 1) {
|
||||
*d++ = *s;
|
||||
if (n-- == 0)
|
||||
return(dlen + strlen(src));
|
||||
while (*src != '\0') {
|
||||
if (n != 0) {
|
||||
*dst++ = *src;
|
||||
n--;
|
||||
}
|
||||
s++;
|
||||
src++;
|
||||
}
|
||||
*d = '\0';
|
||||
*dst = '\0';
|
||||
|
||||
return(dlen + (s - src)); /* count does not include NUL */
|
||||
return(dlen + (src - osrc)); /* count does not include NUL */
|
||||
}
|
52
compat/strlcpy.c
Normal file
52
compat/strlcpy.c
Normal file
@ -0,0 +1,52 @@
|
||||
/* $OpenBSD: strlcpy.c,v 1.12 2015/01/15 03:54:12 millert Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1998, 2015 Todd C. Miller <Todd.Miller@courtesan.com>
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "compat.h"
|
||||
|
||||
/*
|
||||
* Copy string src to buffer dst of size dsize. At most dsize-1
|
||||
* chars will be copied. Always NUL terminates (unless dsize == 0).
|
||||
* Returns strlen(src); if retval >= dsize, truncation occurred.
|
||||
*/
|
||||
size_t
|
||||
strlcpy(char *dst, const char *src, size_t dsize)
|
||||
{
|
||||
const char *osrc = src;
|
||||
size_t nleft = dsize;
|
||||
|
||||
/* Copy as many bytes as will fit. */
|
||||
if (nleft != 0) {
|
||||
while (--nleft != 0) {
|
||||
if ((*dst++ = *src++) == '\0')
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Not enough room in dst, add NUL and traverse rest of src. */
|
||||
if (nleft == 0) {
|
||||
if (dsize != 0)
|
||||
*dst = '\0'; /* NUL-terminate dst */
|
||||
while (*src++)
|
||||
;
|
||||
}
|
||||
|
||||
return(src - osrc - 1); /* count does not include NUL */
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: strtonum.c,v 1.6 2004/08/03 19:38:01 millert Exp $ */
|
||||
/* $OpenBSD: strtonum.c,v 1.7 2013/04/17 18:40:58 tedu Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2004 Ted Unangst and Todd Miller
|
||||
@ -17,35 +17,23 @@
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#include "ezstream.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
#include <stdlib.h>
|
||||
#include "strfctns.h"
|
||||
|
||||
#define INVALID 1
|
||||
#define TOOSMALL 2
|
||||
#define TOOLARGE 3
|
||||
#include "compat.h"
|
||||
|
||||
#if !defined(LLONG_MIN) || !defined(LLONG_MAX)
|
||||
# undef LLONG_MIN
|
||||
# undef LLONG_MAX
|
||||
# define LLONG_MIN LONG_LONG_MIN
|
||||
# define LLONG_MAX LONG_LONG_MAX
|
||||
#endif
|
||||
#define INVALID 1
|
||||
#define TOOSMALL 2
|
||||
#define TOOLARGE 3
|
||||
|
||||
long long
|
||||
local_strtonum(const char *numstr, long long minval, long long maxval,
|
||||
strtonum(const char *numstr, long long minval, long long maxval,
|
||||
const char **errstrp)
|
||||
{
|
||||
long long ll = 0;
|
||||
char *ep;
|
||||
int error = 0;
|
||||
char *ep;
|
||||
struct errval {
|
||||
const char *errstr;
|
||||
int err;
|
||||
@ -58,9 +46,9 @@ local_strtonum(const char *numstr, long long minval, long long maxval,
|
||||
|
||||
ev[0].err = errno;
|
||||
errno = 0;
|
||||
if (minval > maxval)
|
||||
if (minval > maxval) {
|
||||
error = INVALID;
|
||||
else {
|
||||
} else {
|
||||
ll = strtoll(numstr, &ep, 10);
|
||||
if (numstr == ep || *ep != '\0')
|
||||
error = INVALID;
|
@ -1,4 +1,4 @@
|
||||
AUTOMAKE_OPTIONS = 1.10 foreign
|
||||
AUTOMAKE_OPTIONS = 1.10 foreign subdir-objects
|
||||
|
||||
EXTRA_DIST = tree.h tree.3
|
||||
|
||||
|
@ -9,7 +9,7 @@ AC_CONFIG_SRCDIR([src/ezstream.c])
|
||||
AC_CONFIG_AUX_DIR([build-aux])
|
||||
AM_INIT_AUTOMAKE
|
||||
AC_CONFIG_HEADERS([src/config.h])
|
||||
AC_CONFIG_LIBOBJ_DIR([src])
|
||||
AC_CONFIG_LIBOBJ_DIR([compat])
|
||||
AM_MAINTAINER_MODE
|
||||
AC_USE_SYSTEM_EXTENSIONS
|
||||
AC_PROG_CC_STDC
|
||||
@ -211,7 +211,6 @@ dnl #######################
|
||||
AC_CHECK_FUNCS([ \
|
||||
arc4random \
|
||||
basename \
|
||||
getopt \
|
||||
gettimeofday \
|
||||
nl_langinfo \
|
||||
pclose \
|
||||
@ -232,6 +231,7 @@ AC_CHECK_FUNCS([ \
|
||||
])
|
||||
|
||||
AC_REPLACE_FUNCS([ \
|
||||
getopt \
|
||||
strlcat \
|
||||
strlcpy \
|
||||
strtonum \
|
||||
|
@ -1,4 +1,4 @@
|
||||
AUTOMAKE_OPTIONS = 1.10 foreign
|
||||
AUTOMAKE_OPTIONS = 1.10 foreign subdir-objects
|
||||
|
||||
man_MANS = ezstream.1 ezstream-file.sh.1
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
AUTOMAKE_OPTIONS = 1.10 foreign
|
||||
AUTOMAKE_OPTIONS = 1.10 foreign subdir-objects
|
||||
|
||||
examplesdir = @EXAMPLES_DIR@
|
||||
dist_examples_DATA = \
|
||||
|
@ -1,4 +1,4 @@
|
||||
AUTOMAKE_OPTIONS = 1.10 foreign
|
||||
AUTOMAKE_OPTIONS = 1.10 foreign subdir-objects
|
||||
|
||||
CLEANFILES = core *.core *~ .*~
|
||||
|
||||
|
@ -1,13 +1,12 @@
|
||||
AUTOMAKE_OPTIONS = 1.10 foreign
|
||||
AUTOMAKE_OPTIONS = 1.10 foreign subdir-objects
|
||||
|
||||
bin_PROGRAMS = ezstream
|
||||
bin_SCRIPTS = ezstream-file.sh
|
||||
|
||||
ezstream_SOURCES = \
|
||||
compat.c \
|
||||
configfile.c \
|
||||
ezstream.c \
|
||||
getopt.c \
|
||||
local_basename.c \
|
||||
metadata.c \
|
||||
playlist.c \
|
||||
util.c \
|
||||
@ -21,9 +20,9 @@ AM_LDFLAGS = @EZ_LDFLAGS@
|
||||
EXTRA_DIST = \
|
||||
configfile.h \
|
||||
ezstream.h \
|
||||
local_basename.h \
|
||||
metadata.h \
|
||||
playlist.h \
|
||||
strfctns.h \
|
||||
util.h \
|
||||
xalloc.h
|
||||
|
||||
|
@ -23,8 +23,9 @@
|
||||
|
||||
#include "ezstream.h"
|
||||
|
||||
#include "compat.h"
|
||||
|
||||
#include "configfile.h"
|
||||
#include "strfctns.h"
|
||||
#include "util.h"
|
||||
#include "xalloc.h"
|
||||
|
||||
|
@ -29,13 +29,16 @@
|
||||
|
||||
#include <shout/shout.h>
|
||||
|
||||
#include "compat.h"
|
||||
|
||||
#include "configfile.h"
|
||||
#include "metadata.h"
|
||||
#include "playlist.h"
|
||||
#include "strfctns.h"
|
||||
#include "util.h"
|
||||
#include "xalloc.h"
|
||||
|
||||
#include "local_basename.h"
|
||||
|
||||
#define STREAM_DONE 0
|
||||
#define STREAM_CONT 1
|
||||
#define STREAM_SKIP 2
|
||||
@ -1149,7 +1152,7 @@ main(int argc, char *argv[])
|
||||
qFlag = 0;
|
||||
vFlag = 0;
|
||||
|
||||
while ((c = local_getopt(argc, argv, "c:hmnqsVv")) != -1) {
|
||||
while ((c = getopt(argc, argv, "c:hmnqsVv")) != -1) {
|
||||
switch (c) {
|
||||
case 'c':
|
||||
if (configFile != NULL) {
|
||||
|
@ -14,8 +14,8 @@
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef __COMPAT_H__
|
||||
#define __COMPAT_H__
|
||||
#ifndef __EZSTREAM_H__
|
||||
#define __EZSTREAM_H__
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
@ -98,22 +98,4 @@
|
||||
# define sleep(a) Sleep((a) * 1000)
|
||||
#endif /* WIN32 */
|
||||
|
||||
/*
|
||||
* For compat.c and getopt.c:
|
||||
*/
|
||||
|
||||
extern int opterr;
|
||||
extern int optind;
|
||||
extern int optopt;
|
||||
extern int optreset;
|
||||
extern char *optarg;
|
||||
|
||||
extern int
|
||||
local_getopt(int, char * const *, const char *);
|
||||
|
||||
extern const char *path_separators;
|
||||
|
||||
extern char *
|
||||
local_basename(const char *);
|
||||
|
||||
#endif /* __COMPAT_H__ */
|
||||
#endif /* __EZSTREAM_H__ */
|
||||
|
@ -2,11 +2,18 @@
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#include "ezstream.h"
|
||||
#ifdef HAVE_SYS_TYPES_H
|
||||
# include <sys/types.h>
|
||||
#endif /* HAVE_SYS_TYPES_H */
|
||||
|
||||
#include <errno.h>
|
||||
#if defined(HAVE_LIBGEN_H) && !defined(__linux__)
|
||||
# include <libgen.h>
|
||||
#endif /* HAVE_LIBGEN_H && !__linux__ */
|
||||
#include <limits.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "local_basename.h"
|
||||
|
||||
#ifndef PATH_SEPARATORS
|
||||
# define PATH_SEPARATORS "/"
|
||||
@ -34,7 +41,7 @@ is_separator(int c)
|
||||
|
||||
/*
|
||||
* Modified basename() implementation from OpenBSD, based on:
|
||||
* $OpenBSD: src/lib/libc/gen/basename.c,v 1.14 2005/08/08 08:05:33 espie Exp $
|
||||
* $OpenBSD: src/lib/libc/gen/basename.c,v 1.15 2013/09/30 12:02:32 millert Exp $
|
||||
*/
|
||||
/*
|
||||
* Copyright (c) 1997, 2004 Todd C. Miller <Todd.Miller@courtesan.com>
|
8
src/local_basename.h
Normal file
8
src/local_basename.h
Normal file
@ -0,0 +1,8 @@
|
||||
#ifndef __LOCAL_BASENAME_H__
|
||||
#define __LOCAL_BASENAME_H__
|
||||
|
||||
extern const char *path_separators;
|
||||
|
||||
char * local_basename(const char *);
|
||||
|
||||
#endif /* __LOCAL_BASENAME_H__ */
|
@ -20,6 +20,8 @@
|
||||
|
||||
#include "ezstream.h"
|
||||
|
||||
#include "compat.h"
|
||||
|
||||
#ifdef HAVE_TAGLIB
|
||||
# include <taglib/tag_c.h>
|
||||
#endif /* HAVE_TAGLIB */
|
||||
@ -29,10 +31,11 @@
|
||||
#include <shout/shout.h>
|
||||
|
||||
#include "metadata.h"
|
||||
#include "strfctns.h"
|
||||
#include "util.h"
|
||||
#include "xalloc.h"
|
||||
|
||||
#include "local_basename.h"
|
||||
|
||||
/* Usually defined in <sys/stat.h>. */
|
||||
#ifndef S_IEXEC
|
||||
# define S_IEXEC S_IXUSR
|
||||
|
@ -1,23 +0,0 @@
|
||||
#ifndef __STRLFCTNS_H__
|
||||
#define __STRLFCTNS_H__
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_STRLCAT
|
||||
# define strlcat local_strlcat
|
||||
#endif
|
||||
size_t local_strlcat(char *, const char *, size_t);
|
||||
|
||||
#ifndef HAVE_STRLCPY
|
||||
# define strlcpy local_strlcpy
|
||||
#endif
|
||||
size_t local_strlcpy(char *, const char *, size_t);
|
||||
|
||||
#ifndef HAVE_STRTONUM
|
||||
# define strtonum local_strtonum
|
||||
#endif
|
||||
long long local_strtonum(const char *, long long, long long, const char **);
|
||||
|
||||
#endif /* __STRLFCTNS_H__ */
|
@ -1,58 +0,0 @@
|
||||
/* $OpenBSD: strlcpy.c,v 1.11 2006/05/05 15:27:38 millert Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
|
||||
*
|
||||
* 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 <string.h>
|
||||
#include "strfctns.h"
|
||||
|
||||
/*
|
||||
* Copy src to string dst of size siz. At most siz-1 characters
|
||||
* will be copied. Always NUL terminates (unless siz == 0).
|
||||
* Returns strlen(src); if retval >= siz, truncation occurred.
|
||||
*/
|
||||
size_t
|
||||
local_strlcpy(char *dst, const char *src, size_t siz)
|
||||
{
|
||||
char *d = dst;
|
||||
const char *s = src;
|
||||
size_t n = siz;
|
||||
|
||||
/* Copy as many bytes as will fit */
|
||||
if (n != 0) {
|
||||
while (--n != 0) {
|
||||
if ((*d++ = *s++) == '\0')
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Not enough room in dst, add NUL and traverse rest of src */
|
||||
if (n == 0) {
|
||||
if (siz != 0)
|
||||
*d = '\0'; /* NUL-terminate dst */
|
||||
while (*s++)
|
||||
;
|
||||
}
|
||||
|
||||
return(s - src - 1); /* count does not include NUL */
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
AUTOMAKE_OPTIONS = 1.10 foreign
|
||||
AUTOMAKE_OPTIONS = 1.10 foreign subdir-objects
|
||||
|
||||
SUBDIRS = shout
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
AUTOMAKE_OPTIONS = 1.10 foreign
|
||||
AUTOMAKE_OPTIONS = 1.10 foreign subdir-objects
|
||||
|
||||
EXTRA_DIST = shout.h
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user