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
1 # Bootstrap configuration. 1 # Bootstrap configuration.
2 2
3 # Copyright (C) 2006, 2007, 2008 Free Software Foundation, Inc. 3 # Copyright (C) 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
4 4
5 # This program is free software; you can redistribute it and/or modify 5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by 6 # it under the terms of the GNU General Public License as published by
...@@ -77,10 +77,6 @@ excluded_files=' ...@@ -77,10 +77,6 @@ excluded_files='
77 m4/visibility.m4 77 m4/visibility.m4
78 ' 78 '
79 79
80 gnulib_extra_files="$gnulib_extra_files
81 m4/inttostr.m4
82 "
83
84 # Read local configuration file 80 # Read local configuration file
85 if [ -r .bootstrap ]; then 81 if [ -r .bootstrap ]; then
86 echo "$0: Reading configuration file .bootstrap" 82 echo "$0: Reading configuration file .bootstrap"
......
...@@ -2,9 +2,6 @@ ...@@ -2,9 +2,6 @@
2 # A module name per line. Empty lines and comments are ignored. 2 # A module name per line. Empty lines and comments are ignored.
3 3
4 # FIXME: regex and glob are used by libmailutils... 4 # FIXME: regex and glob are used by libmailutils...
5 # FIXME: intprops and stdint are not used directly, they are needed for
6 # inttostr, which is included in mailbox. Another inttostr dependency,
7 # m4/inttostr.m4, is set in bootstrap.conf.
8 5
9 alloca 6 alloca
10 autobuild 7 autobuild
...@@ -16,6 +13,7 @@ getpass-gnu ...@@ -16,6 +13,7 @@ getpass-gnu
16 gettext 13 gettext
17 gitlog-to-changelog 14 gitlog-to-changelog
18 intprops 15 intprops
16 inttostr
19 malloc 17 malloc
20 mbswidth 18 mbswidth
21 obstack 19 obstack
......
1 ## Process this file with GNU Automake to create Makefile.in 1 ## Process this file with GNU Automake to create Makefile.in
2 2
3 ## Copyright (C) 2000, 2001, 2002, 2003, 3 ## Copyright (C) 2000, 2001, 2002, 2003,
4 ## 2004, 2005, 2007, 2008 Free Software Foundation, Inc. 4 ## 2004, 2005, 2007, 2008, 2009 Free Software Foundation, Inc.
5 ## 5 ##
6 ## GNU Mailutils is free software; you can redistribute it and/or 6 ## GNU Mailutils is free software; you can redistribute it and/or
7 ## modify it under the terms of the GNU General Public License as 7 ## modify it under the terms of the GNU General Public License as
...@@ -53,6 +53,7 @@ pkginclude_HEADERS = \ ...@@ -53,6 +53,7 @@ pkginclude_HEADERS = \
53 gsasl.h\ 53 gsasl.h\
54 guile.h\ 54 guile.h\
55 header.h\ 55 header.h\
56 io.h\
56 iterator.h\ 57 iterator.h\
57 kwd.h\ 58 kwd.h\
58 ldap.h\ 59 ldap.h\
......
1 /* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 2009 Free Software Foundation, Inc.
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 3 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General
15 Public License along with this library; if not, write to the
16 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301 USA */
18
19 #ifndef _MAILUTILS_IO_H
20 #define _MAILUTILS_IO_H
21
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25
26 int mu_asprintf (char **pbuf, const char *fmt, ...);
27 int mu_asnprintf (char **pbuf, size_t *psize, const char *fmt, ...);
28 int mu_vasnprintf (char **pbuf, size_t *psize, const char *fmt, va_list ap);
29
30 #ifdef __cplusplus
31 }
32 #endif
33
34 #endif
1 /* GNU Mailutils -- a suite of utilities for electronic mail 1 /* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 1999, 2000, 2001, 2002, 2003, 2 Copyright (C) 1999, 2000, 2001, 2002, 2003,
3 2004, 2007, 2008 Free Software Foundation, Inc. 3 2004, 2007, 2008, 2009 Free Software Foundation, Inc.
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public 6 modify it under the terms of the GNU Lesser General Public
...@@ -61,6 +61,7 @@ ...@@ -61,6 +61,7 @@
61 #include <mailutils/gocs.h> 61 #include <mailutils/gocs.h>
62 #include <mailutils/version.h> 62 #include <mailutils/version.h>
63 #include <mailutils/vartab.h> 63 #include <mailutils/vartab.h>
64 #include <mailutils/io.h>
64 65
65 #ifdef MU_COMPAT 66 #ifdef MU_COMPAT
66 # error "Version 0.6 is no longer supported. Please, update your program." 67 # error "Version 0.6 is no longer supported. Please, update your program."
......
1 ## Process this file with GNU Automake to create Makefile.in 1 ## Process this file with GNU Automake to create Makefile.in
2 2
3 ## Copyright (C) 1999, 2000, 2001, 2002, 2005, 3 ## Copyright (C) 1999, 2000, 2001, 2002, 2005,
4 ## 2007, 2008 Free Software Foundation, Inc. 4 ## 2007, 2008, 2009 Free Software Foundation, Inc.
5 ## 5 ##
6 ## GNU Mailutils is free software; you can redistribute it and/or 6 ## GNU Mailutils is free software; you can redistribute it and/or
7 ## modify it under the terms of the GNU General Public License as 7 ## modify it under the terms of the GNU General Public License as
...@@ -29,7 +29,9 @@ libmuaux_la_SOURCES += \ ...@@ -29,7 +29,9 @@ libmuaux_la_SOURCES += \
29 signal.c\ 29 signal.c\
30 strexit.c\ 30 strexit.c\
31 tcpwrap.c\ 31 tcpwrap.c\
32 userprivs.c 32 userprivs.c\
33 mu_umaxtostr.c\
34 mu_umaxtostr.h
33 35
34 noinst_HEADERS +=\ 36 noinst_HEADERS +=\
35 mailcap.h\ 37 mailcap.h\
......
1 /* GNU Mailutils -- a suite of utilities for electronic mail 1 /* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 2005, 2007, 2008 Free Software Foundation, Inc. 2 Copyright (C) 2005, 2007, 2008, 2009 Free Software Foundation, Inc.
3 3
4 This library is free software; you can redistribute it and/or 4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public 5 modify it under the terms of the GNU Lesser General Public
...@@ -183,26 +183,12 @@ mu_grad_logger(int level, ...@@ -183,26 +183,12 @@ mu_grad_logger(int level,
183 char *pfx = NULL; 183 char *pfx = NULL;
184 if (loc) 184 if (loc)
185 { 185 {
186 char buf[INT_STRLEN_BOUND(uintmax_t)];
187 char *p = umaxtostr (loc->line, buf);
188 size_t size = strlen (loc->file) + 1 + strlen (p) + 2 + strlen (fmt) + 1;
189 if (func_name) 186 if (func_name)
190 size += strlen (func_name) + 1; 187 mu_asprintf (&pfx, "%s:%lu:%s: %s",
191 pfx = malloc (size); 188 loc->file, (unsigned long) loc->line, func_name, fmt);
192 if (pfx) 189 else
193 { 190 mu_asprintf (&pfx, "%s:%lu: %s",
194 strcpy (pfx, loc->file); 191 loc->file, (unsigned long) loc->line, fmt);
195 strcat (pfx, ":");
196 strcat (pfx, p);
197 strcat (pfx, ":");
198 if (func_name)
199 {
200 strcat (pfx, func_name);
201 strcat (pfx, ":");
202 }
203 strcat (pfx, " ");
204 strcat (pfx, fmt);
205 }
206 } 192 }
207 mu_diag_voutput (mlevel[level & GRAD_LOG_PRIMASK], pfx ? pfx : fmt, ap); 193 mu_diag_voutput (mlevel[level & GRAD_LOG_PRIMASK], pfx ? pfx : fmt, ap);
208 if (pfx) 194 if (pfx)
......
1 /* This file is part of GNU Mailutils 1 /* This file is part of GNU Mailutils
2 Copyright (C) 2007, 2008 Free Software Foundation, Inc. 2 Copyright (C) 2007, 2008, 2009 Free Software Foundation, Inc.
3 3
4 GNU Mailutils is free software; you can redistribute it and/or 4 GNU Mailutils is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License as 5 modify it under the terms of the GNU General Public License as
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
24 #include <mailutils/debug.h> 24 #include <mailutils/debug.h>
25 #include <mailutils/syslog.h> 25 #include <mailutils/syslog.h>
26 #include <mailutils/mailbox.h> 26 #include <mailutils/mailbox.h>
27 #include <mu_umaxtostr.h> 27 #include <mailutils/io.h>
28 28
29 static struct mu_gocs_locking locking_settings; 29 static struct mu_gocs_locking locking_settings;
30 static struct mu_gocs_logging logging_settings; 30 static struct mu_gocs_logging logging_settings;
...@@ -164,9 +164,6 @@ DCL_CFG_CAPA (logging); ...@@ -164,9 +164,6 @@ DCL_CFG_CAPA (logging);
164 static int 164 static int
165 _cb2_debug_level (mu_debug_t debug, const char *arg, void *data MU_ARG_UNUSED) 165 _cb2_debug_level (mu_debug_t debug, const char *arg, void *data MU_ARG_UNUSED)
166 { 166 {
167 char buf[UINTMAX_STRSIZE_BOUND];
168 char *p;
169 size_t size;
170 char *pfx; 167 char *pfx;
171 struct mu_debug_locus locus; 168 struct mu_debug_locus locus;
172 169
...@@ -175,24 +172,21 @@ _cb2_debug_level (mu_debug_t debug, const char *arg, void *data MU_ARG_UNUSED) ...@@ -175,24 +172,21 @@ _cb2_debug_level (mu_debug_t debug, const char *arg, void *data MU_ARG_UNUSED)
175 debug_settings.string = strdup (arg); 172 debug_settings.string = strdup (arg);
176 if (mu_debug_get_locus (debug, &locus) == 0) 173 if (mu_debug_get_locus (debug, &locus) == 0)
177 { 174 {
178 p = umaxtostr (locus.line, buf); 175 int status = mu_asprintf (&pfx, "%s:%lu",
179 size = strlen (locus.file) + 1 + strlen (p) + 1; 176 locus.file, (unsigned long) locus.line);
180 pfx = malloc (size); 177 if (status)
181 if (!pfx)
182 { 178 {
183 mu_cfg_format_error (debug, MU_DEBUG_ERROR, 179 mu_cfg_format_error (debug, MU_DEBUG_ERROR,
184 "%s", mu_strerror (errno)); 180 "%s", mu_strerror (status));
185 return 1; 181 return 1;
186 } 182 }
187 strcpy (pfx, locus.file);
188 strcat (pfx, ":");
189 strcat (pfx, p);
190 } 183 }
191 else 184 else
192 pfx = strdup ("command line");/*FIXME*/ 185 pfx = strdup ("command line");/*FIXME*/
193 /*FIXME: this is suboptimal, there's no use parsing 1st arg in 186 /*FIXME: this is suboptimal, there's no use parsing 1st arg in
194 mu_global_debug_from_string */ 187 mu_global_debug_from_string */
195 mu_global_debug_from_string (debug_settings.string, pfx); 188 mu_global_debug_from_string (debug_settings.string, pfx);
189 free (pfx);
196 free (debug_settings.string); 190 free (debug_settings.string);
197 free (debug_settings.errpfx); 191 free (debug_settings.errpfx);
198 memset (&debug_settings, 0, sizeof debug_settings); 192 memset (&debug_settings, 0, sizeof debug_settings);
......
1 /* GNU Mailutils -- a suite of utilities for electronic mail 1 /* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 1999, 2000, 2001, 2006, 2007 Free Software Foundation, Inc. 2 Copyright (C) 1999, 2000, 2001, 2006, 2007,
3 2009 Free Software Foundation, Inc.
3 4
4 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public 6 modify it under the terms of the GNU Lesser General Public
...@@ -17,7 +18,7 @@ ...@@ -17,7 +18,7 @@
17 Boston, MA 02110-1301 USA */ 18 Boston, MA 02110-1301 USA */
18 19
19 #include "mu_scm.h" 20 #include "mu_scm.h"
20 #include <mu_umaxtostr.h> 21 #include <mailutils/io.h>
21 22
22 struct mu_port 23 struct mu_port
23 { 24 {
...@@ -276,10 +277,13 @@ mu_port_print (SCM exp, SCM port, scm_print_state *pstate) ...@@ -276,10 +277,13 @@ mu_port_print (SCM exp, SCM port, scm_print_state *pstate)
276 scm_puts ("mu-port", port); 277 scm_puts ("mu-port", port);
277 if (mu_stream_size (mp->stream, &size) == 0) 278 if (mu_stream_size (mp->stream, &size) == 0)
278 { 279 {
279 char buffer[64]; 280 char *buf;
280 snprintf (buffer, sizeof (buffer), " %-5s", mu_umaxtostr (0, size)); 281 if (mu_asprintf (&buf, " %5lu", (unsigned long) size) == 0)
281 scm_puts (buffer, port); 282 {
283 scm_puts (buf, port);
282 scm_puts (" chars", port); 284 scm_puts (" chars", port);
285 free (buf);
286 }
283 } 287 }
284 scm_putc ('>', port); 288 scm_putc ('>', port);
285 return 1; 289 return 1;
......
1 /* GNU Mailutils -- a suite of utilities for electronic mail 1 /* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 1999, 2000, 2001, 2003, 2004, 2 Copyright (C) 1999, 2000, 2001, 2003, 2004,
3 2005, 2006, 2007 Free Software Foundation, Inc. 3 2005, 2006, 2007, 2009 Free Software Foundation, Inc.
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public 6 modify it under the terms of the GNU Lesser General Public
...@@ -50,7 +50,6 @@ ...@@ -50,7 +50,6 @@
50 #include <mailutils/argcv.h> 50 #include <mailutils/argcv.h>
51 #include <mailutils/tls.h> 51 #include <mailutils/tls.h>
52 #include <mailutils/nls.h> 52 #include <mailutils/nls.h>
53 #include <mu_umaxtostr.h>
54 53
55 /* For dbg purposes set to one to see different level of traffic. */ 54 /* For dbg purposes set to one to see different level of traffic. */
56 /* Print to stderr the command sent to the IMAP server. */ 55 /* Print to stderr the command sent to the IMAP server. */
...@@ -570,10 +569,10 @@ static int ...@@ -570,10 +569,10 @@ static int
570 imap_writer (void *iodata, char *buf) 569 imap_writer (void *iodata, char *buf)
571 { 570 {
572 f_imap_t iop = iodata; 571 f_imap_t iop = iodata;
573 MU_DEBUG2 (iop->folder->debug, MU_DEBUG_PROT, "g%s %s\n", 572 MU_DEBUG2 (iop->folder->debug, MU_DEBUG_PROT, "g%lu %s\n",
574 mu_umaxtostr (0, iop->seq), buf); 573 (unsigned long)iop->seq, buf);
575 int status = imap_writeline (iop, "g%s %s\r\n", 574 int status = imap_writeline (iop, "g%lu %s\r\n",
576 mu_umaxtostr (0, iop->seq++), buf); 575 (unsigned long)iop->seq++, buf);
577 CHECK_ERROR (iop, status); 576 CHECK_ERROR (iop, status);
578 status = imap_send (iop); 577 status = imap_send (iop);
579 CHECK_ERROR (iop, status); 578 CHECK_ERROR (iop, status);
......
1 /* GNU Mailutils -- a suite of utilities for electronic mail 1 /* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 1999, 2000, 2001, 2003, 2004, 2 Copyright (C) 1999, 2000, 2001, 2003, 2004,
3 2005, 2006, 2007 Free Software Foundation, Inc. 3 2005, 2006, 2007, 2009 Free Software Foundation, Inc.
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public 6 modify it under the terms of the GNU Lesser General Public
...@@ -32,7 +32,6 @@ ...@@ -32,7 +32,6 @@
32 #include <assert.h> 32 #include <assert.h>
33 #include <time.h> 33 #include <time.h>
34 34
35 #include <mu_umaxtostr.h>
36 #include <mailutils/address.h> 35 #include <mailutils/address.h>
37 #include <mailutils/attribute.h> 36 #include <mailutils/attribute.h>
38 #include <mailutils/body.h> 37 #include <mailutils/body.h>
...@@ -46,6 +45,7 @@ ...@@ -46,6 +45,7 @@
46 #include <mailutils/observer.h> 45 #include <mailutils/observer.h>
47 #include <mailutils/property.h> 46 #include <mailutils/property.h>
48 #include <mailutils/stream.h> 47 #include <mailutils/stream.h>
48 #include <mailutils/io.h>
49 49
50 #include <imap0.h> 50 #include <imap0.h>
51 #include <mailbox0.h> 51 #include <mailbox0.h>
...@@ -393,8 +393,8 @@ mailbox_imap_close (mu_mailbox_t mailbox) ...@@ -393,8 +393,8 @@ mailbox_imap_close (mu_mailbox_t mailbox)
393 switch (f_imap->state) 393 switch (f_imap->state)
394 { 394 {
395 case IMAP_NO_STATE: 395 case IMAP_NO_STATE:
396 status = imap_writeline (f_imap, "g%s CLOSE\r\n", 396 status = imap_writeline (f_imap, "g%lu CLOSE\r\n",
397 mu_umaxtostr (0, f_imap->seq++)); 397 (unsigned long) f_imap->seq++);
398 CHECK_ERROR (f_imap, status); 398 CHECK_ERROR (f_imap, status);
399 MU_DEBUG (mailbox->debug, MU_DEBUG_PROT, f_imap->buffer); 399 MU_DEBUG (mailbox->debug, MU_DEBUG_PROT, f_imap->buffer);
400 f_imap->state = IMAP_CLOSE; 400 f_imap->state = IMAP_CLOSE;
...@@ -682,8 +682,8 @@ imap_messages_count (mu_mailbox_t mailbox, size_t *pnum) ...@@ -682,8 +682,8 @@ imap_messages_count (mu_mailbox_t mailbox, size_t *pnum)
682 switch (f_imap->state) 682 switch (f_imap->state)
683 { 683 {
684 case IMAP_NO_STATE: 684 case IMAP_NO_STATE:
685 status = imap_writeline (f_imap, "g%s %s %s\r\n", 685 status = imap_writeline (f_imap, "g%lu %s %s\r\n",
686 mu_umaxtostr (0, f_imap->seq++), 686 (unsigned long) f_imap->seq++,
687 MBX_WRITABLE(mailbox) ? "SELECT" : "EXAMINE", 687 MBX_WRITABLE(mailbox) ? "SELECT" : "EXAMINE",
688 m_imap->name); 688 m_imap->name);
689 CHECK_ERROR (f_imap, status); 689 CHECK_ERROR (f_imap, status);
...@@ -751,8 +751,8 @@ imap_scan0 (mu_mailbox_t mailbox, size_t msgno, size_t *pcount, int notif) ...@@ -751,8 +751,8 @@ imap_scan0 (mu_mailbox_t mailbox, size_t msgno, size_t *pcount, int notif)
751 { 751 {
752 case IMAP_NO_STATE: 752 case IMAP_NO_STATE:
753 status = imap_writeline (f_imap, 753 status = imap_writeline (f_imap,
754 "g%s FETCH 1:* (FLAGS RFC822.SIZE BODY.PEEK[HEADER.FIELDS (%s)])\r\n", 754 "g%lu FETCH 1:* (FLAGS RFC822.SIZE BODY.PEEK[HEADER.FIELDS (%s)])\r\n",
755 mu_umaxtostr (0, f_imap->seq++), 755 (unsigned long) f_imap->seq++,
756 MU_IMAP_CACHE_HEADERS); 756 MU_IMAP_CACHE_HEADERS);
757 CHECK_ERROR (f_imap, status); 757 CHECK_ERROR (f_imap, status);
758 MU_DEBUG (mailbox->debug, MU_DEBUG_PROT, f_imap->buffer); 758 MU_DEBUG (mailbox->debug, MU_DEBUG_PROT, f_imap->buffer);
...@@ -827,8 +827,8 @@ imap_is_updated (mu_mailbox_t mailbox) ...@@ -827,8 +827,8 @@ imap_is_updated (mu_mailbox_t mailbox)
827 switch (f_imap->state) 827 switch (f_imap->state)
828 { 828 {
829 case IMAP_NO_STATE: 829 case IMAP_NO_STATE:
830 status = imap_writeline (f_imap, "g%s NOOP\r\n", 830 status = imap_writeline (f_imap, "g%lu NOOP\r\n",
831 mu_umaxtostr (0, f_imap->seq++)); 831 (unsigned long) f_imap->seq++);
832 CHECK_ERROR (f_imap, status); 832 CHECK_ERROR (f_imap, status);
833 MU_DEBUG (mailbox->debug, MU_DEBUG_PROT, f_imap->buffer); 833 MU_DEBUG (mailbox->debug, MU_DEBUG_PROT, f_imap->buffer);
834 f_imap->state = IMAP_NOOP; 834 f_imap->state = IMAP_NOOP;
...@@ -882,8 +882,8 @@ imap_expunge (mu_mailbox_t mailbox) ...@@ -882,8 +882,8 @@ imap_expunge (mu_mailbox_t mailbox)
882 return 0; 882 return 0;
883 } 883 }
884 status = imap_writeline (f_imap, 884 status = imap_writeline (f_imap,
885 "g%s STORE %s +FLAGS.SILENT (\\Deleted)\r\n", 885 "g%lu STORE %s +FLAGS.SILENT (\\Deleted)\r\n",
886 mu_umaxtostr (0, f_imap->seq++), 886 (unsigned long) f_imap->seq++,
887 set); 887 set);
888 free (set); 888 free (set);
889 CHECK_ERROR (f_imap, status); 889 CHECK_ERROR (f_imap, status);
...@@ -905,8 +905,8 @@ imap_expunge (mu_mailbox_t mailbox) ...@@ -905,8 +905,8 @@ imap_expunge (mu_mailbox_t mailbox)
905 905
906 case IMAP_EXPUNGE: 906 case IMAP_EXPUNGE:
907 case IMAP_EXPUNGE_ACK: 907 case IMAP_EXPUNGE_ACK:
908 status = imap_writeline (f_imap, "g%s EXPUNGE\r\n", 908 status = imap_writeline (f_imap, "g%lu EXPUNGE\r\n",
909 mu_umaxtostr (0, f_imap->seq++)); 909 (unsigned long) f_imap->seq++);
910 CHECK_ERROR (f_imap, status); 910 CHECK_ERROR (f_imap, status);
911 status = imap_send (f_imap); 911 status = imap_send (f_imap);
912 CHECK_EAGAIN (f_imap, status); 912 CHECK_EAGAIN (f_imap, status);
...@@ -1029,11 +1029,11 @@ imap_append_message0 (mu_mailbox_t mailbox, mu_message_t msg) ...@@ -1029,11 +1029,11 @@ imap_append_message0 (mu_mailbox_t mailbox, mu_message_t msg)
1029 mu_message_size (msg, &size); 1029 mu_message_size (msg, &size);
1030 mu_message_lines (msg, &lines); 1030 mu_message_lines (msg, &lines);
1031 total = size + lines; 1031 total = size + lines;
1032 status = imap_writeline (f_imap, "g%s APPEND %s %s {%s}\r\n", 1032 status = imap_writeline (f_imap, "g%lu APPEND %s %s {%lu}\r\n",
1033 mu_umaxtostr (0, f_imap->seq++), 1033 (unsigned long) f_imap->seq++,
1034 path, 1034 path,
1035 abuf, 1035 abuf,
1036 mu_umaxtostr (1, size + lines)); 1036 (unsigned long) (size + lines));
1037 free (abuf); 1037 free (abuf);
1038 CHECK_ERROR (f_imap, status); 1038 CHECK_ERROR (f_imap, status);
1039 MU_DEBUG (mailbox->debug, MU_DEBUG_PROT, f_imap->buffer); 1039 MU_DEBUG (mailbox->debug, MU_DEBUG_PROT, f_imap->buffer);
...@@ -1124,9 +1124,9 @@ imap_copy_message (mu_mailbox_t mailbox, mu_message_t msg) ...@@ -1124,9 +1124,9 @@ imap_copy_message (mu_mailbox_t mailbox, mu_message_t msg)
1124 /* Check for a valid mailbox name. */ 1124 /* Check for a valid mailbox name. */
1125 status = mu_url_sget_path (mailbox->url, &path); 1125 status = mu_url_sget_path (mailbox->url, &path);
1126 if (status == 0) 1126 if (status == 0)
1127 status = imap_writeline (f_imap, "g%s COPY %s %s\r\n", 1127 status = imap_writeline (f_imap, "g%lu COPY %lu %s\r\n",
1128 mu_umaxtostr (0, f_imap->seq++), 1128 (unsigned long) f_imap->seq++,
1129 mu_umaxtostr (1, msg_imap->num), 1129 (unsigned long) msg_imap->num,
1130 path); 1130 path);
1131 CHECK_ERROR (f_imap, status); 1131 CHECK_ERROR (f_imap, status);
1132 MU_DEBUG (mailbox->debug, MU_DEBUG_PROT, f_imap->buffer); 1132 MU_DEBUG (mailbox->debug, MU_DEBUG_PROT, f_imap->buffer);
...@@ -1195,13 +1195,13 @@ imap_message_read (mu_stream_t stream, char *buffer, size_t buflen, ...@@ -1195,13 +1195,13 @@ imap_message_read (mu_stream_t stream, char *buffer, size_t buflen,
1195 /* We have strip the \r, but the offset on the imap server is with that 1195 /* We have strip the \r, but the offset on the imap server is with that
1196 octet(CFLF) so add it in the offset, it's the number of lines. */ 1196 octet(CFLF) so add it in the offset, it's the number of lines. */
1197 status = imap_writeline (f_imap, 1197 status = imap_writeline (f_imap,
1198 "g%s FETCH %s BODY.PEEK[%s]<%s.%s>\r\n", 1198 "g%lu FETCH %lu BODY.PEEK[%s]<%lu.%lu>\r\n",
1199 mu_umaxtostr (0, f_imap->seq++), 1199 (unsigned long) f_imap->seq++,
1200 mu_umaxtostr (1, msg_imap->num), 1200 (unsigned long) msg_imap->num,
1201 (section) ? section : "", 1201 (section) ? section : "",
1202 mu_umaxtostr (2, offset + 1202 (unsigned long) (offset +
1203 msg_imap->mu_message_lines), 1203 msg_imap->mu_message_lines),
1204 mu_umaxtostr (3, buflen)); 1204 (unsigned long) buflen);
1205 if (section) 1205 if (section)
1206 free (section); 1206 free (section);
1207 CHECK_ERROR (f_imap, status); 1207 CHECK_ERROR (f_imap, status);
...@@ -1283,9 +1283,9 @@ imap_message_size (mu_message_t msg, size_t *psize) ...@@ -1283,9 +1283,9 @@ imap_message_size (mu_message_t msg, size_t *psize)
1283 that octet so add it in the offset, since it's the number of 1283 that octet so add it in the offset, since it's the number of
1284 lines. */ 1284 lines. */
1285 status = imap_writeline (f_imap, 1285 status = imap_writeline (f_imap,
1286 "g%s FETCH %s RFC822.SIZE\r\n", 1286 "g%lu FETCH %lu RFC822.SIZE\r\n",
1287 mu_umaxtostr (0, f_imap->seq++), 1287 (unsigned long) f_imap->seq++,
1288 mu_umaxtostr (1, msg_imap->num)); 1288 (unsigned long) msg_imap->num);
1289 CHECK_ERROR (f_imap, status); 1289 CHECK_ERROR (f_imap, status);
1290 MU_DEBUG (m_imap->mailbox->debug, MU_DEBUG_PROT, f_imap->buffer); 1290 MU_DEBUG (m_imap->mailbox->debug, MU_DEBUG_PROT, f_imap->buffer);
1291 f_imap->state = IMAP_FETCH; 1291 f_imap->state = IMAP_FETCH;
...@@ -1324,9 +1324,9 @@ imap_message_uid (mu_message_t msg, size_t *puid) ...@@ -1324,9 +1324,9 @@ imap_message_uid (mu_message_t msg, size_t *puid)
1324 *puid = msg_imap->uid; 1324 *puid = msg_imap->uid;
1325 return 0; 1325 return 0;
1326 } 1326 }
1327 status = imap_writeline (f_imap, "g%s FETCH %s UID\r\n", 1327 status = imap_writeline (f_imap, "g%lu FETCH %lu UID\r\n",
1328 mu_umaxtostr (0, f_imap->seq++), 1328 (unsigned long) f_imap->seq++,
1329 mu_umaxtostr (1, msg_imap->num)); 1329 (unsigned long) msg_imap->num);
1330 CHECK_ERROR (f_imap, status); 1330 CHECK_ERROR (f_imap, status);
1331 MU_DEBUG (m_imap->mailbox->debug, MU_DEBUG_PROT, f_imap->buffer); 1331 MU_DEBUG (m_imap->mailbox->debug, MU_DEBUG_PROT, f_imap->buffer);
1332 f_imap->state = IMAP_FETCH; 1332 f_imap->state = IMAP_FETCH;
...@@ -1369,9 +1369,9 @@ imap_is_multipart (mu_message_t msg, int *ismulti) ...@@ -1369,9 +1369,9 @@ imap_is_multipart (mu_message_t msg, int *ismulti)
1369 return 0; 1369 return 0;
1370 } 1370 }
1371 status = imap_writeline (f_imap, 1371 status = imap_writeline (f_imap,
1372 "g%s FETCH %s BODYSTRUCTURE\r\n", 1372 "g%lu FETCH %lu BODYSTRUCTURE\r\n",
1373 mu_umaxtostr (0, f_imap->seq++), 1373 (unsigned long) f_imap->seq++,
1374 mu_umaxtostr (1, msg_imap->num)); 1374 (unsigned long) msg_imap->num);
1375 CHECK_ERROR (f_imap, status); 1375 CHECK_ERROR (f_imap, status);
1376 MU_DEBUG (m_imap->mailbox->debug, MU_DEBUG_PROT, f_imap->buffer); 1376 MU_DEBUG (m_imap->mailbox->debug, MU_DEBUG_PROT, f_imap->buffer);
1377 f_imap->state = IMAP_FETCH; 1377 f_imap->state = IMAP_FETCH;
...@@ -1509,9 +1509,9 @@ imap_envelope_date (mu_envelope_t envelope, char *buffer, size_t buflen, ...@@ -1509,9 +1509,9 @@ imap_envelope_date (mu_envelope_t envelope, char *buffer, size_t buflen,
1509 if (f_imap->state == IMAP_NO_STATE) 1509 if (f_imap->state == IMAP_NO_STATE)
1510 { 1510 {
1511 status = imap_writeline (f_imap, 1511 status = imap_writeline (f_imap,
1512 "g%s FETCH %s INTERNALDATE\r\n", 1512 "g%lu FETCH %lu INTERNALDATE\r\n",
1513 mu_umaxtostr (0, f_imap->seq++), 1513 (unsigned long) f_imap->seq++,
1514 mu_umaxtostr (1, msg_imap->num)); 1514 (unsigned long) msg_imap->num);
1515 CHECK_ERROR (f_imap, status); 1515 CHECK_ERROR (f_imap, status);
1516 MU_DEBUG (m_imap->mailbox->debug, MU_DEBUG_PROT, f_imap->buffer); 1516 MU_DEBUG (m_imap->mailbox->debug, MU_DEBUG_PROT, f_imap->buffer);
1517 f_imap->state = IMAP_FETCH; 1517 f_imap->state = IMAP_FETCH;
...@@ -1580,9 +1580,9 @@ imap_attr_get_flags (mu_attribute_t attribute, int *pflags) ...@@ -1580,9 +1580,9 @@ imap_attr_get_flags (mu_attribute_t attribute, int *pflags)
1580 1580
1581 if (f_imap->state == IMAP_NO_STATE) 1581 if (f_imap->state == IMAP_NO_STATE)
1582 { 1582 {
1583 status = imap_writeline (f_imap, "g%s FETCH %s FLAGS\r\n", 1583 status = imap_writeline (f_imap, "g%lu FETCH %lu FLAGS\r\n",
1584 mu_umaxtostr (0, f_imap->seq++), 1584 (unsigned long) f_imap->seq++,
1585 mu_umaxtostr (1, msg_imap->num)); 1585 (unsigned long) msg_imap->num);
1586 CHECK_ERROR (f_imap, status); 1586 CHECK_ERROR (f_imap, status);
1587 MU_DEBUG (m_imap->mailbox->debug, MU_DEBUG_PROT, f_imap->buffer); 1587 MU_DEBUG (m_imap->mailbox->debug, MU_DEBUG_PROT, f_imap->buffer);
1588 f_imap->state = IMAP_FETCH; 1588 f_imap->state = IMAP_FETCH;
...@@ -1636,9 +1636,9 @@ imap_attr_set_flags (mu_attribute_t attribute, int flag) ...@@ -1636,9 +1636,9 @@ imap_attr_set_flags (mu_attribute_t attribute, int flag)
1636 free (abuf); 1636 free (abuf);
1637 return 0; 1637 return 0;
1638 } 1638 }
1639 status = imap_writeline (f_imap, "g%s STORE %s +FLAGS.SILENT (%s)\r\n", 1639 status = imap_writeline (f_imap, "g%lu STORE %lu +FLAGS.SILENT (%s)\r\n",
1640 mu_umaxtostr (0, f_imap->seq++), 1640 (unsigned long) f_imap->seq++,
1641 mu_umaxtostr (1, msg_imap->num), 1641 (unsigned long) msg_imap->num,
1642 abuf); 1642 abuf);
1643 free (abuf); 1643 free (abuf);
1644 CHECK_ERROR (f_imap, status); 1644 CHECK_ERROR (f_imap, status);
...@@ -1685,9 +1685,9 @@ imap_attr_unset_flags (mu_attribute_t attribute, int flag) ...@@ -1685,9 +1685,9 @@ imap_attr_unset_flags (mu_attribute_t attribute, int flag)
1685 free (abuf); 1685 free (abuf);
1686 return 0; 1686 return 0;
1687 } 1687 }
1688 status = imap_writeline (f_imap, "g%s STORE %s -FLAGS.SILENT (%s)\r\n", 1688 status = imap_writeline (f_imap, "g%lu STORE %lu -FLAGS.SILENT (%s)\r\n",
1689 mu_umaxtostr (0, f_imap->seq++), 1689 (unsigned long) f_imap->seq++,
1690 mu_umaxtostr (1, msg_imap->num), 1690 (unsigned long) msg_imap->num,
1691 abuf); 1691 abuf);
1692 free (abuf); 1692 free (abuf);
1693 CHECK_ERROR (f_imap, status); 1693 CHECK_ERROR (f_imap, status);
...@@ -1742,24 +1742,24 @@ imap_header_read (mu_header_t header, char *buffer, ...@@ -1742,24 +1742,24 @@ imap_header_read (mu_header_t header, char *buffer,
1742 { 1742 {
1743 char *section = section_name (msg_imap); 1743 char *section = section_name (msg_imap);
1744 status = imap_writeline (f_imap, 1744 status = imap_writeline (f_imap,
1745 "g%s FETCH %s BODY.PEEK[%s.MIME]<%s.%s>\r\n", 1745 "g%lu FETCH %lu BODY.PEEK[%s.MIME]<%lu.%lu>\r\n",
1746 mu_umaxtostr (0, f_imap->seq++), 1746 (unsigned long) f_imap->seq++,
1747 mu_umaxtostr (1, msg_imap->num), 1747 (unsigned long) msg_imap->num,
1748 (section) ? section : "", 1748 (section) ? section : "",
1749 mu_umaxtostr (2, offset + 1749 (unsigned long) (offset +
1750 msg_imap->header_lines), 1750 msg_imap->header_lines),
1751 mu_umaxtostr (3, buflen)); 1751 (unsigned long) buflen);
1752 if (section) 1752 if (section)
1753 free (section); 1753 free (section);
1754 } 1754 }
1755 else 1755 else
1756 status = imap_writeline (f_imap, 1756 status = imap_writeline (f_imap,
1757 "g%s FETCH %s BODY.PEEK[HEADER]<%s.%s>\r\n", 1757 "g%lu FETCH %lu BODY.PEEK[HEADER]<%lu.%lu>\r\n",
1758 mu_umaxtostr (0, f_imap->seq++), 1758 (unsigned long) f_imap->seq++,
1759 mu_umaxtostr (1, msg_imap->num), 1759 (unsigned long) msg_imap->num,
1760 mu_umaxtostr (2, offset + 1760 (unsigned long) (offset +
1761 msg_imap->header_lines), 1761 msg_imap->header_lines),
1762 mu_umaxtostr (3, buflen)); 1762 (unsigned long) buflen);
1763 CHECK_ERROR (f_imap, status); 1763 CHECK_ERROR (f_imap, status);
1764 MU_DEBUG (m_imap->mailbox->debug, MU_DEBUG_PROT, f_imap->buffer); 1764 MU_DEBUG (m_imap->mailbox->debug, MU_DEBUG_PROT, f_imap->buffer);
1765 f_imap->state = IMAP_FETCH; 1765 f_imap->state = IMAP_FETCH;
...@@ -1857,24 +1857,24 @@ imap_body_read (mu_stream_t stream, char *buffer, size_t buflen, ...@@ -1857,24 +1857,24 @@ imap_body_read (mu_stream_t stream, char *buffer, size_t buflen,
1857 { 1857 {
1858 char *section = section_name (msg_imap); 1858 char *section = section_name (msg_imap);
1859 status = imap_writeline (f_imap, 1859 status = imap_writeline (f_imap,
1860 "g%s FETCH %s BODY.PEEK[%s]<%s.%s>\r\n", 1860 "g%lu FETCH %lu BODY.PEEK[%s]<%lu.%lu>\r\n",
1861 mu_umaxtostr (0, f_imap->seq++), 1861 (unsigned long) f_imap->seq++,
1862 mu_umaxtostr (1, msg_imap->num), 1862 (unsigned long) msg_imap->num,
1863 (section) ? section: "", 1863 (section) ? section: "",
1864 mu_umaxtostr (2, offset + 1864 (unsigned long) (offset +
1865 msg_imap->body_lines), 1865 msg_imap->body_lines),
1866 mu_umaxtostr (3, buflen)); 1866 (unsigned long) buflen);
1867 if (section) 1867 if (section)
1868 free (section); 1868 free (section);
1869 } 1869 }
1870 else 1870 else
1871 status = imap_writeline (f_imap, 1871 status = imap_writeline (f_imap,
1872 "g%s FETCH %s BODY.PEEK[TEXT]<%s.%s>\r\n", 1872 "g%lu FETCH %lu BODY.PEEK[TEXT]<%lu.%lu>\r\n",
1873 mu_umaxtostr (0, f_imap->seq++), 1873 (unsigned long) f_imap->seq++,
1874 mu_umaxtostr (1, msg_imap->num), 1874 (unsigned long) msg_imap->num,
1875 mu_umaxtostr (2, offset + 1875 (unsigned long) (offset +
1876 msg_imap->body_lines), 1876 msg_imap->body_lines),
1877 mu_umaxtostr (3, buflen)); 1877 (unsigned long) buflen);
1878 CHECK_ERROR (f_imap, status); 1878 CHECK_ERROR (f_imap, status);
1879 MU_DEBUG (m_imap->mailbox->debug, MU_DEBUG_PROT, f_imap->buffer); 1879 MU_DEBUG (m_imap->mailbox->debug, MU_DEBUG_PROT, f_imap->buffer);
1880 f_imap->state = IMAP_FETCH; 1880 f_imap->state = IMAP_FETCH;
...@@ -2047,7 +2047,7 @@ flags_to_string (char **pbuf, int flag) ...@@ -2047,7 +2047,7 @@ flags_to_string (char **pbuf, int flag)
2047 static int 2047 static int
2048 add_number (char **pset, size_t start, size_t end) 2048 add_number (char **pset, size_t start, size_t end)
2049 { 2049 {
2050 char buf[2*UINTMAX_STRSIZE_BOUND+2]; 2050 char *buf = NULL;
2051 char *set; 2051 char *set;
2052 char *tmp; 2052 char *tmp;
2053 size_t set_len = 0; 2053 size_t set_len = 0;
...@@ -2062,13 +2062,12 @@ add_number (char **pset, size_t start, size_t end) ...@@ -2062,13 +2062,12 @@ add_number (char **pset, size_t start, size_t end)
2062 2062
2063 /* We had a previous seqence. */ 2063 /* We had a previous seqence. */
2064 if (start == 0) 2064 if (start == 0)
2065 *buf = '\0'; 2065 /* nothing */;
2066 else if (start != end) 2066 else if (start != end)
2067 snprintf (buf, sizeof buf, "%s:%s", 2067 mu_asprintf (&buf, "%lu:%lu",
2068 mu_umaxtostr (0, start), 2068 (unsigned long) start, (unsigned long) end);
2069 mu_umaxtostr (1, end));
2070 else 2069 else
2071 snprintf (buf, sizeof buf, "%s", mu_umaxtostr (0, start)); 2070 mu_asprintf (&buf, "%lu", (unsigned long) start);
2072 2071
2073 if (set_len) 2072 if (set_len)
2074 tmp = realloc (set, set_len + strlen (buf) + 2 /* null and comma */); 2073 tmp = realloc (set, set_len + strlen (buf) + 2 /* null and comma */);
...@@ -2078,6 +2077,7 @@ add_number (char **pset, size_t start, size_t end) ...@@ -2078,6 +2077,7 @@ add_number (char **pset, size_t start, size_t end)
2078 if (tmp == NULL) 2077 if (tmp == NULL)
2079 { 2078 {
2080 free (set); 2079 free (set);
2080 free (buf);
2081 return ENOMEM; 2081 return ENOMEM;
2082 } 2082 }
2083 set = tmp; 2083 set = tmp;
...@@ -2086,6 +2086,7 @@ add_number (char **pset, size_t start, size_t end) ...@@ -2086,6 +2086,7 @@ add_number (char **pset, size_t start, size_t end)
2086 if (set_len) 2086 if (set_len)
2087 strcat (set, ","); 2087 strcat (set, ",");
2088 strcat (set, buf); 2088 strcat (set, buf);
2089 free (buf);
2089 2090
2090 *pset = set; 2091 *pset = set;
2091 return 0; 2092 return 0;
......
1 /* GNU Mailutils -- a suite of utilities for electronic mail 1 /* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 1999, 2000, 2001, 2003, 2 Copyright (C) 1999, 2000, 2001, 2003,
3 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc. 3 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public 6 modify it under the terms of the GNU Lesser General Public
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
24 #endif 24 #endif
25 25
26 #include <mbox0.h> 26 #include <mbox0.h>
27 #include <mu_umaxtostr.h> 27 #include <mailutils/io.h>
28 28
29 #define ATTRIBUTE_IS_DELETED(flag) (flag & MU_ATTRIBUTE_DELETED) 29 #define ATTRIBUTE_IS_DELETED(flag) (flag & MU_ATTRIBUTE_DELETED)
30 #define ATTRIBUTE_IS_EQUAL(flag1, flag2) (flag1 == flag2) 30 #define ATTRIBUTE_IS_EQUAL(flag1, flag2) (flag1 == flag2)
...@@ -805,12 +805,7 @@ static int ...@@ -805,12 +805,7 @@ static int
805 mbox_message_qid (mu_message_t msg, mu_message_qid_t *pqid) 805 mbox_message_qid (mu_message_t msg, mu_message_qid_t *pqid)
806 { 806 {
807 mbox_message_t mum = mu_message_get_owner (msg); 807 mbox_message_t mum = mu_message_get_owner (msg);
808 char buf[UINTMAX_STRSIZE_BOUND]; 808 return mu_asprintf (pqid, "%lu", (unsigned long) mum->header_from);
809 const char *p = umaxtostr (mum->header_from, buf);
810 *pqid = strdup (p);
811 if (*pqid == NULL)
812 return ENOMEM;
813 return 0;
814 } 809 }
815 810
816 static int 811 static int
...@@ -1303,9 +1298,10 @@ mbox_append_message (mu_mailbox_t mailbox, mu_message_t msg) ...@@ -1303,9 +1298,10 @@ mbox_append_message (mu_mailbox_t mailbox, mu_message_t msg)
1303 1298
1304 if (mailbox->observable) 1299 if (mailbox->observable)
1305 { 1300 {
1306 char buf[UINTMAX_STRSIZE_BOUND]; 1301 char *buf = NULL;
1307 mu_observable_notify (mailbox->observable, MU_EVT_MESSAGE_APPEND, 1302 mu_asprintf (&buf, "%lu", (unsigned long) size);
1308 umaxtostr (size, buf)); 1303 mu_observable_notify (mailbox->observable, MU_EVT_MESSAGE_APPEND, buf);
1304 free (buf);
1309 } 1305 }
1310 1306
1311 return 0; 1307 return 0;
......
1 /* GNU Mailutils -- a suite of utilities for electronic mail 1 /* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 1999, 2000, 2001, 2002, 2003, 2 Copyright (C) 1999, 2000, 2001, 2002, 2003,
3 2004, 2005, 2007, 2008 Free Software Foundation, Inc. 3 2004, 2005, 2007, 2008, 2009 Free Software Foundation, Inc.
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public 6 modify it under the terms of the GNU Lesser General Public
...@@ -63,10 +63,10 @@ ...@@ -63,10 +63,10 @@
63 #include <mailutils/stream.h> 63 #include <mailutils/stream.h>
64 #include <mailutils/url.h> 64 #include <mailutils/url.h>
65 #include <mailutils/observer.h> 65 #include <mailutils/observer.h>
66 #include <mailutils/io.h>
66 #include <mailbox0.h> 67 #include <mailbox0.h>
67 #include <registrar0.h> 68 #include <registrar0.h>
68 #include <amd.h> 69 #include <amd.h>
69 #include <mu_umaxtostr.h>
70 70
71 struct _mh_message 71 struct _mh_message
72 { 72 {
...@@ -102,9 +102,13 @@ _mh_cur_message_name (struct _amd_message *amsg, char **pname) ...@@ -102,9 +102,13 @@ _mh_cur_message_name (struct _amd_message *amsg, char **pname)
102 int status = 0; 102 int status = 0;
103 struct _mh_message *mhm = (struct _mh_message *) amsg; 103 struct _mh_message *mhm = (struct _mh_message *) amsg;
104 char *filename; 104 char *filename;
105 char buf[UINTMAX_STRSIZE_BOUND]; 105 char *pnum;
106 char *pnum = umaxtostr (mhm->seq_number, buf); 106 size_t len;
107 size_t len = strlen (amsg->amd->name) + 1 + strlen (pnum) + 1; 107
108 status = mu_asprintf (&pnum, "%lu", (unsigned long) mhm->seq_number);
109 if (status)
110 return status;
111 len = strlen (amsg->amd->name) + 1 + strlen (pnum) + 1;
108 filename = malloc (len); 112 filename = malloc (len);
109 if (filename) 113 if (filename)
110 { 114 {
...@@ -115,6 +119,7 @@ _mh_cur_message_name (struct _amd_message *amsg, char **pname) ...@@ -115,6 +119,7 @@ _mh_cur_message_name (struct _amd_message *amsg, char **pname)
115 } 119 }
116 else 120 else
117 status = ENOMEM; 121 status = ENOMEM;
122 free (pnum);
118 return status; 123 return status;
119 } 124 }
120 125
...@@ -126,9 +131,13 @@ _mh_new_message_name (struct _amd_message *amsg, int flags, char **pname) ...@@ -126,9 +131,13 @@ _mh_new_message_name (struct _amd_message *amsg, int flags, char **pname)
126 int status = 0; 131 int status = 0;
127 struct _mh_message *mhm = (struct _mh_message *) amsg; 132 struct _mh_message *mhm = (struct _mh_message *) amsg;
128 char *filename; 133 char *filename;
129 char buf[UINTMAX_STRSIZE_BOUND]; 134 char *pnum;
130 char *pnum = umaxtostr (mhm->seq_number, buf); 135 size_t len;
131 size_t len = strlen (amsg->amd->name) + 1 + 136
137 status = mu_asprintf (&pnum, "%lu", (unsigned long) mhm->seq_number);
138 if (status)
139 return status;
140 len = strlen (amsg->amd->name) + 1 +
132 ((flags & MU_ATTRIBUTE_DELETED) ? 1 : 0) + strlen (pnum) + 1; 141 ((flags & MU_ATTRIBUTE_DELETED) ? 1 : 0) + strlen (pnum) + 1;
133 filename = malloc (len); 142 filename = malloc (len);
134 if (filename) 143 if (filename)
...@@ -142,6 +151,7 @@ _mh_new_message_name (struct _amd_message *amsg, int flags, char **pname) ...@@ -142,6 +151,7 @@ _mh_new_message_name (struct _amd_message *amsg, int flags, char **pname)
142 } 151 }
143 else 152 else
144 status = ENOMEM; 153 status = ENOMEM;
154 free (pnum);
145 return status; 155 return status;
146 } 156 }
147 157
......
1 /* GNU Mailutils -- a suite of utilities for electronic mail 1 /* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 1999,2000,2001,2003,2005,2007 Free Software Foundation, Inc. 2 Copyright (C) 1999,2000,2001,2003,2005,2007,
3 2009 Free Software Foundation, Inc.
3 4
4 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public 6 modify it under the terms of the GNU Lesser General Public
...@@ -38,7 +39,6 @@ ...@@ -38,7 +39,6 @@
38 # include <strings.h> 39 # include <strings.h>
39 #endif 40 #endif
40 41
41 #include <mu_umaxtostr.h>
42 #include <mailutils/attribute.h> 42 #include <mailutils/attribute.h>
43 #include <mailutils/auth.h> 43 #include <mailutils/auth.h>
44 #include <mailutils/body.h> 44 #include <mailutils/body.h>
...@@ -53,6 +53,7 @@ ...@@ -53,6 +53,7 @@
53 #include <mailutils/url.h> 53 #include <mailutils/url.h>
54 #include <mailutils/tls.h> 54 #include <mailutils/tls.h>
55 #include <mailutils/md5.h> 55 #include <mailutils/md5.h>
56 #include <mailutils/io.h>
56 57
57 #include <folder0.h> 58 #include <folder0.h>
58 #include <mailbox0.h> 59 #include <mailbox0.h>
...@@ -147,7 +148,8 @@ static int fill_buffer (pop_data_t, char *, size_t); ...@@ -147,7 +148,8 @@ static int fill_buffer (pop_data_t, char *, size_t);
147 static int pop_sleep (int); 148 static int pop_sleep (int);
148 static int pop_readline (pop_data_t); 149 static int pop_readline (pop_data_t);
149 static int pop_read_ack (pop_data_t); 150 static int pop_read_ack (pop_data_t);
150 static int pop_writeline (pop_data_t, const char *, ...); 151 static int pop_writeline (pop_data_t, const char *, ...)
152 MU_PRINTFLIKE(2,3);
151 static int pop_write (pop_data_t); 153 static int pop_write (pop_data_t);
152 static int pop_get_user (mu_authority_t); 154 static int pop_get_user (mu_authority_t);
153 static int pop_get_passwd (mu_authority_t); 155 static int pop_get_passwd (mu_authority_t);
...@@ -1295,9 +1297,9 @@ pop_expunge (mu_mailbox_t mbox) ...@@ -1295,9 +1297,9 @@ pop_expunge (mu_mailbox_t mbox)
1295 switch (mpd->state) 1297 switch (mpd->state)
1296 { 1298 {
1297 case POP_NO_STATE: 1299 case POP_NO_STATE:
1298 status = pop_writeline (mpd, "DELE %s\r\n", 1300 status = pop_writeline (mpd, "DELE %lu\r\n",
1299 mu_umaxtostr (0, 1301 (unsigned long)
1300 mpd->pmessages[i]->num)); 1302 mpd->pmessages[i]->num);
1301 CHECK_ERROR (mpd, status); 1303 CHECK_ERROR (mpd, status);
1302 MU_DEBUG (mbox->debug, MU_DEBUG_PROT, mpd->buffer); 1304 MU_DEBUG (mbox->debug, MU_DEBUG_PROT, mpd->buffer);
1303 mpd->state = POP_DELE; 1305 mpd->state = POP_DELE;
...@@ -1391,7 +1393,7 @@ pop_message_size (mu_message_t msg, size_t *psize) ...@@ -1391,7 +1393,7 @@ pop_message_size (mu_message_t msg, size_t *psize)
1391 switch (mpd->state) 1393 switch (mpd->state)
1392 { 1394 {
1393 case POP_NO_STATE: 1395 case POP_NO_STATE:
1394 status = pop_writeline (mpd, "LIST %s\r\n", mu_umaxtostr (0, mpm->num)); 1396 status = pop_writeline (mpd, "LIST %lu\r\n", (unsigned long) mpm->num);
1395 CHECK_ERROR (mpd, status); 1397 CHECK_ERROR (mpd, status);
1396 MU_DEBUG (mpd->mbox->debug, MU_DEBUG_PROT, mpd->buffer); 1398 MU_DEBUG (mpd->mbox->debug, MU_DEBUG_PROT, mpd->buffer);
1397 mpd->state = POP_LIST; 1399 mpd->state = POP_LIST;
...@@ -1610,7 +1612,7 @@ pop_uidl (mu_message_t msg, char *buffer, size_t buflen, size_t *pnwriten) ...@@ -1610,7 +1612,7 @@ pop_uidl (mu_message_t msg, char *buffer, size_t buflen, size_t *pnwriten)
1610 switch (mpd->state) 1612 switch (mpd->state)
1611 { 1613 {
1612 case POP_NO_STATE: 1614 case POP_NO_STATE:
1613 status = pop_writeline (mpd, "UIDL %s\r\n", mu_umaxtostr (0, mpm->num)); 1615 status = pop_writeline (mpd, "UIDL %lu\r\n", (unsigned long) mpm->num);
1614 CHECK_ERROR (mpd, status); 1616 CHECK_ERROR (mpd, status);
1615 MU_DEBUG (mpd->mbox->debug, MU_DEBUG_PROT, mpd->buffer); 1617 MU_DEBUG (mpd->mbox->debug, MU_DEBUG_PROT, mpd->buffer);
1616 mpd->state = POP_UIDL; 1618 mpd->state = POP_UIDL;
...@@ -1705,8 +1707,8 @@ pop_top (mu_header_t header, char *buffer, size_t buflen, ...@@ -1705,8 +1707,8 @@ pop_top (mu_header_t header, char *buffer, size_t buflen,
1705 case POP_NO_STATE: 1707 case POP_NO_STATE:
1706 if (mpd->capa & CAPA_TOP) 1708 if (mpd->capa & CAPA_TOP)
1707 { 1709 {
1708 status = pop_writeline (mpd, "TOP %s 0\r\n", 1710 status = pop_writeline (mpd, "TOP %lu 0\r\n",
1709 mu_umaxtostr (0, mpm->num)); 1711 (unsigned long) mpm->num);
1710 CHECK_ERROR (mpd, status); 1712 CHECK_ERROR (mpd, status);
1711 MU_DEBUG (mpd->mbox->debug, MU_DEBUG_PROT, mpd->buffer); 1713 MU_DEBUG (mpd->mbox->debug, MU_DEBUG_PROT, mpd->buffer);
1712 mpd->state = POP_TOP; 1714 mpd->state = POP_TOP;
...@@ -1931,8 +1933,8 @@ pop_retr (pop_message_t mpm, char *buffer, size_t buflen, ...@@ -1931,8 +1933,8 @@ pop_retr (pop_message_t mpm, char *buffer, size_t buflen,
1931 { 1933 {
1932 case POP_NO_STATE: 1934 case POP_NO_STATE:
1933 mpm->body_lines = mpm->body_size = 0; 1935 mpm->body_lines = mpm->body_size = 0;
1934 status = pop_writeline (mpd, "RETR %s\r\n", 1936 status = pop_writeline (mpd, "RETR %lu\r\n",
1935 mu_umaxtostr (0, mpm->num)); 1937 (unsigned long) mpm->num);
1936 MU_DEBUG (mpd->mbox->debug, MU_DEBUG_PROT, mpd->buffer); 1938 MU_DEBUG (mpd->mbox->debug, MU_DEBUG_PROT, mpd->buffer);
1937 CHECK_ERROR (mpd, status); 1939 CHECK_ERROR (mpd, status);
1938 mpd->state = POP_RETR; 1940 mpd->state = POP_RETR;
......
1 ## Process this file with GNU Automake to create Makefile.in 1 ## Process this file with GNU Automake to create Makefile.in
2 2
3 ## Copyright (C) 2000, 2001, 2002, 2004, 2005, 2006, 2007, 2008 3 ## Copyright (C) 2000, 2001, 2002, 2004, 2005, 2006, 2007, 2008,
4 ## Free Software Foundation, Inc. 4 ## 2009 Free Software Foundation, Inc.
5 ## 5 ##
6 ## GNU Mailutils is free software; you can redistribute it and/or 6 ## GNU Mailutils is free software; you can redistribute it and/or
7 ## modify it under the terms of the GNU General Public License as 7 ## modify it under the terms of the GNU General Public License as
...@@ -41,9 +41,7 @@ EXTRA_DIST = \ ...@@ -41,9 +41,7 @@ EXTRA_DIST = \
41 fgetpwent.c\ 41 fgetpwent.c\
42 cfg_lexer.l\ 42 cfg_lexer.l\
43 cfg_parser.y\ 43 cfg_parser.y\
44 cfg_parser.h\ 44 cfg_parser.h
45 inttostr.c\
46 inttostr.h
47 45
48 libmailutils_la_SOURCES = \ 46 libmailutils_la_SOURCES = \
49 acl.c\ 47 acl.c\
...@@ -51,6 +49,8 @@ libmailutils_la_SOURCES = \ ...@@ -51,6 +49,8 @@ libmailutils_la_SOURCES = \
51 alloc.c\ 49 alloc.c\
52 amd.c\ 50 amd.c\
53 argcv.c\ 51 argcv.c\
52 asnprintf.c\
53 asprintf.c\
54 assoc.c\ 54 assoc.c\
55 attachment.c\ 55 attachment.c\
56 attribute.c\ 56 attribute.c\
...@@ -97,8 +97,6 @@ libmailutils_la_SOURCES = \ ...@@ -97,8 +97,6 @@ libmailutils_la_SOURCES = \
97 monitor.c\ 97 monitor.c\
98 msrv.c\ 98 msrv.c\
99 mu_auth.c\ 99 mu_auth.c\
100 mu_umaxtostr.h\
101 mu_umaxtostr.c\
102 munre.c\ 100 munre.c\
103 mutil.c\ 101 mutil.c\
104 muerror.c\ 102 muerror.c\
...@@ -124,9 +122,9 @@ libmailutils_la_SOURCES = \ ...@@ -124,9 +122,9 @@ libmailutils_la_SOURCES = \
124 tcp.c\ 122 tcp.c\
125 url.c\ 123 url.c\
126 vartab.c\ 124 vartab.c\
125 vasnprintf.c\
127 version.c\ 126 version.c\
128 wicket.c\ 127 wicket.c
129 imaxtostr.c offtostr.c umaxtostr.c intprops.h
130 128
131 BUILT_SOURCES = parsedate.c muerrno.c cfg_parser.c cfg_parser.h cfg_lexer.c 129 BUILT_SOURCES = parsedate.c muerrno.c cfg_parser.c cfg_parser.h cfg_lexer.c
132 MOSTLYCLEANFILES= 130 MOSTLYCLEANFILES=
......
1 /* GNU Mailutils -- a suite of utilities for electronic mail 1 /* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 2007, 2008 Free Software Foundation, Inc. 2 Copyright (C) 2007, 2008, 2009 Free Software Foundation, Inc.
3 3
4 This library is free software; you can redistribute it and/or 4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public 5 modify it under the terms of the GNU Lesser General Public
...@@ -36,7 +36,7 @@ ...@@ -36,7 +36,7 @@
36 #include <mailutils/errno.h> 36 #include <mailutils/errno.h>
37 #include <mailutils/kwd.h> 37 #include <mailutils/kwd.h>
38 #include <mailutils/vartab.h> 38 #include <mailutils/vartab.h>
39 #include <mu_umaxtostr.h> 39 #include <mailutils/io.h>
40 40
41 struct _mu_acl_entry 41 struct _mu_acl_entry
42 { 42 {
...@@ -368,7 +368,7 @@ mu_sockaddr_to_str (const struct sockaddr *sa, int salen, ...@@ -368,7 +368,7 @@ mu_sockaddr_to_str (const struct sockaddr *sa, int salen,
368 char *bufptr, size_t buflen, 368 char *bufptr, size_t buflen,
369 size_t *plen) 369 size_t *plen)
370 { 370 {
371 char buf[UINTMAX_STRSIZE_BOUND]; /* FIXME: too much */ 371 char *nbuf;
372 size_t len = 0; 372 size_t len = 0;
373 switch (sa->sa_family) 373 switch (sa->sa_family)
374 { 374 {
...@@ -377,8 +377,11 @@ mu_sockaddr_to_str (const struct sockaddr *sa, int salen, ...@@ -377,8 +377,11 @@ mu_sockaddr_to_str (const struct sockaddr *sa, int salen,
377 struct sockaddr_in s_in = *(struct sockaddr_in *)sa; 377 struct sockaddr_in s_in = *(struct sockaddr_in *)sa;
378 len += mu_stpcpy (&bufptr, &buflen, inet_ntoa (s_in.sin_addr)); 378 len += mu_stpcpy (&bufptr, &buflen, inet_ntoa (s_in.sin_addr));
379 len += mu_stpcpy (&bufptr, &buflen, ":"); 379 len += mu_stpcpy (&bufptr, &buflen, ":");
380 len += mu_stpcpy (&bufptr, &buflen, umaxtostr (ntohs (s_in.sin_port), 380 if (mu_asprintf (&nbuf, "%hu", ntohs (s_in.sin_port)) == 0)
381 buf)); 381 {
382 len += mu_stpcpy (&bufptr, &buflen, nbuf);
383 free (nbuf);
384 }
382 break; 385 break;
383 } 386 }
384 387
...@@ -396,8 +399,12 @@ mu_sockaddr_to_str (const struct sockaddr *sa, int salen, ...@@ -396,8 +399,12 @@ mu_sockaddr_to_str (const struct sockaddr *sa, int salen,
396 } 399 }
397 400
398 default: 401 default:
399 len += mu_stpcpy (&bufptr, &buflen, "{Unsupported family: "); 402 len += mu_stpcpy (&bufptr, &buflen, "{Unsupported family");
400 len += mu_stpcpy (&bufptr, &buflen, umaxtostr (sa->sa_family, buf)); 403 if (mu_asprintf (&nbuf, ": %d", sa->sa_family) == 0)
404 {
405 len += mu_stpcpy (&bufptr, &buflen, nbuf);
406 free (nbuf);
407 }
401 len += mu_stpcpy (&bufptr, &buflen, "}"); 408 len += mu_stpcpy (&bufptr, &buflen, "}");
402 } 409 }
403 if (plen) 410 if (plen)
...@@ -500,10 +507,8 @@ static int ...@@ -500,10 +507,8 @@ static int
500 _expand_aclno (const char *name, void *data, char **p) 507 _expand_aclno (const char *name, void *data, char **p)
501 { 508 {
502 struct run_closure *rp = data; 509 struct run_closure *rp = data;
503 char buf[UINTMAX_STRSIZE_BOUND];
504 /*FIXME: memory leak*/ 510 /*FIXME: memory leak*/
505 *p = strdup (umaxtostr (rp->idx, buf)); 511 return mu_asprintf (p, "%u", rp->idx);
506 return 0;
507 } 512 }
508 513
509 #if defined (HAVE_SYSCONF) && defined (_SC_OPEN_MAX) 514 #if defined (HAVE_SYSCONF) && defined (_SC_OPEN_MAX)
...@@ -530,14 +535,13 @@ expand_arg (const char *cmdline, struct run_closure *rp, char **s) ...@@ -530,14 +535,13 @@ expand_arg (const char *cmdline, struct run_closure *rp, char **s)
530 { 535 {
531 struct sockaddr_in *s_in = (struct sockaddr_in *)rp->sa; 536 struct sockaddr_in *s_in = (struct sockaddr_in *)rp->sa;
532 struct in_addr addr = s_in->sin_addr; 537 struct in_addr addr = s_in->sin_addr;
533 char buf[UINTMAX_STRSIZE_BOUND]; 538 char *p;
534 unsigned n;
535 539
536 mu_vartab_define (vtab, "family", "AF_INET", 1); 540 mu_vartab_define (vtab, "family", "AF_INET", 1);
537 addr.s_addr = htonl (addr.s_addr); 541 addr.s_addr = htonl (addr.s_addr);
538 mu_vartab_define (vtab, "address", inet_ntoa (addr), 0); 542 mu_vartab_define (vtab, "address", inet_ntoa (addr), 0);
539 n = ntohs (s_in->sin_port); 543 if (mu_asprintf (&p, "%hu", ntohs (s_in->sin_port)) == 0)
540 mu_vartab_define (vtab, "port", umaxtostr (n, buf), 0); 544 mu_vartab_define (vtab, "port", p, 0);
541 } 545 }
542 break; 546 break;
543 547
...@@ -768,7 +772,7 @@ mu_acl_check_fd (mu_acl_t acl, int fd, mu_acl_result_t *pres) ...@@ -768,7 +772,7 @@ mu_acl_check_fd (mu_acl_t acl, int fd, mu_acl_result_t *pres)
768 { 772 {
769 MU_DEBUG1 (acl->debug, MU_DEBUG_ERROR, 773 MU_DEBUG1 (acl->debug, MU_DEBUG_ERROR,
770 "Cannot obtain IP address of client: %s", 774 "Cannot obtain IP address of client: %s",
771 strerror (errno)); 775 mu_strerror (errno));
772 return MU_ERR_FAILURE; 776 return MU_ERR_FAILURE;
773 } 777 }
774 778
......
1 /* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 2009 Free Software Foundation, Inc.
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 3 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General
15 Public License along with this library; if not, write to the
16 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301 USA */
18
19 #if HAVE_CONFIG_H
20 # include <config.h>
21 #endif
22
23 #include <stdlib.h>
24 #include <stdarg.h>
25 #include <stdio.h>
26
27 #include <mailutils/io.h>
28
29 int
30 mu_asnprintf (char **pbuf, size_t *psize, const char *fmt, ...)
31 {
32 int rc;
33 va_list ap;
34
35 va_start (ap, fmt);
36 rc = mu_vasnprintf (pbuf, psize, fmt, ap);
37 va_end (ap);
38 return rc;
39 }
40
1 /* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 2009 Free Software Foundation, Inc.
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 3 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General
15 Public License along with this library; if not, write to the
16 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301 USA */
18
19 #if HAVE_CONFIG_H
20 # include <config.h>
21 #endif
22
23 #include <stdlib.h>
24 #include <stdarg.h>
25 #include <stdio.h>
26
27 #include <mailutils/io.h>
28
29 int
30 mu_asprintf (char **pbuf, const char *fmt, ...)
31 {
32 va_list ap;
33 size_t size;
34 int rc;
35
36 va_start (ap, fmt);
37 *pbuf = NULL;
38 size = 0;
39 rc = mu_vasnprintf (pbuf, &size, fmt, ap);
40 va_end (ap);
41 return rc;
42 }
1 /* GNU Mailutils -- a suite of utilities for electronic mail 1 /* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 2004, 2005, 2007, 2008 Free Software Foundation, Inc. 2 Copyright (C) 2004, 2005, 2007, 2008, 2009 Free Software Foundation, Inc.
3 3
4 This library is free software; you can redistribute it and/or 4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public 5 modify it under the terms of the GNU Lesser General Public
...@@ -32,7 +32,6 @@ ...@@ -32,7 +32,6 @@
32 #include <mailutils/errno.h> 32 #include <mailutils/errno.h>
33 #include <mailutils/error.h> 33 #include <mailutils/error.h>
34 #include <mailutils/nls.h> 34 #include <mailutils/nls.h>
35 #include <mu_umaxtostr.h>
36 35
37 static char *pidfile; 36 static char *pidfile;
38 static pid_t current_pid; 37 static pid_t current_pid;
...@@ -80,7 +79,6 @@ int ...@@ -80,7 +79,6 @@ int
80 mu_daemon_create_pidfile (const char *filename) 79 mu_daemon_create_pidfile (const char *filename)
81 { 80 {
82 char *p; 81 char *p;
83 const char *pid_string;
84 int fd; 82 int fd;
85 uid_t uid = 0; 83 uid_t uid = 0;
86 int rc; 84 int rc;
...@@ -122,11 +120,20 @@ mu_daemon_create_pidfile (const char *filename) ...@@ -122,11 +120,20 @@ mu_daemon_create_pidfile (const char *filename)
122 120
123 if ((fd = open (pidfile, O_WRONLY | O_CREAT | O_TRUNC | O_EXCL, 0644)) != -1) 121 if ((fd = open (pidfile, O_WRONLY | O_CREAT | O_TRUNC | O_EXCL, 0644)) != -1)
124 { 122 {
125 pid_string = mu_umaxtostr (0, current_pid); 123 FILE *fp = fdopen (fd, "w");
126 write (fd, pid_string, strlen (pid_string)); 124 if (!fp)
125 {
126 rc = errno;
127 free (pidfile);
127 close (fd); 128 close (fd);
129 }
130 else
131 {
132 fprintf (fp, "%lu", (unsigned long) current_pid);
133 fclose (fp);
128 atexit (mu_daemon_remove_pidfile); 134 atexit (mu_daemon_remove_pidfile);
129 } 135 }
136 }
130 else 137 else
131 { 138 {
132 rc = errno; 139 rc = errno;
......
1 #define inttostr imaxtostr
2 #define inttype intmax_t
3 #include "inttostr.c"
1 /* intprops.h -- properties of integer types
2
3 Copyright (C) 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2, or (at your option)
8 any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software Foundation,
17 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
18
19 /* Written by Paul Eggert. */
20
21 #include <limits.h>
22
23 /* The extra casts in the following macros work around compiler bugs,
24 e.g., in Cray C 5.0.3.0. */
25
26 /* True if the arithmetic type T is an integer type. bool counts as
27 an integer. */
28 #define TYPE_IS_INTEGER(t) ((t) 1.5 == 1)
29
30 /* True if negative values of the signed integer type T use two's
31 complement, ones' complement, or signed magnitude representation,
32 respectively. Much GNU code assumes two's complement, but some
33 people like to be portable to all possible C hosts. */
34 #define TYPE_TWOS_COMPLEMENT(t) ((t) ~ (t) 0 == (t) -1)
35 #define TYPE_ONES_COMPLEMENT(t) ((t) ~ (t) 0 == 0)
36 #define TYPE_SIGNED_MAGNITUDE(t) ((t) ~ (t) 0 < (t) -1)
37
38 /* True if the arithmetic type T is signed. */
39 #define TYPE_SIGNED(t) (! ((t) 0 < (t) -1))
40
41 /* The maximum and minimum values for the integer type T. These
42 macros have undefined behavior if T is signed and has padding bits.
43 If this is a problem for you, please let us know how to fix it for
44 your host. */
45 #define TYPE_MINIMUM(t) \
46 ((t) (! TYPE_SIGNED (t) \
47 ? (t) 0 \
48 : TYPE_SIGNED_MAGNITUDE (t) \
49 ? ~ (t) 0 \
50 : ~ (t) 0 << (sizeof (t) * CHAR_BIT - 1)))
51 #define TYPE_MAXIMUM(t) \
52 ((t) (! TYPE_SIGNED (t) \
53 ? (t) -1 \
54 : ~ (~ (t) 0 << (sizeof (t) * CHAR_BIT - 1))))
55
56 /* Return zero if T can be determined to be an unsigned type.
57 Otherwise, return 1.
58 When compiling with GCC, INT_STRLEN_BOUND uses this macro to obtain a
59 tighter bound. Otherwise, it overestimates the true bound by one byte
60 when applied to unsigned types of size 2, 4, 16, ... bytes.
61 The symbol signed_type_or_expr__ is private to this header file. */
62 #if __GNUC__ >= 2
63 # define signed_type_or_expr__(t) TYPE_SIGNED (__typeof__ (t))
64 #else
65 # define signed_type_or_expr__(t) 1
66 #endif
67
68 /* Bound on length of the string representing an integer type or expression T.
69 Subtract 1 for the sign bit if T is signed; log10 (2.0) < 146/485;
70 add 1 for integer division truncation; add 1 more for a minus sign
71 if needed. */
72 #define INT_STRLEN_BOUND(t) \
73 ((sizeof (t) * CHAR_BIT - signed_type_or_expr__ (t)) * 146 / 485 \
74 + signed_type_or_expr__ (t) + 1)
75
76 /* Bound on buffer size needed to represent an integer type or expression T,
77 including the terminating null. */
78 #define INT_BUFSIZE_BOUND(t) (INT_STRLEN_BOUND (t) + 1)
1 /* inttostr.c -- convert integers to printable strings
2
3 Copyright (C) 2001 Free Software Foundation, Inc.
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2, or (at your option)
8 any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software Foundation,
17 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
18
19 /* Written by Paul Eggert */
20
21 #ifdef HAVE_CONFIG_H
22 # include <config.h>
23 #endif
24 #include "inttostr.h"
25
26 /* Convert I to a printable string in BUF, which must be at least
27 INT_BUFSIZE_BOUND (INTTYPE) bytes long. Return the address of the
28 printable string, which need not start at BUF. */
29
30 char *
31 inttostr (inttype i, char *buf)
32 {
33 char *p = buf + INT_STRLEN_BOUND (inttype);
34 *p = 0;
35
36 if (i < 0)
37 {
38 do
39 *--p = '0' - i % 10;
40 while ((i /= 10) != 0);
41
42 *--p = '-';
43 }
44 else
45 {
46 do
47 *--p = '0' + i % 10;
48 while ((i /= 10) != 0);
49 }
50
51 return p;
52 }
1 /* inttostr.h -- convert integers to printable strings
2
3 Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006 Free Software
4 Foundation, Inc.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software Foundation,
18 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
19
20 /* Written by Paul Eggert */
21
22 #include <stdint.h>
23 #include <sys/types.h>
24
25 #include "intprops.h"
26
27 char *offtostr (off_t, char *);
28 char *imaxtostr (intmax_t, char *);
29 char *umaxtostr (uintmax_t, char *);
1 /* GNU Mailutils -- a suite of utilities for electronic mail 1 /* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 1999, 2000, 2001, 2004, 2005, 2006, 2 Copyright (C) 1999, 2000, 2001, 2004, 2005, 2006,
3 2007 Free Software Foundation, Inc. 3 2007, 2009 Free Software Foundation, Inc.
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public 6 modify it under the terms of the GNU Lesser General Public
...@@ -47,7 +47,7 @@ ...@@ -47,7 +47,7 @@
47 #include <mailutils/argcv.h> 47 #include <mailutils/argcv.h>
48 #include <mailutils/mutil.h> 48 #include <mailutils/mutil.h>
49 #include <mailutils/mime.h> 49 #include <mailutils/mime.h>
50 #include <mu_umaxtostr.h> 50 #include <mailutils/io.h>
51 51
52 #include <mailer0.h> 52 #include <mailer0.h>
53 53
...@@ -404,19 +404,19 @@ create_part (mu_mime_t mime, mu_stream_t istr, ...@@ -404,19 +404,19 @@ create_part (mu_mime_t mime, mu_stream_t istr,
404 mu_body_t body; 404 mu_body_t body;
405 mu_stream_t ostr; 405 mu_stream_t ostr;
406 char buffer[512], *str; 406 char buffer[512], *str;
407 const char *nstr, *npartstr; 407 size_t slen;
408 408
409 mu_message_create (&newmsg, NULL); 409 mu_message_create (&newmsg, NULL);
410 mu_message_get_header (newmsg, &newhdr); 410 mu_message_get_header (newmsg, &newhdr);
411 411
412 nstr = mu_umaxtostr (0, n); 412 str = NULL;
413 npartstr = mu_umaxtostr (1, nparts); 413 slen = 0;
414 asprintf (&str, 414 mu_asnprintf (&str, &slen,
415 "message/partial; id=\"%s\"; number=%s; total=%s", 415 "message/partial; id=\"%s\"; number=%lu; total=%lu",
416 msgid, nstr, npartstr); 416 msgid, (unsigned long)n, (unsigned long)nparts);
417 mu_header_append (newhdr, MU_HEADER_CONTENT_TYPE, str); 417 mu_header_append (newhdr, MU_HEADER_CONTENT_TYPE, str);
418 free (str); 418 mu_asnprintf (&str, &slen, "part %lu of %lu",
419 asprintf (&str, "part %s of %s", nstr, npartstr); 419 (unsigned long)n, (unsigned long)nparts);
420 mu_header_append (newhdr, MU_HEADER_CONTENT_DESCRIPTION, str); 420 mu_header_append (newhdr, MU_HEADER_CONTENT_DESCRIPTION, str);
421 free (str); 421 free (str);
422 422
......
1 /* GNU Mailutils -- a suite of utilities for electronic mail 1 /* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 1999, 2000, 2001, 2002, 2004, 2 Copyright (C) 1999, 2000, 2001, 2002, 2004,
3 2005, 2006, 2007 Free Software Foundation, Inc. 3 2005, 2006, 2007, 2009 Free Software Foundation, Inc.
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public 6 modify it under the terms of the GNU Lesser General Public
...@@ -50,7 +50,7 @@ ...@@ -50,7 +50,7 @@
50 #include <mailutils/mu_auth.h> 50 #include <mailutils/mu_auth.h>
51 #include <mailutils/nls.h> 51 #include <mailutils/nls.h>
52 #include <mailutils/md5.h> 52 #include <mailutils/md5.h>
53 #include <mu_umaxtostr.h> 53 #include <mailutils/io.h>
54 54
55 #define MESSAGE_MODIFIED 0x10000; 55 #define MESSAGE_MODIFIED 0x10000;
56 56
...@@ -638,8 +638,8 @@ mu_message_get_uidl (mu_message_t msg, char *buffer, size_t buflen, size_t *pwri ...@@ -638,8 +638,8 @@ mu_message_get_uidl (mu_message_t msg, char *buffer, size_t buflen, size_t *pwri
638 sprintf (tmp, "%02x", md5digest[n]); 638 sprintf (tmp, "%02x", md5digest[n]);
639 *tmp = '\0'; 639 *tmp = '\0';
640 /* POP3 rfc says that an UID should not be longer than 70. */ 640 /* POP3 rfc says that an UID should not be longer than 70. */
641 snprintf (buf + 32, 70, ".%lu.%s", (unsigned long)time (NULL), 641 snprintf (buf + 32, 70, ".%lu.%lu", (unsigned long)time (NULL),
642 mu_umaxtostr (0, uid)); 642 (unsigned long) uid);
643 643
644 mu_header_set_value (header, "X-UIDL", buf, 1); 644 mu_header_set_value (header, "X-UIDL", buf, 1);
645 buflen--; /* leave space for the NULL. */ 645 buflen--; /* leave space for the NULL. */
......
1 /* GNU Mailutils -- a suite of utilities for electronic mail 1 /* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 1999, 2000, 2001, 2002, 2003, 2 Copyright (C) 1999, 2000, 2001, 2002, 2003,
3 2005, 2006, 2007 Free Software Foundation, Inc. 3 2005, 2006, 2007, 2009 Free Software Foundation, Inc.
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public 6 modify it under the terms of the GNU Lesser General Public
...@@ -60,6 +60,7 @@ ...@@ -60,6 +60,7 @@
60 #include <mailutils/filter.h> 60 #include <mailutils/filter.h>
61 #include <mailutils/sql.h> 61 #include <mailutils/sql.h>
62 #include <mailutils/url.h> 62 #include <mailutils/url.h>
63 #include <mailutils/io.h>
63 64
64 #include <registrar0.h> 65 #include <registrar0.h>
65 66
...@@ -611,7 +612,7 @@ mu_tempfile (const char *tmpdir, char **namep) ...@@ -611,7 +612,7 @@ mu_tempfile (const char *tmpdir, char **namep)
611 612
612 if (fd == -1) 613 if (fd == -1)
613 { 614 {
614 mu_error (_("Cannot open temporary file: %s"), strerror (errno)); 615 mu_error (_("Cannot open temporary file: %s"), mu_strerror (errno));
615 free (filename); 616 free (filename);
616 return -1; 617 return -1;
617 } 618 }
...@@ -1031,14 +1032,14 @@ mu_rfc2822_msg_id (int subpart, char **pval) ...@@ -1031,14 +1032,14 @@ mu_rfc2822_msg_id (int subpart, char **pval)
1031 { 1032 {
1032 struct timeval tv; 1033 struct timeval tv;
1033 gettimeofday (&tv, NULL); 1034 gettimeofday (&tv, NULL);
1034 asprintf (&p, "<%s.%lu.%d@%s>", 1035 mu_asprintf (&p, "<%s.%lu.%d@%s>",
1035 date, 1036 date,
1036 (unsigned long) getpid (), 1037 (unsigned long) getpid (),
1037 subpart, 1038 subpart,
1038 host); 1039 host);
1039 } 1040 }
1040 else 1041 else
1041 asprintf (&p, "<%s.%lu@%s>", date, (unsigned long) getpid (), host); 1042 mu_asprintf (&p, "<%s.%lu@%s>", date, (unsigned long) getpid (), host);
1042 free (host); 1043 free (host);
1043 *pval = p; 1044 *pval = p;
1044 return 0; 1045 return 0;
......
1 #define inttostr offtostr
2 #define inttype off_t
3 #include "inttostr.c"
...@@ -40,6 +40,7 @@ ...@@ -40,6 +40,7 @@
40 40
41 #include <mailutils/property.h> 41 #include <mailutils/property.h>
42 #include <mailutils/errno.h> 42 #include <mailutils/errno.h>
43 #include <mailutils/io.h>
43 #include <stream0.h> 44 #include <stream0.h>
44 45
45 static int refill (mu_stream_t, mu_off_t); 46 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, ...@@ -493,43 +494,16 @@ mu_stream_write (mu_stream_t os, const char *buf, size_t count,
493 int 494 int
494 mu_stream_vprintf (mu_stream_t os, mu_off_t *poff, const char *fmt, va_list ap) 495 mu_stream_vprintf (mu_stream_t os, mu_off_t *poff, const char *fmt, va_list ap)
495 { 496 {
496 char *buf, *p; 497 char *buf = NULL, *p;
497 size_t buflen = 512; 498 size_t buflen = 0;
498 size_t n; 499 size_t n;
499 int done = 0;
500 int rc; 500 int rc;
501 501
502 buf = calloc (1, buflen); 502 rc = mu_vasnprintf (&buf, &buflen, fmt, ap);
503 if (buf == NULL) 503 if (rc)
504 return ENOMEM; 504 return rc;
505
506 do
507 {
508 n = vsnprintf (buf, buflen, fmt, ap);
509 if (n < 0 || n >= buflen || !memchr (buf, '\0', n + 1))
510 {
511 char *newbuf;
512 size_t newlen = buflen * 2;
513 if (newlen < buflen)
514 {
515 free (buf);
516 return ENOMEM;
517 }
518 newbuf = realloc (buf, newlen);
519 if (newbuf == NULL)
520 {
521 free (buf);
522 return ENOMEM;
523 }
524 buflen = newlen;
525 buf = newbuf;
526 }
527 else
528 done = 1;
529 }
530 while (!done);
531
532 p = buf; 505 p = buf;
506 n = strlen (buf);
533 do 507 do
534 { 508 {
535 size_t wrs; 509 size_t wrs;
......
1 #define inttostr umaxtostr
2 #define inttype uintmax_t
3 #include "inttostr.c"
1 /* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 2009 Free Software Foundation, Inc.
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 3 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General
15 Public License along with this library; if not, write to the
16 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301 USA */
18
19 #if HAVE_CONFIG_H
20 # include <config.h>
21 #endif
22
23 #include <stdlib.h>
24 #include <stdarg.h>
25 #include <stdio.h>
26 #include <errno.h>
27 #include <string.h>
28
29 #include <mailutils/io.h>
30
31 int
32 mu_vasnprintf (char **pbuf, size_t *psize, const char *fmt, va_list ap)
33 {
34 char *buf = *pbuf;
35 size_t buflen = *psize;
36 int rc = 0;
37
38 if (!buf)
39 {
40 if (buflen == 0)
41 buflen = 512; /* Initial allocation */
42
43 buf = calloc (1, buflen);
44 if (buf == NULL)
45 return ENOMEM;
46 }
47
48 for (;;)
49 {
50 ssize_t n = vsnprintf (buf, buflen, fmt, ap);
51 if (n < 0 || n >= buflen || !memchr (buf, '\0', n + 1))
52 {
53 char *newbuf;
54 size_t newlen = buflen * 2;
55 if (newlen < buflen)
56 {
57 rc = ENOMEM;
58 break;
59 }
60 newbuf = realloc (buf, newlen);
61 if (newbuf == NULL)
62 {
63 rc = ENOMEM;
64 break;
65 }
66 buflen = newlen;
67 buf = newbuf;
68 }
69 else
70 break;
71 }
72
73 if (rc)
74 {
75 if (!*pbuf)
76 {
77 /* We made first allocation, now free it */
78 free (buf);
79 buf = NULL;
80 buflen = 0;
81 }
82 }
83
84 *pbuf = buf;
85 *psize = buflen;
86 return rc;
87 }