Fix compile issues on Linux (Issue #200)

This commit is contained in:
Michael R Sweet 2017-06-27 13:06:25 -04:00
parent 3836e126a8
commit 6f51c8ece5
8 changed files with 93 additions and 24 deletions

View File

@ -84,6 +84,11 @@ extern char *_mxml_strdup(const char *);
# define strdup _mxml_strdup
# endif /* !HAVE_STRDUP */
# ifndef HAVE_STRLCAT
extern size_t _mxml_strlcat(char *, const char *, size_t);
# define strlcat _mxml_strlcat
# endif /* !HAVE_STRLCAT */
# ifndef HAVE_STRLCPY
extern size_t _mxml_strlcpy(char *, const char *, size_t);
# define strlcpy _mxml_strlcpy

18
configure vendored
View File

@ -687,6 +687,7 @@ infodir
docdir
oldincludedir
includedir
runstatedir
localstatedir
sharedstatedir
sysconfdir
@ -767,6 +768,7 @@ datadir='${datarootdir}'
sysconfdir='${prefix}/etc'
sharedstatedir='${prefix}/com'
localstatedir='${prefix}/var'
runstatedir='${localstatedir}/run'
includedir='${prefix}/include'
oldincludedir='/usr/include'
docdir='${datarootdir}/doc/${PACKAGE_TARNAME}'
@ -1019,6 +1021,15 @@ do
| -silent | --silent | --silen | --sile | --sil)
silent=yes ;;
-runstatedir | --runstatedir | --runstatedi | --runstated \
| --runstate | --runstat | --runsta | --runst | --runs \
| --run | --ru | --r)
ac_prev=runstatedir ;;
-runstatedir=* | --runstatedir=* | --runstatedi=* | --runstated=* \
| --runstate=* | --runstat=* | --runsta=* | --runst=* | --runs=* \
| --run=* | --ru=* | --r=*)
runstatedir=$ac_optarg ;;
-sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb)
ac_prev=sbindir ;;
-sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \
@ -1156,7 +1167,7 @@ fi
for ac_var in exec_prefix prefix bindir sbindir libexecdir datarootdir \
datadir sysconfdir sharedstatedir localstatedir includedir \
oldincludedir docdir infodir htmldir dvidir pdfdir psdir \
libdir localedir mandir
libdir localedir mandir runstatedir
do
eval ac_val=\$$ac_var
# Remove trailing slashes.
@ -1309,6 +1320,7 @@ Fine tuning of the installation directories:
--sysconfdir=DIR read-only single-machine data [PREFIX/etc]
--sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com]
--localstatedir=DIR modifiable single-machine data [PREFIX/var]
--runstatedir=DIR modifiable per-process data [LOCALSTATEDIR/run]
--libdir=DIR object code libraries [EPREFIX/lib]
--includedir=DIR C header files [PREFIX/include]
--oldincludedir=DIR C header files for non-gcc [/usr/include]
@ -3901,7 +3913,7 @@ esac
if test "x$use_ansi" != xyes; then
for ac_func in strdup strlcpy
for ac_func in strdup strlcat strlcpy
do :
as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
@ -4588,7 +4600,7 @@ fi
if test -n "$GCC"; then
CFLAGS="-Wall $CFLAGS"
CFLAGS="-Wall -D_GNU_SOURCE $CFLAGS"
if test "x$OPTIM" = x; then
OPTIM="-Os -g"

View File

@ -95,7 +95,7 @@ AC_C_INLINE
dnl Checks for string functions.
if test "x$use_ansi" != xyes; then
AC_CHECK_FUNCS(strdup strlcpy)
AC_CHECK_FUNCS(strdup strlcat strlcpy)
fi
if test "x$use_vsnprintf" != xyes; then
@ -252,7 +252,7 @@ AC_SUBST(PICFLAG)
dnl Add -Wall for GCC...
if test -n "$GCC"; then
CFLAGS="-Wall $CFLAGS"
CFLAGS="-Wall -D_GNU_SOURCE $CFLAGS"
if test "x$OPTIM" = x; then
OPTIM="-Os -g"

View File

@ -1,4 +1,4 @@
.TH mxml 3 "Mini-XML API" "06/09/17" "Mini-XML API"
.TH mxml 3 "Mini-XML API" "06/27/17" "Mini-XML API"
.SH NAME
mxml \- Mini-XML API
.SH INCLUDE FILE

2
mmd.c
View File

@ -479,6 +479,8 @@ mmdLoadFile(FILE *fp) /* I - File to load */
block = NULL;
continue;
}
type = MMD_TYPE_PARAGRAPH;
}
else if ((*lineptr == '-' || *lineptr == '+' || *lineptr == '*') && isspace(lineptr[1] & 255))
{

View File

@ -98,7 +98,8 @@ _mxml_strdupf(const char *format, /* I - Printf-style format string */
va_start(ap, format);
#ifdef HAVE_VASPRINTF
vasprintf(&s, format, ap);
if (vasprintf(&s, format, ap) < 0)
s = NULL;
#else
s = _mxml_vstrdupf(format, ap);
#endif /* HAVE_VASPRINTF */
@ -108,6 +109,52 @@ _mxml_strdupf(const char *format, /* I - Printf-style format string */
}
#ifndef HAVE_STRLCAT
/*
* '_mxml_strlcat()' - Safely concatenate a string.
*/
size_t /* O - Number of bytes copied */
_mxml_strlcat(char *dst, /* I - Destination buffer */
const char *src, /* I - Source string */
size_t dstsize) /* I - Size of destinatipon buffer */
{
size_t srclen; /* Length of source string */
size_t dstlen; /* Length of destination string */
/*
* Figure out how much room is left...
*/
dstlen = strlen(dst);
if (dstsize <= (dstlen + 1))
return (dstlen); /* No room, return immediately... */
dstsize -= dstlen + 1;
/*
* Figure out how much room is needed...
*/
srclen = strlen(src);
/*
* Copy the appropriate amount...
*/
if (srclen > dstsize)
srclen = dstsize;
memmove(dst + dstlen, src, srclen);
dst[dstlen + srclen] = '\0';
return (dstlen + srclen);
}
#endif /* !HAVE_STRLCAT */
#ifndef HAVE_STRLCPY
/*
* '_mxml_strlcpy()' - Safely copy a string.
@ -466,7 +513,8 @@ _mxml_vstrdupf(const char *format, /* I - Printf-style format string */
#ifdef HAVE_VASPRINTF
char *s; /* String */
vasprintf(&s, format, ap);
if (vasprintf(&s, format, ap) < 0)
s = NULL;
return (s);

View File

@ -175,7 +175,9 @@ static const char *markdown_anchor(const char *text);
static void markdown_write_block(FILE *out, mmd_t *parent, int mode);
static void markdown_write_leaf(FILE *out, mmd_t *node, int mode);
static mxml_node_t *new_documentation(mxml_node_t **mxmldoc);
#ifdef __APPLE__
static int remove_directory(const char *path);
#endif /* __APPLE__ */
static void safe_strcpy(char *dst, const char *src);
static int scan_file(const char *filename, FILE *fp, mxml_node_t *doc);
static void sort_node(mxml_node_t *tree, mxml_node_t *func);
@ -1879,6 +1881,7 @@ new_documentation(mxml_node_t **mxmldoc)/* O - mxmldoc node */
}
#ifdef __APPLE__
/*
* 'remove_directory()' - Remove a directory.
*/
@ -1886,10 +1889,6 @@ new_documentation(mxml_node_t **mxmldoc)/* O - mxmldoc node */
static int /* O - 1 on success, 0 on failure */
remove_directory(const char *path) /* I - Directory to remove */
{
#ifdef WIN32
/* TODO: Add Windows directory removal code */
#else
DIR *dir; /* Directory */
struct dirent *dent; /* Current directory entry */
char filename[1024]; /* Current filename */
@ -1951,10 +1950,10 @@ remove_directory(const char *path) /* I - Directory to remove */
strerror(errno));
return (0);
}
#endif /* WIN32 */
return (1);
}
#endif /* __APPLE__ */
/*
@ -3929,9 +3928,16 @@ write_docset(const char *docset, /* I - Documentation set directory */
mxml_node_t *doc, /* I - XML documentation */
const char *footerfile) /* I - Footer file */
{
FILE *out; /* Output file */
char filename[1024]; /* Current output filename */
toc_t *toc; /* Table of contents */
FILE *out; /* Output file */
char filename[1024]; /* Current output filename */
toc_t *toc; /* Table of contents */
const char *id; /* Identifier */
size_t i; /* Looping var */
toc_entry_t *tentry; /* Current table of contents */
int toc_level; /* Current table-of-contents level */
int xmlid = 1; /* Current XML node ID */
const char *indent; /* Indentation */
/*
@ -3945,13 +3951,6 @@ write_docset(const char *docset, /* I - Documentation set directory */
* output directory...
*/
const char *id; /* Identifier */
size_t i; /* Looping var */
toc_entry_t *tentry; /* Current table of contents */
int toc_level; /* Current table-of-contents level */
int xmlid = 1; /* Current XML node ID */
const char *indent; /* Indentation */
if (!access(docset, 0) && !remove_directory(docset))
return;

View File

@ -715,13 +715,16 @@ main(int argc, /* I - Number of command-line args */
if (getenv("TEST_DELAY") != NULL)
sleep(atoi(getenv("TEST_DELAY")));
# ifdef __APPLE__
if (getenv("TEST_LEAKS") != NULL)
{
char command[1024];
snprintf(command, sizeof(command), "leaks %d", (int)getpid());
system(command);
if (system(command))
puts("Unable to check for leaks.");
}
# endif /* __APPLE__ */
#endif /* !WIN32 */
/*