added floating-point formatting implementation in basic logging functions.
changed O_CLOEXEC to EPOLL_CLOEXEC in a call to epoll_create1()
This commit is contained in:
@ -13,6 +13,9 @@ LDFLAGS_ALL_COMMON = -L$(abs_builddir) -L$(libdir)
|
||||
|
||||
CPPFLAGS_LIB_COMMON = $(CPPFLAGS_ALL_COMMON)
|
||||
LDFLAGS_LIB_COMMON = $(LDFLAGS_ALL_COMMON) -version-info 1:0:0 -no-undefined
|
||||
|
||||
# $(LIBM) here for quadmath_snprintf() in libquadmath
|
||||
# TODO: make this selective by moving MIO_ENABLE_FLTFMT to configure.ac
|
||||
LIBADD_LIB_COMMON = $(LIBM)
|
||||
|
||||
#pkgincludedir = $(includedir)
|
||||
|
@ -403,6 +403,7 @@ pdfdir = @pdfdir@
|
||||
prefix = @prefix@
|
||||
program_transform_name = @program_transform_name@
|
||||
psdir = @psdir@
|
||||
runstatedir = @runstatedir@
|
||||
sbindir = @sbindir@
|
||||
sharedstatedir = @sharedstatedir@
|
||||
srcdir = @srcdir@
|
||||
@ -424,6 +425,9 @@ LDFLAGS_ALL_COMMON = -L$(abs_builddir) -L$(libdir)
|
||||
##################################################
|
||||
CPPFLAGS_LIB_COMMON = $(CPPFLAGS_ALL_COMMON)
|
||||
LDFLAGS_LIB_COMMON = $(LDFLAGS_ALL_COMMON) -version-info 1:0:0 -no-undefined
|
||||
|
||||
# $(LIBM) here for quadmath_snprintf() in libquadmath
|
||||
# TODO: make this selective by moving MIO_ENABLE_FLTFMT to configure.ac
|
||||
LIBADD_LIB_COMMON = $(LIBM)
|
||||
|
||||
#pkgincludedir = $(includedir)
|
||||
|
212
mio/lib/fmt.c
212
mio/lib/fmt.c
@ -68,7 +68,8 @@
|
||||
#include "mio-prv.h"
|
||||
|
||||
|
||||
#if 0
|
||||
#if defined(MIO_ENABLE_FLTFMT)
|
||||
|
||||
#include <stdio.h> /* for snrintf(). used for floating-point number formatting */
|
||||
#if defined(_MSC_VER) || defined(__BORLANDC__) || (defined(__WATCOMC__) && (__WATCOMC__ < 1200))
|
||||
# define snprintf _snprintf
|
||||
@ -79,6 +80,7 @@
|
||||
#if defined(HAVE_QUADMATH_H)
|
||||
# include <quadmath.h> /* for quadmath_snprintf() */
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/* Max number conversion buffer length:
|
||||
@ -287,10 +289,25 @@ static int fmt_outv (mio_fmtout_t* fmtout, va_list ap)
|
||||
mio_bch_t nbuf[MAXNBUF];
|
||||
const mio_bch_t* nbufp;
|
||||
int stop = 0;
|
||||
#if 0
|
||||
mio_bchbuf_t* fltfmt;
|
||||
mio_oochbuf_t* fltout;
|
||||
|
||||
#if defined(MIO_ENABLE_FLTFMT)
|
||||
struct
|
||||
{
|
||||
struct
|
||||
{
|
||||
mio_bch_t sbuf[32];
|
||||
mio_bch_t* ptr;
|
||||
mio_oow_t capa;
|
||||
} fmt;
|
||||
struct
|
||||
{
|
||||
mio_bch_t sbuf[64];
|
||||
mio_bch_t* ptr;
|
||||
mio_oow_t capa;
|
||||
} out;
|
||||
} fb; /* some buffers for handling float-point number formatting */
|
||||
#endif
|
||||
|
||||
mio_bch_t* (*sprintn) (mio_bch_t* nbuf, mio_uintmax_t num, int base, mio_ooi_t* lenp);
|
||||
|
||||
fmtptr = (const mio_uint8_t*)fmtout->fmt_str;
|
||||
@ -306,16 +323,11 @@ static int fmt_outv (mio_fmtout_t* fmtout, va_list ap)
|
||||
|
||||
/* this is an internal function. it doesn't reset count to 0 */
|
||||
/* fmtout->count = 0; */
|
||||
|
||||
#if 0
|
||||
fltfmt = &mio->d->fltfmt;
|
||||
fltout = &mio->d->fltout;
|
||||
|
||||
fltfmt->ptr = fltfmt->buf;
|
||||
fltfmt->capa = MIO_COUNTOF(fltfmt->buf) - 1;
|
||||
|
||||
fltout->ptr = fltout->buf;
|
||||
fltout->capa = MIO_COUNTOF(fltout->buf) - 1;
|
||||
#if defined(MIO_ENABLE_FLTFMT)
|
||||
fb.fmt.ptr = fb.fmt.sbuf;
|
||||
fb.fmt.capa = MIO_COUNTOF(fb.fmt.sbuf) - 1;
|
||||
fb.out.ptr = fb.out.sbuf;
|
||||
fb.out.capa = MIO_COUNTOF(fb.out.sbuf) - 1;
|
||||
#endif
|
||||
|
||||
while (1)
|
||||
@ -429,7 +441,6 @@ static int fmt_outv (mio_fmtout_t* fmtout, va_list ap)
|
||||
flagc &= ~FLAGC_ZEROPAD;
|
||||
}
|
||||
}
|
||||
|
||||
goto reswitch;
|
||||
|
||||
case '*': /* take the length from the parameter */
|
||||
@ -515,7 +526,7 @@ static int fmt_outv (mio_fmtout_t* fmtout, va_list ap)
|
||||
case 'q': /* long long int */
|
||||
case 'j': /* mio_intmax_t/mio_uintmax_t */
|
||||
case 'z': /* mio_ooi_t/mio_oow_t */
|
||||
case 't': /* ptrdiff_t */
|
||||
case 't': /* ptrdiff_t - usually mio_intptr_t */
|
||||
if (lm_flag & (LF_LD | LF_QD)) goto invalid_format;
|
||||
|
||||
flagc |= FLAGC_LENMOD;
|
||||
@ -874,6 +885,13 @@ static int fmt_outv (mio_fmtout_t* fmtout, va_list ap)
|
||||
}
|
||||
|
||||
#if 0
|
||||
case 'O': /* object - ignore precision, width, adjustment */
|
||||
if (!fmtout->putobj) goto invalid_format;
|
||||
if (fmtout->putobj(fmtout, va_arg(ap, mio_oop_t)) <= -1) goto oops;
|
||||
break;
|
||||
#endif
|
||||
|
||||
#if defined(MIO_ENABLE_FLTFMT)
|
||||
case 'e':
|
||||
case 'E':
|
||||
case 'f':
|
||||
@ -888,23 +906,27 @@ static int fmt_outv (mio_fmtout_t* fmtout, va_list ap)
|
||||
/* let me rely on snprintf until i implement float-point to string conversion */
|
||||
int q;
|
||||
mio_oow_t fmtlen;
|
||||
#if (MIO_SIZEOF___FLOAT128 > 0) && defined(HAVE_QUADMATH_SNPRINTF)
|
||||
__float128 v_qd;
|
||||
#endif
|
||||
long double v_ld;
|
||||
double v_d;
|
||||
union
|
||||
{
|
||||
#if (MIO_SIZEOF___FLOAT128 > 0) && defined(HAVE_QUADMATH_SNPRINTF)
|
||||
__float128 qd;
|
||||
#endif
|
||||
long double ld;
|
||||
double d;
|
||||
} v;
|
||||
int dtype = 0;
|
||||
mio_oow_t newcapa;
|
||||
mio_bch_t* bsp;
|
||||
|
||||
if (lm_flag & LF_J)
|
||||
{
|
||||
#if (MIO_SIZEOF___FLOAT128 > 0) && defined(HAVE_QUADMATH_SNPRINTF) && (MIO_SIZEOF_FLTMAX_T == MIO_SIZEOF___FLOAT128)
|
||||
v_qd = va_arg (ap, mio_fltmax_t);
|
||||
v.qd = va_arg(ap, mio_fltmax_t);
|
||||
dtype = LF_QD;
|
||||
#elif MIO_SIZEOF_FLTMAX_T == MIO_SIZEOF_DOUBLE
|
||||
v_d = va_arg(ap, mio_fltmax_t);
|
||||
v.d = va_arg(ap, mio_fltmax_t);
|
||||
#elif MIO_SIZEOF_FLTMAX_T == MIO_SIZEOF_LONG_DOUBLE
|
||||
v_ld = va_arg(ap, mio_fltmax_t);
|
||||
v.ld = va_arg(ap, mio_fltmax_t);
|
||||
dtype = LF_LD;
|
||||
#else
|
||||
#error Unsupported mio_flt_t
|
||||
@ -919,9 +941,9 @@ static int fmt_outv (mio_fmtout_t* fmtout, va_list ap)
|
||||
* so i prefer the format specifier with no modifier.
|
||||
*/
|
||||
#if MIO_SIZEOF_FLT_T == MIO_SIZEOF_DOUBLE
|
||||
v_d = va_arg(ap, mio_flt_t);
|
||||
v.d = va_arg(ap, mio_flt_t);
|
||||
#elif MIO_SIZEOF_FLT_T == MIO_SIZEOF_LONG_DOUBLE
|
||||
v_ld = va_arg(ap, mio_flt_t);
|
||||
v.ld = va_arg(ap, mio_flt_t);
|
||||
dtype = LF_LD;
|
||||
#else
|
||||
#error Unsupported mio_flt_t
|
||||
@ -929,13 +951,13 @@ static int fmt_outv (mio_fmtout_t* fmtout, va_list ap)
|
||||
}
|
||||
else if (lm_flag & (LF_LD | LF_L))
|
||||
{
|
||||
v_ld = va_arg (ap, long double);
|
||||
v.ld = va_arg(ap, long double);
|
||||
dtype = LF_LD;
|
||||
}
|
||||
#if (MIO_SIZEOF___FLOAT128 > 0) && defined(HAVE_QUADMATH_SNPRINTF)
|
||||
else if (lm_flag & (LF_QD | LF_Q))
|
||||
{
|
||||
v_qd = va_arg(ap, __float128);
|
||||
v.qd = va_arg(ap, __float128);
|
||||
dtype = LF_QD;
|
||||
}
|
||||
#endif
|
||||
@ -945,63 +967,63 @@ static int fmt_outv (mio_fmtout_t* fmtout, va_list ap)
|
||||
}
|
||||
else
|
||||
{
|
||||
v_d = va_arg (ap, double);
|
||||
v.d = va_arg(ap, double);
|
||||
}
|
||||
|
||||
fmtlen = fmt - percent;
|
||||
if (fmtlen > fltfmt->capa)
|
||||
fmtlen = fmtptr - percent;
|
||||
if (fmtlen > fb.fmt.capa)
|
||||
{
|
||||
if (fltfmt->ptr == fltfmt->buf)
|
||||
if (fb.fmt.ptr == fb.fmt.sbuf)
|
||||
{
|
||||
fltfmt->ptr = MIO_MMGR_ALLOC(MIO_MMGR_GETDFL(), MIO_SIZEOF(*fltfmt->ptr) * (fmtlen + 1));
|
||||
if (!fltfmt->ptr) goto oops;
|
||||
fb.fmt.ptr = (mio_bch_t*)MIO_MMGR_ALLOC(fmtout->mmgr, MIO_SIZEOF(*fb.fmt.ptr) * (fmtlen + 1));
|
||||
if (!fb.fmt.ptr) goto oops;
|
||||
}
|
||||
else
|
||||
{
|
||||
mio_bch_t* tmpptr;
|
||||
|
||||
tmpptr = MIO_MMGR_REALLOC(MIO_MMGR_GETDFL(), fltfmt->ptr, MIO_SIZEOF(*fltfmt->ptr) * (fmtlen + 1));
|
||||
tmpptr = (mio_bch_t*)MIO_MMGR_REALLOC(fmtout->mmgr, fb.fmt.ptr, MIO_SIZEOF(*fb.fmt.ptr) * (fmtlen + 1));
|
||||
if (!tmpptr) goto oops;
|
||||
fltfmt->ptr = tmpptr;
|
||||
fb.fmt.ptr = tmpptr;
|
||||
}
|
||||
|
||||
fltfmt->capa = fmtlen;
|
||||
fb.fmt.capa = fmtlen;
|
||||
}
|
||||
|
||||
/* compose back the format specifier */
|
||||
fmtlen = 0;
|
||||
fltfmt->ptr[fmtlen++] = '%';
|
||||
if (flagc & FLAGC_SPACE) fltfmt->ptr[fmtlen++] = ' ';
|
||||
if (flagc & FLAGC_SHARP) fltfmt->ptr[fmtlen++] = '#';
|
||||
if (flagc & FLAGC_SIGN) fltfmt->ptr[fmtlen++] = '+';
|
||||
if (flagc & FLAGC_LEFTADJ) fltfmt->ptr[fmtlen++] = '-';
|
||||
if (flagc & FLAGC_ZEROPAD) fltfmt->ptr[fmtlen++] = '0';
|
||||
fb.fmt.ptr[fmtlen++] = '%';
|
||||
if (flagc & FLAGC_SPACE) fb.fmt.ptr[fmtlen++] = ' ';
|
||||
if (flagc & FLAGC_SHARP) fb.fmt.ptr[fmtlen++] = '#';
|
||||
if (flagc & FLAGC_SIGN) fb.fmt.ptr[fmtlen++] = '+';
|
||||
if (flagc & FLAGC_LEFTADJ) fb.fmt.ptr[fmtlen++] = '-';
|
||||
if (flagc & FLAGC_ZEROPAD) fb.fmt.ptr[fmtlen++] = '0';
|
||||
|
||||
if (flagc & FLAGC_STAR1) fltfmt->ptr[fmtlen++] = '*';
|
||||
if (flagc & FLAGC_STAR1) fb.fmt.ptr[fmtlen++] = '*';
|
||||
else if (flagc & FLAGC_WIDTH)
|
||||
{
|
||||
fmtlen += mio_fmtuintmaxtombs (
|
||||
&fltfmt->ptr[fmtlen], fltfmt->capa - fmtlen,
|
||||
fmtlen += mio_fmt_uintmax_to_bcstr(
|
||||
&fb.fmt.ptr[fmtlen], fb.fmt.capa - fmtlen,
|
||||
width, 10, -1, '\0', MIO_NULL);
|
||||
}
|
||||
if (flagc & FLAGC_DOT) fltfmt->ptr[fmtlen++] = '.';
|
||||
if (flagc & FLAGC_STAR2) fltfmt->ptr[fmtlen++] = '*';
|
||||
if (flagc & FLAGC_DOT) fb.fmt.ptr[fmtlen++] = '.';
|
||||
if (flagc & FLAGC_STAR2) fb.fmt.ptr[fmtlen++] = '*';
|
||||
else if (flagc & FLAGC_PRECISION)
|
||||
{
|
||||
fmtlen += mio_fmtuintmaxtombs (
|
||||
&fltfmt->ptr[fmtlen], fltfmt->capa - fmtlen,
|
||||
fmtlen += mio_fmt_uintmax_to_bcstr(
|
||||
&fb.fmt.ptr[fmtlen], fb.fmt.capa - fmtlen,
|
||||
precision, 10, -1, '\0', MIO_NULL);
|
||||
}
|
||||
|
||||
if (dtype == LF_LD)
|
||||
fltfmt->ptr[fmtlen++] = 'L';
|
||||
fb.fmt.ptr[fmtlen++] = 'L';
|
||||
#if (MIO_SIZEOF___FLOAT128 > 0)
|
||||
else if (dtype == LF_QD)
|
||||
fltfmt->ptr[fmtlen++] = 'Q';
|
||||
fb.fmt.ptr[fmtlen++] = 'Q';
|
||||
#endif
|
||||
|
||||
fltfmt->ptr[fmtlen++] = ch;
|
||||
fltfmt->ptr[fmtlen] = '\0';
|
||||
fb.fmt.ptr[fmtlen++] = uch;
|
||||
fb.fmt.ptr[fmtlen] = '\0';
|
||||
|
||||
#if defined(HAVE_SNPRINTF)
|
||||
/* nothing special here */
|
||||
@ -1009,78 +1031,64 @@ static int fmt_outv (mio_fmtout_t* fmtout, va_list ap)
|
||||
/* best effort to avoid buffer overflow when no snprintf is available.
|
||||
* i really can't do much if it happens. */
|
||||
newcapa = precision + width + 32;
|
||||
if (fltout->capa < newcapa)
|
||||
if (fb.out.capa < newcapa)
|
||||
{
|
||||
MIO_ASSERT (mio, fltout->ptr == fltout->buf);
|
||||
|
||||
fltout->ptr = MIO_MMGR_ALLOC(MIO_MMGR_GETDFL(), MIO_SIZEOF(char_t) * (newcapa + 1));
|
||||
if (!fltout->ptr) goto oops;
|
||||
fltout->capa = newcapa;
|
||||
/*MIO_ASSERT (mio, fb.out.ptr == fb.out.sbuf);*/
|
||||
fb.out.ptr = MIO_MMGR_ALLOC(fmtout->mmgr, MIO_SIZEOF(mio_bch_t) * (newcapa + 1));
|
||||
if (!fb.out.ptr) goto oops;
|
||||
fb.out.capa = newcapa;
|
||||
}
|
||||
#endif
|
||||
|
||||
while (1)
|
||||
{
|
||||
|
||||
if (dtype == LF_LD)
|
||||
{
|
||||
#if defined(HAVE_SNPRINTF)
|
||||
q = snprintf ((mio_bch_t*)fltout->ptr, fltout->capa + 1, fltfmt->ptr, v_ld);
|
||||
q = snprintf((mio_bch_t*)fb.out.ptr, fb.out.capa + 1, fb.fmt.ptr, v.ld);
|
||||
#else
|
||||
q = sprintf ((mio_bch_t*)fltout->ptr, fltfmt->ptr, v_ld);
|
||||
q = sprintf((mio_bch_t*)fb.out.ptr, fb.fmt.ptr, v.ld);
|
||||
#endif
|
||||
}
|
||||
#if (MIO_SIZEOF___FLOAT128 > 0) && defined(HAVE_QUADMATH_SNPRINTF)
|
||||
else if (dtype == LF_QD)
|
||||
{
|
||||
q = quadmath_snprintf((mio_bch_t*)fltout->ptr, fltout->capa + 1, fltfmt->ptr, v_qd);
|
||||
q = quadmath_snprintf((mio_bch_t*)fb.out.ptr, fb.out.capa + 1, fb.fmt.ptr, v.qd);
|
||||
}
|
||||
#endif
|
||||
else
|
||||
{
|
||||
#if defined(HAVE_SNPRINTF)
|
||||
q = snprintf ((mio_bch_t*)fltout->ptr, fltout->capa + 1, fltfmt->ptr, v_d);
|
||||
q = snprintf((mio_bch_t*)fb.out.ptr, fb.out.capa + 1, fb.fmt.ptr, v.d);
|
||||
#else
|
||||
q = sprintf ((mio_bch_t*)fltout->ptr, fltfmt->ptr, v_d);
|
||||
q = sprintf((mio_bch_t*)fb.out.ptr, fb.fmt.ptr, v.d);
|
||||
#endif
|
||||
}
|
||||
if (q <= -1) goto oops;
|
||||
if (q <= fltout->capa) break;
|
||||
if (q <= fb.out.capa) break;
|
||||
|
||||
newcapa = fltout->capa * 2;
|
||||
newcapa = fb.out.capa * 2;
|
||||
if (newcapa < q) newcapa = q;
|
||||
|
||||
if (fltout->ptr == fltout->sbuf)
|
||||
if (fb.out.ptr == fb.out.sbuf)
|
||||
{
|
||||
fltout->ptr = MIO_MMGR_ALLOC(MIO_MMGR_GETDFL(), MIO_SIZEOF(char_t) * (newcapa + 1));
|
||||
if (!fltout->ptr) goto oops;
|
||||
fb.out.ptr = (mio_bch_t*)MIO_MMGR_ALLOC(fmtout->mmgr, MIO_SIZEOF(mio_bch_t) * (newcapa + 1));
|
||||
if (!fb.out.ptr) goto oops;
|
||||
}
|
||||
else
|
||||
{
|
||||
char_t* tmpptr;
|
||||
|
||||
tmpptr = MIO_MMGR_REALLOC(MIO_MMGR_GETDFL(), fltout->ptr, MIO_SIZEOF(char_t) * (newcapa + 1));
|
||||
mio_bch_t* tmpptr;
|
||||
tmpptr = (mio_bch_t*)MIO_MMGR_REALLOC(fmtout->mmgr, fb.out.ptr, MIO_SIZEOF(mio_bch_t) * (newcapa + 1));
|
||||
if (!tmpptr) goto oops;
|
||||
fltout->ptr = tmpptr;
|
||||
fb.out.ptr = tmpptr;
|
||||
}
|
||||
fltout->capa = newcapa;
|
||||
fb.out.capa = newcapa;
|
||||
}
|
||||
|
||||
if (MIO_SIZEOF(char_t) != MIO_SIZEOF(mio_bch_t))
|
||||
{
|
||||
fltout->ptr[q] = '\0';
|
||||
while (q > 0)
|
||||
{
|
||||
q--;
|
||||
fltout->ptr[q] = ((mio_bch_t*)fltout->ptr)[q];
|
||||
}
|
||||
}
|
||||
|
||||
sp = fltout->ptr;
|
||||
flagc &= ~FLAGC_DOT;
|
||||
width = 0;
|
||||
precision = 0;
|
||||
goto print_lowercase_s;
|
||||
bsp = fb.out.ptr;
|
||||
n = 0; while (bsp[n] != '\0') n++;
|
||||
PUT_BCS (fmtout, bsp, n);
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -1092,7 +1100,7 @@ static int fmt_outv (mio_fmtout_t* fmtout, va_list ap)
|
||||
(MIO_SIZEOF_UINTMAX_T > MIO_SIZEOF_OOW_T) && \
|
||||
(MIO_SIZEOF_UINTMAX_T != MIO_SIZEOF_LONG_LONG) && \
|
||||
(MIO_SIZEOF_UINTMAX_T != MIO_SIZEOF_LONG)
|
||||
/* Binaries by some GCC compilers crashed when getting mio_uintmax_t with va_arg.
|
||||
/* GCC-compiled binaries crashed when getting mio_uintmax_t with va_arg.
|
||||
* This is just a work-around for it */
|
||||
int i;
|
||||
for (i = 0, num = 0; i < MIO_SIZEOF(mio_uintmax_t) / MIO_SIZEOF(mio_oow_t); i++)
|
||||
@ -1109,10 +1117,8 @@ static int fmt_outv (mio_fmtout_t* fmtout, va_list ap)
|
||||
num = va_arg(ap, mio_uintmax_t);
|
||||
#endif
|
||||
}
|
||||
#if 0
|
||||
else if (lm_flag & LF_T)
|
||||
num = va_arg(ap, mio_ptrdiff_t);
|
||||
#endif
|
||||
num = va_arg(ap, mio_intptr_t/*mio_ptrdiff_t*/);
|
||||
else if (lm_flag & LF_Z)
|
||||
num = va_arg(ap, mio_oow_t);
|
||||
#if (MIO_SIZEOF_LONG_LONG > 0)
|
||||
@ -1154,10 +1160,8 @@ static int fmt_outv (mio_fmtout_t* fmtout, va_list ap)
|
||||
#endif
|
||||
}
|
||||
|
||||
#if 0
|
||||
else if (lm_flag & LF_T)
|
||||
num = va_arg(ap, mio_ptrdiff_t);
|
||||
#endif
|
||||
num = va_arg(ap, mio_intptr_t/*mio_ptrdiff_t*/);
|
||||
else if (lm_flag & LF_Z)
|
||||
num = va_arg(ap, mio_ooi_t);
|
||||
#if (MIO_SIZEOF_LONG_LONG > 0)
|
||||
@ -1236,7 +1240,6 @@ static int fmt_outv (mio_fmtout_t* fmtout, va_list ap)
|
||||
PUT_OOCH (fmtout, padc, width);
|
||||
}
|
||||
|
||||
|
||||
while (*nbufp) PUT_OOCH (fmtout, *nbufp--, 1); /* output actual digits */
|
||||
|
||||
if ((flagc & FLAGC_LEFTADJ) && width > 0 && (width -= tmp) > 0)
|
||||
@ -1279,9 +1282,17 @@ static int fmt_outv (mio_fmtout_t* fmtout, va_list ap)
|
||||
}
|
||||
|
||||
done:
|
||||
#if defined(MIO_ENABLE_FLTFMT)
|
||||
if (fb.fmt.ptr != fb.fmt.sbuf) MIO_MMGR_FREE (fmtout->mmgr, fb.fmt.ptr);
|
||||
if (fb.out.ptr != fb.out.sbuf) MIO_MMGR_FREE (fmtout->mmgr, fb.out.ptr);
|
||||
#endif
|
||||
return 0;
|
||||
|
||||
oops:
|
||||
#if defined(MIO_ENABLE_FLTFMT)
|
||||
if (fb.fmt.ptr != fb.fmt.sbuf) MIO_MMGR_FREE (fmtout->mmgr, fb.fmt.ptr);
|
||||
if (fb.out.ptr != fb.out.sbuf) MIO_MMGR_FREE (fmtout->mmgr, fb.out.ptr);
|
||||
#endif
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -1538,6 +1549,7 @@ mio_ooi_t mio_logbfmtv (mio_t* mio, mio_bitmask_t mask, const mio_bch_t* fmt, va
|
||||
fo.fmt_str = fmt;
|
||||
fo.ctx = mio;
|
||||
fo.mask = mask;
|
||||
fo.mmgr = mio_getmmgr(mio);
|
||||
fo.putbchars = log_bcs;
|
||||
fo.putuchars = log_ucs;
|
||||
|
||||
@ -1591,6 +1603,7 @@ mio_ooi_t mio_logufmtv (mio_t* mio, mio_bitmask_t mask, const mio_uch_t* fmt, va
|
||||
fo.fmt_str = fmt;
|
||||
fo.ctx = mio;
|
||||
fo.mask = mask;
|
||||
fo.mmgr = mio_getmmgr(mio);
|
||||
fo.putbchars = log_bcs;
|
||||
fo.putuchars = log_ucs;
|
||||
|
||||
@ -1601,6 +1614,7 @@ mio_ooi_t mio_logufmtv (mio_t* mio, mio_bitmask_t mask, const mio_uch_t* fmt, va
|
||||
prim_write_log (mio, mio->log.last_mask, mio->log.ptr, mio->log.len);
|
||||
mio->log.len = 0;
|
||||
}
|
||||
|
||||
return (x <= -1)? -1: fo.count;
|
||||
}
|
||||
|
||||
|
@ -6,51 +6,15 @@
|
||||
/* Define to 1 if you have the `accept4' function. */
|
||||
#undef HAVE_ACCEPT4
|
||||
|
||||
/* Define to 1 if you have the `acos' function. */
|
||||
#undef HAVE_ACOS
|
||||
|
||||
/* Define to 1 if you have the `acosf' function. */
|
||||
#undef HAVE_ACOSF
|
||||
|
||||
/* Define to 1 if you have the `acosl' function. */
|
||||
#undef HAVE_ACOSL
|
||||
|
||||
/* Define to 1 if you have the `acosq' function. */
|
||||
#undef HAVE_ACOSQ
|
||||
|
||||
/* Define to 1 if you have the `asin' function. */
|
||||
#undef HAVE_ASIN
|
||||
|
||||
/* Define to 1 if you have the `asinf' function. */
|
||||
#undef HAVE_ASINF
|
||||
|
||||
/* Define to 1 if you have the `asinl' function. */
|
||||
#undef HAVE_ASINL
|
||||
|
||||
/* Define to 1 if you have the `asinq' function. */
|
||||
#undef HAVE_ASINQ
|
||||
|
||||
/* Define to 1 if you have the `atan' function. */
|
||||
#undef HAVE_ATAN
|
||||
|
||||
/* Define to 1 if you have the `atan2' function. */
|
||||
#undef HAVE_ATAN2
|
||||
|
||||
/* Define to 1 if you have the `atan2f' function. */
|
||||
#undef HAVE_ATAN2F
|
||||
|
||||
/* Define to 1 if you have the `atan2l' function. */
|
||||
#undef HAVE_ATAN2L
|
||||
|
||||
/* Define to 1 if you have the `atan2q' function. */
|
||||
#undef HAVE_ATAN2Q
|
||||
|
||||
/* Define to 1 if you have the `atanf' function. */
|
||||
#undef HAVE_ATANF
|
||||
|
||||
/* Define to 1 if you have the `atanl' function. */
|
||||
#undef HAVE_ATANL
|
||||
|
||||
/* Define to 1 if you have the `atanq' function. */
|
||||
#undef HAVE_ATANQ
|
||||
|
||||
@ -60,15 +24,6 @@
|
||||
/* Define to 1 if you have the `backtrace_symbols' function. */
|
||||
#undef HAVE_BACKTRACE_SYMBOLS
|
||||
|
||||
/* Define to 1 if you have the `ceil' function. */
|
||||
#undef HAVE_CEIL
|
||||
|
||||
/* Define to 1 if you have the `ceilf' function. */
|
||||
#undef HAVE_CEILF
|
||||
|
||||
/* Define to 1 if you have the `ceill' function. */
|
||||
#undef HAVE_CEILL
|
||||
|
||||
/* Define to 1 if you have the `ceilq' function. */
|
||||
#undef HAVE_CEILQ
|
||||
|
||||
@ -84,27 +39,9 @@
|
||||
/* Define to 1 if you have the `connect' function. */
|
||||
#undef HAVE_CONNECT
|
||||
|
||||
/* Define to 1 if you have the `cos' function. */
|
||||
#undef HAVE_COS
|
||||
|
||||
/* Define to 1 if you have the `cosf' function. */
|
||||
#undef HAVE_COSF
|
||||
|
||||
/* Define to 1 if you have the `cosh' function. */
|
||||
#undef HAVE_COSH
|
||||
|
||||
/* Define to 1 if you have the `coshf' function. */
|
||||
#undef HAVE_COSHF
|
||||
|
||||
/* Define to 1 if you have the `coshl' function. */
|
||||
#undef HAVE_COSHL
|
||||
|
||||
/* Define to 1 if you have the `coshq' function. */
|
||||
#undef HAVE_COSHQ
|
||||
|
||||
/* Define to 1 if you have the `cosl' function. */
|
||||
#undef HAVE_COSL
|
||||
|
||||
/* Define to 1 if you have the `cosq' function. */
|
||||
#undef HAVE_COSQ
|
||||
|
||||
@ -148,15 +85,6 @@
|
||||
/* Define to 1 if you have the <execinfo.h> header file. */
|
||||
#undef HAVE_EXECINFO_H
|
||||
|
||||
/* Define to 1 if you have the `exp' function. */
|
||||
#undef HAVE_EXP
|
||||
|
||||
/* Define to 1 if you have the `expf' function. */
|
||||
#undef HAVE_EXPF
|
||||
|
||||
/* Define to 1 if you have the `expl' function. */
|
||||
#undef HAVE_EXPL
|
||||
|
||||
/* Define to 1 if you have the `expq' function. */
|
||||
#undef HAVE_EXPQ
|
||||
|
||||
@ -169,27 +97,9 @@
|
||||
/* Define to 1 if you have the `fdopendir' function. */
|
||||
#undef HAVE_FDOPENDIR
|
||||
|
||||
/* Define to 1 if you have the `floor' function. */
|
||||
#undef HAVE_FLOOR
|
||||
|
||||
/* Define to 1 if you have the `floorf' function. */
|
||||
#undef HAVE_FLOORF
|
||||
|
||||
/* Define to 1 if you have the `floorl' function. */
|
||||
#undef HAVE_FLOORL
|
||||
|
||||
/* Define to 1 if you have the `floorq' function. */
|
||||
#undef HAVE_FLOORQ
|
||||
|
||||
/* Define to 1 if you have the `fmod' function. */
|
||||
#undef HAVE_FMOD
|
||||
|
||||
/* Define to 1 if you have the `fmodf' function. */
|
||||
#undef HAVE_FMODF
|
||||
|
||||
/* Define to 1 if you have the `fmodl' function. */
|
||||
#undef HAVE_FMODL
|
||||
|
||||
/* Define to 1 if you have the `fmodq' function. */
|
||||
#undef HAVE_FMODQ
|
||||
|
||||
@ -283,27 +193,9 @@
|
||||
/* Define to 1 if you have the `localtime_r' function. */
|
||||
#undef HAVE_LOCALTIME_R
|
||||
|
||||
/* Define to 1 if you have the `log' function. */
|
||||
#undef HAVE_LOG
|
||||
|
||||
/* Define to 1 if you have the `log10' function. */
|
||||
#undef HAVE_LOG10
|
||||
|
||||
/* Define to 1 if you have the `log10f' function. */
|
||||
#undef HAVE_LOG10F
|
||||
|
||||
/* Define to 1 if you have the `log10l' function. */
|
||||
#undef HAVE_LOG10L
|
||||
|
||||
/* Define to 1 if you have the `log10q' function. */
|
||||
#undef HAVE_LOG10Q
|
||||
|
||||
/* Define to 1 if you have the `logf' function. */
|
||||
#undef HAVE_LOGF
|
||||
|
||||
/* Define to 1 if you have the `logl' function. */
|
||||
#undef HAVE_LOGL
|
||||
|
||||
/* Define to 1 if you have the `logq' function. */
|
||||
#undef HAVE_LOGQ
|
||||
|
||||
@ -385,15 +277,6 @@
|
||||
/* Define to 1 if you have the `posix_spawn' function. */
|
||||
#undef HAVE_POSIX_SPAWN
|
||||
|
||||
/* Define to 1 if you have the `pow' function. */
|
||||
#undef HAVE_POW
|
||||
|
||||
/* Define to 1 if you have the `powf' function. */
|
||||
#undef HAVE_POWF
|
||||
|
||||
/* Define to 1 if you have the `powl' function. */
|
||||
#undef HAVE_POWL
|
||||
|
||||
/* Define to 1 if you have the `powq' function. */
|
||||
#undef HAVE_POWQ
|
||||
|
||||
@ -427,15 +310,6 @@
|
||||
/* Define to 1 if you have the `recvmsg' function. */
|
||||
#undef HAVE_RECVMSG
|
||||
|
||||
/* Define to 1 if you have the `round' function. */
|
||||
#undef HAVE_ROUND
|
||||
|
||||
/* Define to 1 if you have the `roundf' function. */
|
||||
#undef HAVE_ROUNDF
|
||||
|
||||
/* Define to 1 if you have the `roundl' function. */
|
||||
#undef HAVE_ROUNDL
|
||||
|
||||
/* Define to 1 if you have the `roundq' function. */
|
||||
#undef HAVE_ROUNDQ
|
||||
|
||||
@ -469,27 +343,9 @@
|
||||
/* Define to 1 if you have the <signal.h> header file. */
|
||||
#undef HAVE_SIGNAL_H
|
||||
|
||||
/* Define to 1 if you have the `sin' function. */
|
||||
#undef HAVE_SIN
|
||||
|
||||
/* Define to 1 if you have the `sinf' function. */
|
||||
#undef HAVE_SINF
|
||||
|
||||
/* Define to 1 if you have the `sinh' function. */
|
||||
#undef HAVE_SINH
|
||||
|
||||
/* Define to 1 if you have the `sinhf' function. */
|
||||
#undef HAVE_SINHF
|
||||
|
||||
/* Define to 1 if you have the `sinhl' function. */
|
||||
#undef HAVE_SINHL
|
||||
|
||||
/* Define to 1 if you have the `sinhq' function. */
|
||||
#undef HAVE_SINHQ
|
||||
|
||||
/* Define to 1 if you have the `sinl' function. */
|
||||
#undef HAVE_SINL
|
||||
|
||||
/* Define to 1 if you have the `sinq' function. */
|
||||
#undef HAVE_SINQ
|
||||
|
||||
@ -499,15 +355,6 @@
|
||||
/* Define to 1 if you have the <spawn.h> header file. */
|
||||
#undef HAVE_SPAWN_H
|
||||
|
||||
/* Define to 1 if you have the `sqrt' function. */
|
||||
#undef HAVE_SQRT
|
||||
|
||||
/* Define to 1 if you have the `sqrtf' function. */
|
||||
#undef HAVE_SQRTF
|
||||
|
||||
/* Define to 1 if you have the `sqrtl' function. */
|
||||
#undef HAVE_SQRTL
|
||||
|
||||
/* Define to 1 if you have the `sqrtq' function. */
|
||||
#undef HAVE_SQRTQ
|
||||
|
||||
@ -648,27 +495,9 @@
|
||||
/* Define to 1 if you have the <sys/wait.h> header file. */
|
||||
#undef HAVE_SYS_WAIT_H
|
||||
|
||||
/* Define to 1 if you have the `tan' function. */
|
||||
#undef HAVE_TAN
|
||||
|
||||
/* Define to 1 if you have the `tanf' function. */
|
||||
#undef HAVE_TANF
|
||||
|
||||
/* Define to 1 if you have the `tanh' function. */
|
||||
#undef HAVE_TANH
|
||||
|
||||
/* Define to 1 if you have the `tanhf' function. */
|
||||
#undef HAVE_TANHF
|
||||
|
||||
/* Define to 1 if you have the `tanhl' function. */
|
||||
#undef HAVE_TANHL
|
||||
|
||||
/* Define to 1 if you have the `tanhq' function. */
|
||||
#undef HAVE_TANHQ
|
||||
|
||||
/* Define to 1 if you have the `tanl' function. */
|
||||
#undef HAVE_TANL
|
||||
|
||||
/* Define to 1 if you have the `tanq' function. */
|
||||
#undef HAVE_TANQ
|
||||
|
||||
|
@ -336,6 +336,50 @@
|
||||
# error UNKNOWN INTMAX SIZE
|
||||
#endif
|
||||
|
||||
/* =========================================================================
|
||||
* FLOATING-POINT TYPE
|
||||
* ========================================================================= */
|
||||
/** \typedef mio_fltbas_t
|
||||
* The mio_fltbas_t type defines the largest floating-pointer number type
|
||||
* naturally supported.
|
||||
*/
|
||||
#if defined(__FreeBSD__) || defined(__MINGW32__)
|
||||
/* TODO: check if the support for long double is complete.
|
||||
* if so, use long double for mio_flt_t */
|
||||
typedef double mio_fltbas_t;
|
||||
# define MIO_SIZEOF_FLTBAS_T MIO_SIZEOF_DOUBLE
|
||||
#elif MIO_SIZEOF_LONG_DOUBLE > MIO_SIZEOF_DOUBLE
|
||||
typedef long double mio_fltbas_t;
|
||||
# define MIO_SIZEOF_FLTBAS_T MIO_SIZEOF_LONG_DOUBLE
|
||||
#else
|
||||
typedef double mio_fltbas_t;
|
||||
# define MIO_SIZEOF_FLTBAS_T MIO_SIZEOF_DOUBLE
|
||||
#endif
|
||||
|
||||
/** \typedef mio_fltmax_t
|
||||
* The mio_fltmax_t type defines the largest floating-pointer number type
|
||||
* ever supported.
|
||||
*/
|
||||
#if MIO_SIZEOF___FLOAT128 >= MIO_SIZEOF_FLTBAS_T
|
||||
/* the size of long double may be equal to the size of __float128
|
||||
* for alignment on some platforms */
|
||||
typedef __float128 mio_fltmax_t;
|
||||
# define MIO_SIZEOF_FLTMAX_T MIO_SIZEOF___FLOAT128
|
||||
# define MIO_FLTMAX_REQUIRE_QUADMATH 1
|
||||
#else
|
||||
typedef mio_fltbas_t mio_fltmax_t;
|
||||
# define MIO_SIZEOF_FLTMAX_T MIO_SIZEOF_FLTBAS_T
|
||||
# undef MIO_FLTMAX_REQUIRE_QUADMATH
|
||||
#endif
|
||||
|
||||
#if defined(MIO_USE_FLTMAX)
|
||||
typedef mio_fltmax_t mio_flt_t;
|
||||
#define MIO_SIZEOF_FLT_T MIO_SIZEOF_FLTMAX_T
|
||||
#else
|
||||
typedef mio_fltbas_t mio_flt_t;
|
||||
#define MIO_SIZEOF_FLT_T MIO_SIZEOF_FLTBAS_T
|
||||
#endif
|
||||
|
||||
/* =========================================================================
|
||||
* BASIC HARD-CODED DEFINES
|
||||
* ========================================================================= */
|
||||
|
@ -63,6 +63,7 @@ struct mio_fmtout_t
|
||||
{
|
||||
mio_oow_t count; /* out */
|
||||
|
||||
mio_mmgr_t* mmgr; /* in */
|
||||
mio_fmtout_putbchars_t putbchars; /* in */
|
||||
mio_fmtout_putuchars_t putuchars; /* in */
|
||||
mio_bitmask_t mask; /* in */
|
||||
|
@ -30,6 +30,9 @@
|
||||
#include <mio.h>
|
||||
#include <mio-utl.h>
|
||||
|
||||
/* enable floating-point support in basic formatting functions */
|
||||
#define MIO_ENABLE_FLTFMT
|
||||
|
||||
#if defined(__has_builtin)
|
||||
|
||||
# if (!__has_builtin(__builtin_memset) || !__has_builtin(__builtin_memcpy) || !__has_builtin(__builtin_memmove) || !__has_builtin(__builtin_memcmp))
|
||||
|
@ -42,8 +42,8 @@ int mio_sys_initmux (mio_t* mio)
|
||||
|
||||
#if defined(USE_EPOLL)
|
||||
|
||||
#if defined(HAVE_EPOLL_CREATE1)
|
||||
mux->hnd = epoll_create1(O_CLOEXEC);
|
||||
#if defined(HAVE_EPOLL_CREATE1) && defined(EPOLL_CLOEXEC)
|
||||
mux->hnd = epoll_create1(EPOLL_CLOEXEC);
|
||||
if (mux->hnd == -1)
|
||||
{
|
||||
if (errno == ENOSYS) goto normal_epoll_create; /* kernel doesn't support it */
|
||||
@ -61,11 +61,11 @@ normal_epoll_create:
|
||||
mio_seterrwithsyserr (mio, 0, errno);
|
||||
return -1;
|
||||
}
|
||||
|
||||
#if defined(FD_CLOEXEC)
|
||||
else
|
||||
{
|
||||
int flags = fcntl(mux->hnd, F_GETFD, 0);
|
||||
if (flags >= 0) fcntl(mux->hnd, F_SETFD, flags | FD_CLOEXEC);
|
||||
if (flags >= 0 && !(flags & FD_CLOEXEC)) fcntl(mux->hnd, F_SETFD, flags | FD_CLOEXEC);
|
||||
}
|
||||
#endif /* FD_CLOEXEC */
|
||||
|
||||
|
Reference in New Issue
Block a user