Commit a4e1e5e8 a4e1e5e8481565d97804c083752ee3eea0ebf87e by Sergey Poznyakoff

Remove leftover dependencies of libmailutils from gnulib

* bootstrap.conf (gnulib_extra_files): Remove.
* gnulib.modules (inttostr): Add module.
* include/mailutils/io.h: New file.
* include/mailutils/Makefile.am: Add io.h

* mailbox/inttostr.c, mailbox/inttostr.h: Remove
* mailbox/imaxtostr.c, mailbox/offtostr.c, mailbox/umaxtostr.c: Remove
* mailbox/intprops.h: Remove
* mailbox/asnprintf.c, mailbox/asprintf.c, mailbox/vasnprintf.c: New files.
* mailbox/Makefile.am: Update.

* mailbox/mu_umaxtostr.c: rename to lib/mu_umaxtostr.c
* mailbox/mu_umaxtostr.h: rename to lib/mu_umaxtostr.h
* lib/Makefile.am (libmuaux_la_SOURCES): Add mu_umaxtostr.[ch]

* libmu_auth/radius.c, libmu_cfg/common.c, libmu_scm/mu_port.c,
libproto/imap/folder.c, libproto/imap/mbox.c,
libproto/mbox/mbox.c, libproto/mh/mbox.c, libproto/pop/mbox.c,
mailbox/acl.c, mailbox/daemon.c, mailbox/mailer.c,
mailbox/message.c, mailbox/mutil.c, mailbox/stream.c: Use mu_strerror.
Avoid using mu_umaxtostr.
1 parent 02ce501a
# Bootstrap configuration.
# Copyright (C) 2006, 2007, 2008 Free Software Foundation, Inc.
# Copyright (C) 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
......@@ -77,10 +77,6 @@ excluded_files='
m4/visibility.m4
'
gnulib_extra_files="$gnulib_extra_files
m4/inttostr.m4
"
# Read local configuration file
if [ -r .bootstrap ]; then
echo "$0: Reading configuration file .bootstrap"
......
......@@ -2,9 +2,6 @@
# A module name per line. Empty lines and comments are ignored.
# FIXME: regex and glob are used by libmailutils...
# FIXME: intprops and stdint are not used directly, they are needed for
# inttostr, which is included in mailbox. Another inttostr dependency,
# m4/inttostr.m4, is set in bootstrap.conf.
alloca
autobuild
......@@ -16,6 +13,7 @@ getpass-gnu
gettext
gitlog-to-changelog
intprops
inttostr
malloc
mbswidth
obstack
......
## Process this file with GNU Automake to create Makefile.in
## Copyright (C) 2000, 2001, 2002, 2003,
## 2004, 2005, 2007, 2008 Free Software Foundation, Inc.
## 2004, 2005, 2007, 2008, 2009 Free Software Foundation, Inc.
##
## GNU Mailutils is free software; you can redistribute it and/or
## modify it under the terms of the GNU General Public License as
......@@ -53,6 +53,7 @@ pkginclude_HEADERS = \
gsasl.h\
guile.h\
header.h\
io.h\
iterator.h\
kwd.h\
ldap.h\
......
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2009 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General
Public License along with this library; if not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301 USA */
#ifndef _MAILUTILS_IO_H
#define _MAILUTILS_IO_H
#ifdef __cplusplus
extern "C" {
#endif
int mu_asprintf (char **pbuf, const char *fmt, ...);
int mu_asnprintf (char **pbuf, size_t *psize, const char *fmt, ...);
int mu_vasnprintf (char **pbuf, size_t *psize, const char *fmt, va_list ap);
#ifdef __cplusplus
}
#endif
#endif
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 1999, 2000, 2001, 2002, 2003,
2004, 2007, 2008 Free Software Foundation, Inc.
2004, 2007, 2008, 2009 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
......@@ -61,6 +61,7 @@
#include <mailutils/gocs.h>
#include <mailutils/version.h>
#include <mailutils/vartab.h>
#include <mailutils/io.h>
#ifdef MU_COMPAT
# error "Version 0.6 is no longer supported. Please, update your program."
......
## Process this file with GNU Automake to create Makefile.in
## Copyright (C) 1999, 2000, 2001, 2002, 2005,
## 2007, 2008 Free Software Foundation, Inc.
## 2007, 2008, 2009 Free Software Foundation, Inc.
##
## GNU Mailutils is free software; you can redistribute it and/or
## modify it under the terms of the GNU General Public License as
......@@ -29,7 +29,9 @@ libmuaux_la_SOURCES += \
signal.c\
strexit.c\
tcpwrap.c\
userprivs.c
userprivs.c\
mu_umaxtostr.c\
mu_umaxtostr.h
noinst_HEADERS +=\
mailcap.h\
......
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2005, 2007, 2008 Free Software Foundation, Inc.
Copyright (C) 2005, 2007, 2008, 2009 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
......@@ -183,26 +183,12 @@ mu_grad_logger(int level,
char *pfx = NULL;
if (loc)
{
char buf[INT_STRLEN_BOUND(uintmax_t)];
char *p = umaxtostr (loc->line, buf);
size_t size = strlen (loc->file) + 1 + strlen (p) + 2 + strlen (fmt) + 1;
if (func_name)
size += strlen (func_name) + 1;
pfx = malloc (size);
if (pfx)
{
strcpy (pfx, loc->file);
strcat (pfx, ":");
strcat (pfx, p);
strcat (pfx, ":");
if (func_name)
{
strcat (pfx, func_name);
strcat (pfx, ":");
}
strcat (pfx, " ");
strcat (pfx, fmt);
}
mu_asprintf (&pfx, "%s:%lu:%s: %s",
loc->file, (unsigned long) loc->line, func_name, fmt);
else
mu_asprintf (&pfx, "%s:%lu: %s",
loc->file, (unsigned long) loc->line, fmt);
}
mu_diag_voutput (mlevel[level & GRAD_LOG_PRIMASK], pfx ? pfx : fmt, ap);
if (pfx)
......
/* This file is part of GNU Mailutils
Copyright (C) 2007, 2008 Free Software Foundation, Inc.
Copyright (C) 2007, 2008, 2009 Free Software Foundation, Inc.
GNU Mailutils is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
......@@ -24,7 +24,7 @@
#include <mailutils/debug.h>
#include <mailutils/syslog.h>
#include <mailutils/mailbox.h>
#include <mu_umaxtostr.h>
#include <mailutils/io.h>
static struct mu_gocs_locking locking_settings;
static struct mu_gocs_logging logging_settings;
......@@ -164,9 +164,6 @@ DCL_CFG_CAPA (logging);
static int
_cb2_debug_level (mu_debug_t debug, const char *arg, void *data MU_ARG_UNUSED)
{
char buf[UINTMAX_STRSIZE_BOUND];
char *p;
size_t size;
char *pfx;
struct mu_debug_locus locus;
......@@ -175,24 +172,21 @@ _cb2_debug_level (mu_debug_t debug, const char *arg, void *data MU_ARG_UNUSED)
debug_settings.string = strdup (arg);
if (mu_debug_get_locus (debug, &locus) == 0)
{
p = umaxtostr (locus.line, buf);
size = strlen (locus.file) + 1 + strlen (p) + 1;
pfx = malloc (size);
if (!pfx)
int status = mu_asprintf (&pfx, "%s:%lu",
locus.file, (unsigned long) locus.line);
if (status)
{
mu_cfg_format_error (debug, MU_DEBUG_ERROR,
"%s", mu_strerror (errno));
"%s", mu_strerror (status));
return 1;
}
strcpy (pfx, locus.file);
strcat (pfx, ":");
strcat (pfx, p);
}
else
pfx = strdup ("command line");/*FIXME*/
/*FIXME: this is suboptimal, there's no use parsing 1st arg in
mu_global_debug_from_string */
mu_global_debug_from_string (debug_settings.string, pfx);
free (pfx);
free (debug_settings.string);
free (debug_settings.errpfx);
memset (&debug_settings, 0, sizeof debug_settings);
......
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 1999, 2000, 2001, 2006, 2007 Free Software Foundation, Inc.
Copyright (C) 1999, 2000, 2001, 2006, 2007,
2009 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
......@@ -17,7 +18,7 @@
Boston, MA 02110-1301 USA */
#include "mu_scm.h"
#include <mu_umaxtostr.h>
#include <mailutils/io.h>
struct mu_port
{
......@@ -276,10 +277,13 @@ mu_port_print (SCM exp, SCM port, scm_print_state *pstate)
scm_puts ("mu-port", port);
if (mu_stream_size (mp->stream, &size) == 0)
{
char buffer[64];
snprintf (buffer, sizeof (buffer), " %-5s", mu_umaxtostr (0, size));
scm_puts (buffer, port);
char *buf;
if (mu_asprintf (&buf, " %5lu", (unsigned long) size) == 0)
{
scm_puts (buf, port);
scm_puts (" chars", port);
free (buf);
}
}
scm_putc ('>', port);
return 1;
......
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 1999, 2000, 2001, 2003, 2004,
2005, 2006, 2007 Free Software Foundation, Inc.
2005, 2006, 2007, 2009 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
......@@ -50,7 +50,6 @@
#include <mailutils/argcv.h>
#include <mailutils/tls.h>
#include <mailutils/nls.h>
#include <mu_umaxtostr.h>
/* For dbg purposes set to one to see different level of traffic. */
/* Print to stderr the command sent to the IMAP server. */
......@@ -570,10 +569,10 @@ static int
imap_writer (void *iodata, char *buf)
{
f_imap_t iop = iodata;
MU_DEBUG2 (iop->folder->debug, MU_DEBUG_PROT, "g%s %s\n",
mu_umaxtostr (0, iop->seq), buf);
int status = imap_writeline (iop, "g%s %s\r\n",
mu_umaxtostr (0, iop->seq++), buf);
MU_DEBUG2 (iop->folder->debug, MU_DEBUG_PROT, "g%lu %s\n",
(unsigned long)iop->seq, buf);
int status = imap_writeline (iop, "g%lu %s\r\n",
(unsigned long)iop->seq++, buf);
CHECK_ERROR (iop, status);
status = imap_send (iop);
CHECK_ERROR (iop, status);
......
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 1999, 2000, 2001, 2003,
2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
......@@ -24,7 +24,7 @@
#endif
#include <mbox0.h>
#include <mu_umaxtostr.h>
#include <mailutils/io.h>
#define ATTRIBUTE_IS_DELETED(flag) (flag & MU_ATTRIBUTE_DELETED)
#define ATTRIBUTE_IS_EQUAL(flag1, flag2) (flag1 == flag2)
......@@ -805,12 +805,7 @@ static int
mbox_message_qid (mu_message_t msg, mu_message_qid_t *pqid)
{
mbox_message_t mum = mu_message_get_owner (msg);
char buf[UINTMAX_STRSIZE_BOUND];
const char *p = umaxtostr (mum->header_from, buf);
*pqid = strdup (p);
if (*pqid == NULL)
return ENOMEM;
return 0;
return mu_asprintf (pqid, "%lu", (unsigned long) mum->header_from);
}
static int
......@@ -1303,9 +1298,10 @@ mbox_append_message (mu_mailbox_t mailbox, mu_message_t msg)
if (mailbox->observable)
{
char buf[UINTMAX_STRSIZE_BOUND];
mu_observable_notify (mailbox->observable, MU_EVT_MESSAGE_APPEND,
umaxtostr (size, buf));
char *buf = NULL;
mu_asprintf (&buf, "%lu", (unsigned long) size);
mu_observable_notify (mailbox->observable, MU_EVT_MESSAGE_APPEND, buf);
free (buf);
}
return 0;
......
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 1999, 2000, 2001, 2002, 2003,
2004, 2005, 2007, 2008 Free Software Foundation, Inc.
2004, 2005, 2007, 2008, 2009 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
......@@ -63,10 +63,10 @@
#include <mailutils/stream.h>
#include <mailutils/url.h>
#include <mailutils/observer.h>
#include <mailutils/io.h>
#include <mailbox0.h>
#include <registrar0.h>
#include <amd.h>
#include <mu_umaxtostr.h>
struct _mh_message
{
......@@ -102,9 +102,13 @@ _mh_cur_message_name (struct _amd_message *amsg, char **pname)
int status = 0;
struct _mh_message *mhm = (struct _mh_message *) amsg;
char *filename;
char buf[UINTMAX_STRSIZE_BOUND];
char *pnum = umaxtostr (mhm->seq_number, buf);
size_t len = strlen (amsg->amd->name) + 1 + strlen (pnum) + 1;
char *pnum;
size_t len;
status = mu_asprintf (&pnum, "%lu", (unsigned long) mhm->seq_number);
if (status)
return status;
len = strlen (amsg->amd->name) + 1 + strlen (pnum) + 1;
filename = malloc (len);
if (filename)
{
......@@ -115,6 +119,7 @@ _mh_cur_message_name (struct _amd_message *amsg, char **pname)
}
else
status = ENOMEM;
free (pnum);
return status;
}
......@@ -126,9 +131,13 @@ _mh_new_message_name (struct _amd_message *amsg, int flags, char **pname)
int status = 0;
struct _mh_message *mhm = (struct _mh_message *) amsg;
char *filename;
char buf[UINTMAX_STRSIZE_BOUND];
char *pnum = umaxtostr (mhm->seq_number, buf);
size_t len = strlen (amsg->amd->name) + 1 +
char *pnum;
size_t len;
status = mu_asprintf (&pnum, "%lu", (unsigned long) mhm->seq_number);
if (status)
return status;
len = strlen (amsg->amd->name) + 1 +
((flags & MU_ATTRIBUTE_DELETED) ? 1 : 0) + strlen (pnum) + 1;
filename = malloc (len);
if (filename)
......@@ -142,6 +151,7 @@ _mh_new_message_name (struct _amd_message *amsg, int flags, char **pname)
}
else
status = ENOMEM;
free (pnum);
return status;
}
......
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 1999,2000,2001,2003,2005,2007 Free Software Foundation, Inc.
Copyright (C) 1999,2000,2001,2003,2005,2007,
2009 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
......@@ -38,7 +39,6 @@
# include <strings.h>
#endif
#include <mu_umaxtostr.h>
#include <mailutils/attribute.h>
#include <mailutils/auth.h>
#include <mailutils/body.h>
......@@ -53,6 +53,7 @@
#include <mailutils/url.h>
#include <mailutils/tls.h>
#include <mailutils/md5.h>
#include <mailutils/io.h>
#include <folder0.h>
#include <mailbox0.h>
......@@ -147,7 +148,8 @@ static int fill_buffer (pop_data_t, char *, size_t);
static int pop_sleep (int);
static int pop_readline (pop_data_t);
static int pop_read_ack (pop_data_t);
static int pop_writeline (pop_data_t, const char *, ...);
static int pop_writeline (pop_data_t, const char *, ...)
MU_PRINTFLIKE(2,3);
static int pop_write (pop_data_t);
static int pop_get_user (mu_authority_t);
static int pop_get_passwd (mu_authority_t);
......@@ -1295,9 +1297,9 @@ pop_expunge (mu_mailbox_t mbox)
switch (mpd->state)
{
case POP_NO_STATE:
status = pop_writeline (mpd, "DELE %s\r\n",
mu_umaxtostr (0,
mpd->pmessages[i]->num));
status = pop_writeline (mpd, "DELE %lu\r\n",
(unsigned long)
mpd->pmessages[i]->num);
CHECK_ERROR (mpd, status);
MU_DEBUG (mbox->debug, MU_DEBUG_PROT, mpd->buffer);
mpd->state = POP_DELE;
......@@ -1391,7 +1393,7 @@ pop_message_size (mu_message_t msg, size_t *psize)
switch (mpd->state)
{
case POP_NO_STATE:
status = pop_writeline (mpd, "LIST %s\r\n", mu_umaxtostr (0, mpm->num));
status = pop_writeline (mpd, "LIST %lu\r\n", (unsigned long) mpm->num);
CHECK_ERROR (mpd, status);
MU_DEBUG (mpd->mbox->debug, MU_DEBUG_PROT, mpd->buffer);
mpd->state = POP_LIST;
......@@ -1610,7 +1612,7 @@ pop_uidl (mu_message_t msg, char *buffer, size_t buflen, size_t *pnwriten)
switch (mpd->state)
{
case POP_NO_STATE:
status = pop_writeline (mpd, "UIDL %s\r\n", mu_umaxtostr (0, mpm->num));
status = pop_writeline (mpd, "UIDL %lu\r\n", (unsigned long) mpm->num);
CHECK_ERROR (mpd, status);
MU_DEBUG (mpd->mbox->debug, MU_DEBUG_PROT, mpd->buffer);
mpd->state = POP_UIDL;
......@@ -1705,8 +1707,8 @@ pop_top (mu_header_t header, char *buffer, size_t buflen,
case POP_NO_STATE:
if (mpd->capa & CAPA_TOP)
{
status = pop_writeline (mpd, "TOP %s 0\r\n",
mu_umaxtostr (0, mpm->num));
status = pop_writeline (mpd, "TOP %lu 0\r\n",
(unsigned long) mpm->num);
CHECK_ERROR (mpd, status);
MU_DEBUG (mpd->mbox->debug, MU_DEBUG_PROT, mpd->buffer);
mpd->state = POP_TOP;
......@@ -1931,8 +1933,8 @@ pop_retr (pop_message_t mpm, char *buffer, size_t buflen,
{
case POP_NO_STATE:
mpm->body_lines = mpm->body_size = 0;
status = pop_writeline (mpd, "RETR %s\r\n",
mu_umaxtostr (0, mpm->num));
status = pop_writeline (mpd, "RETR %lu\r\n",
(unsigned long) mpm->num);
MU_DEBUG (mpd->mbox->debug, MU_DEBUG_PROT, mpd->buffer);
CHECK_ERROR (mpd, status);
mpd->state = POP_RETR;
......
## Process this file with GNU Automake to create Makefile.in
## Copyright (C) 2000, 2001, 2002, 2004, 2005, 2006, 2007, 2008
## Free Software Foundation, Inc.
## Copyright (C) 2000, 2001, 2002, 2004, 2005, 2006, 2007, 2008,
## 2009 Free Software Foundation, Inc.
##
## GNU Mailutils is free software; you can redistribute it and/or
## modify it under the terms of the GNU General Public License as
......@@ -41,9 +41,7 @@ EXTRA_DIST = \
fgetpwent.c\
cfg_lexer.l\
cfg_parser.y\
cfg_parser.h\
inttostr.c\
inttostr.h
cfg_parser.h
libmailutils_la_SOURCES = \
acl.c\
......@@ -51,6 +49,8 @@ libmailutils_la_SOURCES = \
alloc.c\
amd.c\
argcv.c\
asnprintf.c\
asprintf.c\
assoc.c\
attachment.c\
attribute.c\
......@@ -97,8 +97,6 @@ libmailutils_la_SOURCES = \
monitor.c\
msrv.c\
mu_auth.c\
mu_umaxtostr.h\
mu_umaxtostr.c\
munre.c\
mutil.c\
muerror.c\
......@@ -124,9 +122,9 @@ libmailutils_la_SOURCES = \
tcp.c\
url.c\
vartab.c\
vasnprintf.c\
version.c\
wicket.c\
imaxtostr.c offtostr.c umaxtostr.c intprops.h
wicket.c
BUILT_SOURCES = parsedate.c muerrno.c cfg_parser.c cfg_parser.h cfg_lexer.c
MOSTLYCLEANFILES=
......
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2007, 2008 Free Software Foundation, Inc.
Copyright (C) 2007, 2008, 2009 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
......@@ -36,7 +36,7 @@
#include <mailutils/errno.h>
#include <mailutils/kwd.h>
#include <mailutils/vartab.h>
#include <mu_umaxtostr.h>
#include <mailutils/io.h>
struct _mu_acl_entry
{
......@@ -368,7 +368,7 @@ mu_sockaddr_to_str (const struct sockaddr *sa, int salen,
char *bufptr, size_t buflen,
size_t *plen)
{
char buf[UINTMAX_STRSIZE_BOUND]; /* FIXME: too much */
char *nbuf;
size_t len = 0;
switch (sa->sa_family)
{
......@@ -377,8 +377,11 @@ mu_sockaddr_to_str (const struct sockaddr *sa, int salen,
struct sockaddr_in s_in = *(struct sockaddr_in *)sa;
len += mu_stpcpy (&bufptr, &buflen, inet_ntoa (s_in.sin_addr));
len += mu_stpcpy (&bufptr, &buflen, ":");
len += mu_stpcpy (&bufptr, &buflen, umaxtostr (ntohs (s_in.sin_port),
buf));
if (mu_asprintf (&nbuf, "%hu", ntohs (s_in.sin_port)) == 0)
{
len += mu_stpcpy (&bufptr, &buflen, nbuf);
free (nbuf);
}
break;
}
......@@ -396,8 +399,12 @@ mu_sockaddr_to_str (const struct sockaddr *sa, int salen,
}
default:
len += mu_stpcpy (&bufptr, &buflen, "{Unsupported family: ");
len += mu_stpcpy (&bufptr, &buflen, umaxtostr (sa->sa_family, buf));
len += mu_stpcpy (&bufptr, &buflen, "{Unsupported family");
if (mu_asprintf (&nbuf, ": %d", sa->sa_family) == 0)
{
len += mu_stpcpy (&bufptr, &buflen, nbuf);
free (nbuf);
}
len += mu_stpcpy (&bufptr, &buflen, "}");
}
if (plen)
......@@ -500,10 +507,8 @@ static int
_expand_aclno (const char *name, void *data, char **p)
{
struct run_closure *rp = data;
char buf[UINTMAX_STRSIZE_BOUND];
/*FIXME: memory leak*/
*p = strdup (umaxtostr (rp->idx, buf));
return 0;
return mu_asprintf (p, "%u", rp->idx);
}
#if defined (HAVE_SYSCONF) && defined (_SC_OPEN_MAX)
......@@ -530,14 +535,13 @@ expand_arg (const char *cmdline, struct run_closure *rp, char **s)
{
struct sockaddr_in *s_in = (struct sockaddr_in *)rp->sa;
struct in_addr addr = s_in->sin_addr;
char buf[UINTMAX_STRSIZE_BOUND];
unsigned n;
char *p;
mu_vartab_define (vtab, "family", "AF_INET", 1);
addr.s_addr = htonl (addr.s_addr);
mu_vartab_define (vtab, "address", inet_ntoa (addr), 0);
n = ntohs (s_in->sin_port);
mu_vartab_define (vtab, "port", umaxtostr (n, buf), 0);
if (mu_asprintf (&p, "%hu", ntohs (s_in->sin_port)) == 0)
mu_vartab_define (vtab, "port", p, 0);
}
break;
......@@ -768,7 +772,7 @@ mu_acl_check_fd (mu_acl_t acl, int fd, mu_acl_result_t *pres)
{
MU_DEBUG1 (acl->debug, MU_DEBUG_ERROR,
"Cannot obtain IP address of client: %s",
strerror (errno));
mu_strerror (errno));
return MU_ERR_FAILURE;
}
......
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2009 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General
Public License along with this library; if not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301 USA */
#if HAVE_CONFIG_H
# include <config.h>
#endif
#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h>
#include <mailutils/io.h>
int
mu_asnprintf (char **pbuf, size_t *psize, const char *fmt, ...)
{
int rc;
va_list ap;
va_start (ap, fmt);
rc = mu_vasnprintf (pbuf, psize, fmt, ap);
va_end (ap);
return rc;
}
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2009 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General
Public License along with this library; if not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301 USA */
#if HAVE_CONFIG_H
# include <config.h>
#endif
#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h>
#include <mailutils/io.h>
int
mu_asprintf (char **pbuf, const char *fmt, ...)
{
va_list ap;
size_t size;
int rc;
va_start (ap, fmt);
*pbuf = NULL;
size = 0;
rc = mu_vasnprintf (pbuf, &size, fmt, ap);
va_end (ap);
return rc;
}
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2004, 2005, 2007, 2008 Free Software Foundation, Inc.
Copyright (C) 2004, 2005, 2007, 2008, 2009 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
......@@ -32,7 +32,6 @@
#include <mailutils/errno.h>
#include <mailutils/error.h>
#include <mailutils/nls.h>
#include <mu_umaxtostr.h>
static char *pidfile;
static pid_t current_pid;
......@@ -80,7 +79,6 @@ int
mu_daemon_create_pidfile (const char *filename)
{
char *p;
const char *pid_string;
int fd;
uid_t uid = 0;
int rc;
......@@ -122,11 +120,20 @@ mu_daemon_create_pidfile (const char *filename)
if ((fd = open (pidfile, O_WRONLY | O_CREAT | O_TRUNC | O_EXCL, 0644)) != -1)
{
pid_string = mu_umaxtostr (0, current_pid);
write (fd, pid_string, strlen (pid_string));
FILE *fp = fdopen (fd, "w");
if (!fp)
{
rc = errno;
free (pidfile);
close (fd);
}
else
{
fprintf (fp, "%lu", (unsigned long) current_pid);
fclose (fp);
atexit (mu_daemon_remove_pidfile);
}
}
else
{
rc = errno;
......
#define inttostr imaxtostr
#define inttype intmax_t
#include "inttostr.c"
/* intprops.h -- properties of integer types
Copyright (C) 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
/* Written by Paul Eggert. */
#include <limits.h>
/* The extra casts in the following macros work around compiler bugs,
e.g., in Cray C 5.0.3.0. */
/* True if the arithmetic type T is an integer type. bool counts as
an integer. */
#define TYPE_IS_INTEGER(t) ((t) 1.5 == 1)
/* True if negative values of the signed integer type T use two's
complement, ones' complement, or signed magnitude representation,
respectively. Much GNU code assumes two's complement, but some
people like to be portable to all possible C hosts. */
#define TYPE_TWOS_COMPLEMENT(t) ((t) ~ (t) 0 == (t) -1)
#define TYPE_ONES_COMPLEMENT(t) ((t) ~ (t) 0 == 0)
#define TYPE_SIGNED_MAGNITUDE(t) ((t) ~ (t) 0 < (t) -1)
/* True if the arithmetic type T is signed. */
#define TYPE_SIGNED(t) (! ((t) 0 < (t) -1))
/* The maximum and minimum values for the integer type T. These
macros have undefined behavior if T is signed and has padding bits.
If this is a problem for you, please let us know how to fix it for
your host. */
#define TYPE_MINIMUM(t) \
((t) (! TYPE_SIGNED (t) \
? (t) 0 \
: TYPE_SIGNED_MAGNITUDE (t) \
? ~ (t) 0 \
: ~ (t) 0 << (sizeof (t) * CHAR_BIT - 1)))
#define TYPE_MAXIMUM(t) \
((t) (! TYPE_SIGNED (t) \
? (t) -1 \
: ~ (~ (t) 0 << (sizeof (t) * CHAR_BIT - 1))))
/* Return zero if T can be determined to be an unsigned type.
Otherwise, return 1.
When compiling with GCC, INT_STRLEN_BOUND uses this macro to obtain a
tighter bound. Otherwise, it overestimates the true bound by one byte
when applied to unsigned types of size 2, 4, 16, ... bytes.
The symbol signed_type_or_expr__ is private to this header file. */
#if __GNUC__ >= 2
# define signed_type_or_expr__(t) TYPE_SIGNED (__typeof__ (t))
#else
# define signed_type_or_expr__(t) 1
#endif
/* Bound on length of the string representing an integer type or expression T.
Subtract 1 for the sign bit if T is signed; log10 (2.0) < 146/485;
add 1 for integer division truncation; add 1 more for a minus sign
if needed. */
#define INT_STRLEN_BOUND(t) \
((sizeof (t) * CHAR_BIT - signed_type_or_expr__ (t)) * 146 / 485 \
+ signed_type_or_expr__ (t) + 1)
/* Bound on buffer size needed to represent an integer type or expression T,
including the terminating null. */
#define INT_BUFSIZE_BOUND(t) (INT_STRLEN_BOUND (t) + 1)
/* inttostr.c -- convert integers to printable strings
Copyright (C) 2001 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
/* Written by Paul Eggert */
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include "inttostr.h"
/* Convert I to a printable string in BUF, which must be at least
INT_BUFSIZE_BOUND (INTTYPE) bytes long. Return the address of the
printable string, which need not start at BUF. */
char *
inttostr (inttype i, char *buf)
{
char *p = buf + INT_STRLEN_BOUND (inttype);
*p = 0;
if (i < 0)
{
do
*--p = '0' - i % 10;
while ((i /= 10) != 0);
*--p = '-';
}
else
{
do
*--p = '0' + i % 10;
while ((i /= 10) != 0);
}
return p;
}
/* inttostr.h -- convert integers to printable strings
Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006 Free Software
Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
/* Written by Paul Eggert */
#include <stdint.h>
#include <sys/types.h>
#include "intprops.h"
char *offtostr (off_t, char *);
char *imaxtostr (intmax_t, char *);
char *umaxtostr (uintmax_t, char *);
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 1999, 2000, 2001, 2004, 2005, 2006,
2007 Free Software Foundation, Inc.
2007, 2009 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
......@@ -47,7 +47,7 @@
#include <mailutils/argcv.h>
#include <mailutils/mutil.h>
#include <mailutils/mime.h>
#include <mu_umaxtostr.h>
#include <mailutils/io.h>
#include <mailer0.h>
......@@ -404,19 +404,19 @@ create_part (mu_mime_t mime, mu_stream_t istr,
mu_body_t body;
mu_stream_t ostr;
char buffer[512], *str;
const char *nstr, *npartstr;
size_t slen;
mu_message_create (&newmsg, NULL);
mu_message_get_header (newmsg, &newhdr);
nstr = mu_umaxtostr (0, n);
npartstr = mu_umaxtostr (1, nparts);
asprintf (&str,
"message/partial; id=\"%s\"; number=%s; total=%s",
msgid, nstr, npartstr);
str = NULL;
slen = 0;
mu_asnprintf (&str, &slen,
"message/partial; id=\"%s\"; number=%lu; total=%lu",
msgid, (unsigned long)n, (unsigned long)nparts);
mu_header_append (newhdr, MU_HEADER_CONTENT_TYPE, str);
free (str);
asprintf (&str, "part %s of %s", nstr, npartstr);
mu_asnprintf (&str, &slen, "part %lu of %lu",
(unsigned long)n, (unsigned long)nparts);
mu_header_append (newhdr, MU_HEADER_CONTENT_DESCRIPTION, str);
free (str);
......
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 1999, 2000, 2001, 2002, 2004,
2005, 2006, 2007 Free Software Foundation, Inc.
2005, 2006, 2007, 2009 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
......@@ -50,7 +50,7 @@
#include <mailutils/mu_auth.h>
#include <mailutils/nls.h>
#include <mailutils/md5.h>
#include <mu_umaxtostr.h>
#include <mailutils/io.h>
#define MESSAGE_MODIFIED 0x10000;
......@@ -638,8 +638,8 @@ mu_message_get_uidl (mu_message_t msg, char *buffer, size_t buflen, size_t *pwri
sprintf (tmp, "%02x", md5digest[n]);
*tmp = '\0';
/* POP3 rfc says that an UID should not be longer than 70. */
snprintf (buf + 32, 70, ".%lu.%s", (unsigned long)time (NULL),
mu_umaxtostr (0, uid));
snprintf (buf + 32, 70, ".%lu.%lu", (unsigned long)time (NULL),
(unsigned long) uid);
mu_header_set_value (header, "X-UIDL", buf, 1);
buflen--; /* leave space for the NULL. */
......
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 1999, 2000, 2001, 2002, 2003,
2005, 2006, 2007 Free Software Foundation, Inc.
2005, 2006, 2007, 2009 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
......@@ -60,6 +60,7 @@
#include <mailutils/filter.h>
#include <mailutils/sql.h>
#include <mailutils/url.h>
#include <mailutils/io.h>
#include <registrar0.h>
......@@ -611,7 +612,7 @@ mu_tempfile (const char *tmpdir, char **namep)
if (fd == -1)
{
mu_error (_("Cannot open temporary file: %s"), strerror (errno));
mu_error (_("Cannot open temporary file: %s"), mu_strerror (errno));
free (filename);
return -1;
}
......@@ -1031,14 +1032,14 @@ mu_rfc2822_msg_id (int subpart, char **pval)
{
struct timeval tv;
gettimeofday (&tv, NULL);
asprintf (&p, "<%s.%lu.%d@%s>",
mu_asprintf (&p, "<%s.%lu.%d@%s>",
date,
(unsigned long) getpid (),
subpart,
host);
}
else
asprintf (&p, "<%s.%lu@%s>", date, (unsigned long) getpid (), host);
mu_asprintf (&p, "<%s.%lu@%s>", date, (unsigned long) getpid (), host);
free (host);
*pval = p;
return 0;
......
#define inttostr offtostr
#define inttype off_t
#include "inttostr.c"
......@@ -40,6 +40,7 @@
#include <mailutils/property.h>
#include <mailutils/errno.h>
#include <mailutils/io.h>
#include <stream0.h>
static int refill (mu_stream_t, mu_off_t);
......@@ -493,43 +494,16 @@ mu_stream_write (mu_stream_t os, const char *buf, size_t count,
int
mu_stream_vprintf (mu_stream_t os, mu_off_t *poff, const char *fmt, va_list ap)
{
char *buf, *p;
size_t buflen = 512;
char *buf = NULL, *p;
size_t buflen = 0;
size_t n;
int done = 0;
int rc;
buf = calloc (1, buflen);
if (buf == NULL)
return ENOMEM;
do
{
n = vsnprintf (buf, buflen, fmt, ap);
if (n < 0 || n >= buflen || !memchr (buf, '\0', n + 1))
{
char *newbuf;
size_t newlen = buflen * 2;
if (newlen < buflen)
{
free (buf);
return ENOMEM;
}
newbuf = realloc (buf, newlen);
if (newbuf == NULL)
{
free (buf);
return ENOMEM;
}
buflen = newlen;
buf = newbuf;
}
else
done = 1;
}
while (!done);
rc = mu_vasnprintf (&buf, &buflen, fmt, ap);
if (rc)
return rc;
p = buf;
n = strlen (buf);
do
{
size_t wrs;
......
#define inttostr umaxtostr
#define inttype uintmax_t
#include "inttostr.c"
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2009 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General
Public License along with this library; if not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301 USA */
#if HAVE_CONFIG_H
# include <config.h>
#endif
#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <mailutils/io.h>
int
mu_vasnprintf (char **pbuf, size_t *psize, const char *fmt, va_list ap)
{
char *buf = *pbuf;
size_t buflen = *psize;
int rc = 0;
if (!buf)
{
if (buflen == 0)
buflen = 512; /* Initial allocation */
buf = calloc (1, buflen);
if (buf == NULL)
return ENOMEM;
}
for (;;)
{
ssize_t n = vsnprintf (buf, buflen, fmt, ap);
if (n < 0 || n >= buflen || !memchr (buf, '\0', n + 1))
{
char *newbuf;
size_t newlen = buflen * 2;
if (newlen < buflen)
{
rc = ENOMEM;
break;
}
newbuf = realloc (buf, newlen);
if (newbuf == NULL)
{
rc = ENOMEM;
break;
}
buflen = newlen;
buf = newbuf;
}
else
break;
}
if (rc)
{
if (!*pbuf)
{
/* We made first allocation, now free it */
free (buf);
buf = NULL;
buflen = 0;
}
}
*pbuf = buf;
*psize = buflen;
return rc;
}