Commit 6ac1fb23 authored by Michael Sweet's avatar Michael Sweet

Use vasprintf when available.

Use strlcpy when available.

Add xcode project.
parent 1272c3df
......@@ -21,4 +21,8 @@ org.minixml.atom
org.minixml.docset
org.minixml.xar
temp1.xmlfd
test.xmlfd
testmxml
test1.xml
xcode/mxml.xcodeproj/project.xcworkspace
xcode/mxml.xcodeproj/xcuserdata
......@@ -45,10 +45,11 @@
/*
* Do we have the snprintf() and vsnprintf() functions?
* Do we have the *printf() functions?
*/
#undef HAVE_SNPRINTF
#undef HAVE_VASPRINTF
#undef HAVE_VSNPRINTF
......@@ -57,6 +58,7 @@
*/
#undef HAVE_STRDUP
#undef HAVE_STRLCPY
/*
......@@ -75,6 +77,11 @@ extern char *_mxml_strdup(const char *);
# define strdup _mxml_strdup
# endif /* !HAVE_STRDUP */
# ifndef HAVE_STRLCPY
extern size_t _mxml_strlcpy(char *, const char *, size_t);
# define strlcpy _mxml_strlcpy
# endif /* !HAVE_STRLCPY */
extern char *_mxml_strdupf(const char *, ...);
extern char *_mxml_vstrdupf(const char *, va_list);
......
......@@ -3899,12 +3899,13 @@ esac
if test "x$use_ansi" != xyes; then
for ac_func in strdup
for ac_func in strdup strlcpy
do :
ac_fn_c_check_func "$LINENO" "strdup" "ac_cv_func_strdup"
if test "x$ac_cv_func_strdup" = xyes; then :
as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
if eval test \"x\$"$as_ac_var"\" = x"yes"; then :
cat >>confdefs.h <<_ACEOF
#define HAVE_STRDUP 1
#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1
_ACEOF
fi
......@@ -3913,7 +3914,7 @@ done
fi
if test "x$use_vsnprintf" != xyes; then
for ac_func in snprintf vsnprintf
for ac_func in snprintf vasprintf vsnprintf
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"
......
......@@ -95,11 +95,11 @@ AC_C_INLINE
dnl Checks for string functions.
if test "x$use_ansi" != xyes; then
AC_CHECK_FUNCS(strdup)
AC_CHECK_FUNCS(strdup strlcpy)
fi
if test "x$use_vsnprintf" != xyes; then
AC_CHECK_FUNCS(snprintf vsnprintf)
AC_CHECK_FUNCS(snprintf vasprintf vsnprintf)
fi
dnl Check for "long long" support...
......
......@@ -394,7 +394,7 @@ mxmlSaveString(mxml_node_t *node, /* I - Node to write */
* Return the number of characters...
*/
return (ptr[0] - buffer);
return ((int)(ptr[0] - buffer));
}
......@@ -1016,7 +1016,7 @@ mxml_fd_read(_mxml_fdbuf_t *buf) /* I - File descriptor buffer */
* Read from the file descriptor...
*/
while ((bytes = read(buf->fd, buf->buffer, sizeof(buf->buffer))) < 0)
while ((bytes = (int)read(buf->fd, buf->buffer, sizeof(buf->buffer))) < 0)
#ifdef EINTR
if (errno != EAGAIN && errno != EINTR)
#else
......@@ -1068,7 +1068,7 @@ mxml_fd_write(_mxml_fdbuf_t *buf) /* I - File descriptor buffer */
*/
for (ptr = buf->buffer; ptr < buf->current; ptr += bytes)
if ((bytes = write(buf->fd, ptr, buf->current - ptr)) < 0)
if ((bytes = (int)write(buf->fd, ptr, buf->current - ptr)) < 0)
return (-1);
/*
......@@ -1352,9 +1352,9 @@ mxml_get_entity(mxml_node_t *parent, /* I - Parent node */
if (entity[0] == '#')
{
if (entity[1] == 'x')
ch = strtol(entity + 2, NULL, 16);
ch = (int)strtol(entity + 2, NULL, 16);
else
ch = strtol(entity + 1, NULL, 10);
ch = (int)strtol(entity + 1, NULL, 10);
}
else if ((ch = mxmlEntityGetValue(entity)) < 0)
mxml_error("Entity name \"%s;\" not supported under parent <%s>!",
......@@ -1446,7 +1446,7 @@ mxml_load_data(
switch (type)
{
case MXML_INTEGER :
node = mxmlNewInteger(parent, strtol(buffer, &bufptr, 0));
node = mxmlNewInteger(parent, (int)strtol(buffer, &bufptr, 0));
break;
case MXML_OPAQUE :
......@@ -2761,7 +2761,7 @@ mxml_write_node(mxml_node_t *node, /* I - Node to write */
i > 0;
i --, attr ++)
{
width = strlen(attr->name);
width = (int)strlen(attr->name);
if (attr->value)
width += strlen(attr->value) + 3;
......@@ -2932,7 +2932,7 @@ mxml_write_node(mxml_node_t *node, /* I - Node to write */
if ((newline = strrchr(data, '\n')) == NULL)
col += strlen(data);
else
col = strlen(newline);
col = (int)strlen(newline);
free(data);
break;
......
......@@ -119,7 +119,8 @@ mxmlIndexFind(mxml_index_t *ind, /* I - Index to search */
{
#ifdef DEBUG
puts(" returning NULL...");
printf(" ind->attr=\"%s\"\n", ind->attr ? ind->attr : "(null)");
if (ind)
printf(" ind->attr=\"%s\"\n", ind->attr ? ind->attr : "(null)");
#endif /* DEBUG */
return (NULL);
......
......@@ -97,13 +97,53 @@ _mxml_strdupf(const char *format, /* I - Printf-style format string */
*/
va_start(ap, format);
#ifdef HAVE_VASPRINTF
vasprintf(&s, format, ap);
#else
s = _mxml_vstrdupf(format, ap);
#endif /* HAVE_VASPRINTF */
va_end(ap);
return (s);
}
#ifndef HAVE_STRLCPY
/*
* '_mxml_strlcpy()' - Safely copy a string.
*/
size_t /* O - Number of bytes copied */
_mxml_strlcpy(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 */
/*
* Figure out how much room is needed...
*/
dstsize --;
srclen = strlen(src);
/*
* Copy the appropriate amount...
*/
if (srclen > dstsize)
srclen = dstsize;
memmove(dst, src, srclen);
dst[srclen] = '\0';
return (srclen);
}
#endif /* !HAVE_STRLCPY */
#ifndef HAVE_VSNPRINTF
/*
* '_mxml_vsnprintf()' - Format a string into a fixed size buffer.
......@@ -423,6 +463,14 @@ char * /* O - New string pointer */
_mxml_vstrdupf(const char *format, /* I - Printf-style format string */
va_list ap) /* I - Pointer to additional arguments */
{
#ifdef HAVE_VASPRINTF
char *s; /* String */
vasprintf(&s, format, ap);
return (s);
#else
int bytes; /* Number of bytes required */
char *buffer, /* String buffer */
temp[256]; /* Small buffer for first vsnprintf */
......@@ -459,4 +507,5 @@ _mxml_vstrdupf(const char *format, /* I - Printf-style format string */
*/
return (buffer);
#endif /* HAVE_VASPRINTF */
}
......@@ -644,7 +644,7 @@ add_variable(mxml_node_t *parent, /* I - Parent node */
if (node->value.text.whitespace && bufptr > buffer)
*bufptr++ = ' ';
strcpy(bufptr, node->value.text.string);
strlcpy(bufptr, node->value.text.string, sizeof(buffer) - (size_t)(bufptr - buffer));
next = node->next;
mxmlDelete(node);
......@@ -673,7 +673,7 @@ add_variable(mxml_node_t *parent, /* I - Parent node */
if (node->value.text.whitespace && bufptr > buffer)
*bufptr++ = ' ';
strcpy(bufptr, node->value.text.string);
strlcpy(bufptr, node->value.text.string, sizeof(buffer) - (size_t)(bufptr - buffer));
next = node->next;
mxmlDelete(node);
......@@ -686,7 +686,7 @@ add_variable(mxml_node_t *parent, /* I - Parent node */
* Handle "type name"...
*/
strcpy(buffer, type->last_child->value.text.string);
strlcpy(buffer, type->last_child->value.text.string, sizeof(buffer));
mxmlDelete(type->last_child);
}
......@@ -797,8 +797,7 @@ get_comment_info(
return ("<span class=\"info\">&nbsp;DEPRECATED&nbsp;</span>");
else if (!strncmp(ptr, "@since ", 7))
{
strncpy(since, ptr + 7, sizeof(since) - 1);
since[sizeof(since) - 1] = '\0';
strlcpy(since, ptr + 7, sizeof(since));
if ((ptr = strchr(since, '@')) != NULL)
*ptr = '\0';
......@@ -1215,7 +1214,7 @@ scan_file(const char *filename, /* I - Filename */
if (node->value.text.whitespace && bufptr > buffer)
*bufptr++ = ' ';
strcpy(bufptr, node->value.text.string);
strlcpy(bufptr, node->value.text.string, sizeof(buffer) - (size_t)(bufptr - buffer));
next = node->next;
mxmlDelete(node);
......
......@@ -708,6 +708,9 @@ main(int argc, /* I - Number of command-line args */
}
}
if (getenv("TEST_DELAY") != NULL)
sleep(atoi(getenv("TEST_DELAY")));
/*
* Return...
*/
......@@ -736,6 +739,8 @@ sax_cb(mxml_node_t *node, /* I - Current node */
};
(void)data;
/*
* This SAX callback just counts the different events.
*/
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment