Commit 715e36a0 715e36a0fc50d2a2af1616d600009633b0be092a by Alain Magloire

* mailbox/misc.c: Removed, _cpystr() function move in mutil.c

	and rename to util_cpystr().
	* mailbox/include/misc.h: Removed.
	* mailbox/mutil.c (util_cpystr): New function, move
	the _cpystr() from misc.c and move here.
	* mailbox/Makefile.am: Removed misc.c in dependencies.
	* mailbox/include/Makefile.am: Removed misc.h in dependencies.
	* mailbox/address.c: Use util_cpystr() instead of _cpystr().
	Added <mailutils/mutil.h> prototype.
	* mailbox/auth.c: Likewised.
	* mailbox/url.c: Likewised.
	* mailbox/folder.c: Likewised
1 parent d3841c3b
......@@ -42,7 +42,6 @@ md5-rsa.c \
message.c \
memory_stream.c \
mime.c \
misc.c \
monitor.c \
mutil.c \
muerror.c \
......
......@@ -28,7 +28,7 @@
#include <errno.h>
#include <mailutils/parse822.h>
#include <misc.h>
#include <mailutils/mutil.h>
#include <address0.h>
/* Get email address from rfc822 address. */
......@@ -103,7 +103,7 @@ address_get_personal (address_t addr, size_t no, char *buf, size_t len,
{
if (j == no)
{
i = _cpystr (buf, addr->personal, len);
i = util_cpystr (buf, addr->personal, len);
status = 0;
break;
}
......@@ -125,7 +125,7 @@ address_get_comments (address_t addr, size_t no, char *buf, size_t len,
{
if (j == no)
{
i = _cpystr (buf, addr->comments, len);
i = util_cpystr (buf, addr->comments, len);
if (n)
*n = i;
status = 0;
......@@ -146,7 +146,7 @@ address_get_email (address_t addr, size_t no, char *buf, size_t len, size_t *n)
{
if (j == no)
{
i = _cpystr (buf, addr->email, len);
i = util_cpystr (buf, addr->email, len);
if (n)
*n = i;
status = 0;
......@@ -167,7 +167,7 @@ address_get_local_part (address_t addr, size_t no, char *buf, size_t len, size_t
{
if (j == no)
{
i = _cpystr (buf, addr->local_part, len);
i = util_cpystr (buf, addr->local_part, len);
if (n)
*n = i;
status = 0;
......@@ -188,7 +188,7 @@ address_get_domain (address_t addr, size_t no, char *buf, size_t len, size_t *n)
{
if (j == no)
{
i = _cpystr (buf, addr->domain, len);
i = util_cpystr (buf, addr->domain, len);
if (n)
*n = i;
status = 0;
......@@ -209,7 +209,7 @@ address_get_route (address_t addr, size_t no, char *buf, size_t len, size_t *n)
{
if (j == no)
{
i = _cpystr (buf, addr->route, len);
i = util_cpystr (buf, addr->route, len);
if (n)
*n = i;
status = 0;
......@@ -251,7 +251,7 @@ address_to_string (address_t addr, char *buf, size_t len, size_t *n)
return EINVAL;
if (buf)
*buf = '\0';
i = _cpystr (buf, addr->addr, len);
i = util_cpystr (buf, addr->addr, len);
if (n)
*n = i;
return 0;
......
/* GNU mailutils - a suite of utilities for electronic mail
Copyright (C) 1999, 2000 Free Software Foundation, Inc.
Copyright (C) 1999, 2000, 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 Library Public License as published by
......@@ -26,8 +26,8 @@
#include <termios.h>
#include <mailutils/mailbox.h>
#include <mailutils/mutil.h>
#include <auth0.h>
#include <misc.h>
static void
echo_off(struct termios *stored_settings)
......@@ -134,7 +134,7 @@ ticket_get_type (ticket_t ticket, char *type, size_t len, size_t *pwriten)
size_t n;
if (ticket == NULL || type == NULL)
return EINVAL;
n = _cpystr (type, ticket->type, len);
n = util_cpystr (type, ticket->type, len);
if (pwriten)
*pwriten = n;
return 0;
......
......@@ -28,7 +28,6 @@
#include <mailutils/list.h>
#include <mailutils/monitor.h>
#include <misc.h>
#include <folder0.h>
/* Internal folder list. */
......
......@@ -15,7 +15,6 @@ mailbox0.h \
mailer0.h \
message0.h \
mime0.h \
misc.h \
monitor0.h \
observer0.h \
property0.h \
......
/* GNU mailutils - a suite of utilities for electronic mail
Copyright (C) 1999, 2000, 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 Library 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 Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#ifndef _MISC_H
#define _MISC_H
#ifdef DMALLOC
# include <dmalloc.h>
#endif
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <sys/types.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifndef __P
# if __STDC__
# define __P(x) x
# else
# define __P(x)
# endif
#endif
extern size_t _cpystr __P ((char *dst, const char *src, size_t size));
#ifdef __cplusplus
}
#endif
#endif /* _MISC_H */
/* GNU mailutils - a suite of utilities for electronic mail
Copyright (C) 1999, 2000, 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 Library 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 Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <misc.h>
#include <string.h>
#include <stdio.h>
#include <sys/types.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
/* Smart strncpy that always add the null and returns the number of bytes
written. */
size_t
_cpystr (char *dst, const char *src, size_t size)
{
size_t len = src ? strlen (src) : 0 ;
if (dst == NULL || size == 0)
return len;
if (len >= size)
len = size - 1;
memcpy (dst, src, len);
dst[len] = '\0';
return len;
}
......@@ -66,10 +66,10 @@ size_t mu_hexstr2ul(unsigned long* ul, const char* hex, size_t len)
}
/* Convert struct tm into time_t, taking into account timezone offset.
mktime() always treats tm as if it was localtime, so convert it
to UTC, then adjust by the tm's real timezone, if it is known.
NOTE: 1. mktime converts localtime struct tm to *time_t in UTC*
2. adding mu_utc_offset() compensates for the localtime
corrections in mktime(), i.e. it yields the time_t in
......@@ -80,7 +80,7 @@ time_t
mu_tm2time (struct tm *timeptr, mu_timezone* tz)
{
int offset = tz ? tz->utc_offset : 0;
return mktime(timeptr) + mu_utc_offset() - offset;
}
......@@ -249,7 +249,7 @@ mu_get_homedir (void)
if (!homedir)
{
struct passwd *pwd;
pwd = getpwuid(getuid());
if (!pwd)
return NULL;
......@@ -264,7 +264,7 @@ char *
mu_tilde_expansion (const char *ref, const char *delim, const char *homedir)
{
char *p = strdup (ref);
if (*p == '~')
{
p++;
......@@ -309,3 +309,18 @@ mu_tilde_expansion (const char *ref, const char *delim, const char *homedir)
}
return p;
}
/* Smart strncpy that always add the null and returns the number of bytes
written. */
size_t
util_cpystr (char *dst, const char *src, size_t size)
{
size_t len = src ? strlen (src) : 0 ;
if (dst == NULL || size == 0)
return len;
if (len >= size)
len = size - 1;
memcpy (dst, src, len);
dst[len] = '\0';
return len;
}
......
......@@ -28,9 +28,7 @@
#endif
#include <mailutils/mutil.h>
#include <mailutils/registrar.h>
#include <misc.h>
#include <url0.h>
#ifndef EPARSE
......@@ -351,7 +349,7 @@ url_get_scheme (const url_t url, char *scheme, size_t len, size_t *n)
return EINVAL;
if (url->_get_scheme)
return url->_get_scheme (url, scheme, len, n);
i = _cpystr (scheme, url->scheme, len);
i = util_cpystr (scheme, url->scheme, len);
if (n)
*n = i;
return 0;
......@@ -365,7 +363,7 @@ url_get_user (const url_t url, char *user, size_t len, size_t *n)
return EINVAL;
if (url->_get_user)
return url->_get_user (url, user, len, n);
i = _cpystr (user, url->user, len);
i = util_cpystr (user, url->user, len);
if (n)
*n = i;
return 0;
......@@ -381,7 +379,7 @@ url_get_passwd (const url_t url, char *passwd, size_t len, size_t *n)
return EINVAL;
if (url->_get_passwd)
return url->_get_passwd (url, passwd, len, n);
i = _cpystr (passwd, url->passwd, len);
i = util_cpystr (passwd, url->passwd, len);
if (n)
*n = i;
return 0;
......@@ -395,7 +393,7 @@ url_get_auth (const url_t url, char *auth, size_t len, size_t *n)
return EINVAL;
if (url->_get_auth)
return url->_get_auth (url, auth, len, n);
i = _cpystr (auth, url->auth, len);
i = util_cpystr (auth, url->auth, len);
if (n)
*n = i;
return 0;
......@@ -409,7 +407,7 @@ url_get_host (const url_t url, char *host, size_t len, size_t *n)
return EINVAL;
if (url->_get_host)
return url->_get_host (url, host, len, n);
i = _cpystr (host, url->host, len);
i = util_cpystr (host, url->host, len);
if (n)
*n = i;
return 0;
......@@ -434,7 +432,7 @@ url_get_path (const url_t url, char *path, size_t len, size_t *n)
return EINVAL;
if (url->_get_path)
return url->_get_path (url, path, len, n);
i = _cpystr(path, url->path, len);
i = util_cpystr(path, url->path, len);
if (n)
*n = i;
return 0;
......@@ -448,7 +446,7 @@ url_get_query (const url_t url, char *query, size_t len, size_t *n)
return EINVAL;
if (url->_get_query)
return url->_get_query (url, query, len, n);
i = _cpystr(query, url->query, len);
i = util_cpystr(query, url->query, len);
if (n)
*n = i;
return 0;
......