char *rfc2045_mk_boundary(struct rfc2045 *s, int fd)
{
char	pidbuf[NUMBUFSIZE];
char	timebuf[NUMBUFSIZE];
char	cntbuf[60];
int	cnt=0;
time_t	mytime;
#ifndef __WINDOWS__
char	hostnamebuf[256];
pid_t	mypid;
#endif
char	*p;
int	rc;

	time(&mytime);

#ifdef __WINDOWS__
	sprintf(pidbuf, "%ld", GetCurrentThreadId());
	sprintf(timebuf, "%ld", (long)mytime);
#else
	hostnamebuf[sizeof(hostnamebuf)-1]=0;
	if (gethostname(hostnamebuf, sizeof(hostnamebuf)-1))
		hostnamebuf[0]=0;
	mypid=getpid();
	sprintf(pidbuf, "%d", (int)mypid);
	sprintf(timebuf, "%ld", mytime);
#endif

	for (;;)
	{
		sprintf(cntbuf, "%d", ++cnt);
		p=malloc(strlen(pidbuf)+strlen(timebuf)+
			strlen(cntbuf)+10);
		if (!p)
		{
			rfc2045_enomem();
			return (NULL);
		}

		sprintf(p, "=_%s-%s-%s", pidbuf, timebuf, cntbuf);
		if ((rc=rfc2045_try_boundary(s, fd, p)) == 0)
			break;
		free(p);
		if (rc < 0)
			return (NULL);
	}
	return (p);
}
Beispiel #2
0
char *rfc2045_mk_boundary(struct rfc2045 *s, int fd)
{
char	hostnamebuf[256];
pid_t	mypid;
char	pidbuf[NUMBUFSIZE];
time_t	mytime;
char	timebuf[NUMBUFSIZE];
static size_t	cnt=0;
char	cntbuf[NUMBUFSIZE];
char	*p;
int	rc;

	hostnamebuf[sizeof(hostnamebuf)-1]=0;
	if (gethostname(hostnamebuf, sizeof(hostnamebuf)-1))
		hostnamebuf[0]=0;
	mypid=getpid();
	time(&mytime);
	libmail_str_pid_t(mypid, pidbuf);
	libmail_str_time_t(mytime, timebuf);
	for (;;)
	{
		char tempbuf[NUMBUFSIZE];

		libmail_str_size_t(++cnt, tempbuf);
		sprintf(cntbuf, "%4s", tempbuf);
		for (p=cntbuf; *p == ' '; *p++ = '0')
			;
		p=malloc(strlen(hostnamebuf)+strlen(pidbuf)
			 +strlen(timebuf)+strlen(cntbuf)+11);
		if (!p)
		{
			rfc2045_enomem();
			return (NULL);
		}

		sprintf(p, "=_%s-%s-%s-%s", hostnamebuf,
			pidbuf, timebuf, cntbuf);
		if ((rc=rfc2045_try_boundary(s, fd, p)) == 0)
			break;
		free(p);
		if (rc < 0)
			return (NULL);
	}
	return (p);
}