rfc2045mkboundary.c
上传用户:s81996212
上传日期:2007-01-04
资源大小:722k
文件大小:1k
源码类别:

WEB邮件程序

开发平台:

C/C++

  1. /*
  2. ** Copyright 1998 - 1999 Double Precision, Inc.  See COPYING for
  3. ** distribution information.
  4. */
  5. #if HAVE_CONFIG_H
  6. #include "config.h"
  7. #endif
  8. #include "rfc2045.h"
  9. #if HAVE_UNISTD_H
  10. #include <unistd.h>
  11. #endif
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14. #include <time.h>
  15. #include "numlib/numlib.h"
  16. /* $Id: rfc2045mkboundary.c,v 1.5 1999/12/06 13:29:02 mrsam Exp $ */
  17. #if HAS_GETHOSTNAME
  18. #else
  19. extern int gethostname(char *, size_t);
  20. #endif
  21. extern void rfc2045_enomem();
  22. char *rfc2045_mk_boundary(struct rfc2045 *s, int fd)
  23. {
  24. char hostnamebuf[256];
  25. pid_t mypid;
  26. char pidbuf[NUMBUFSIZE];
  27. time_t mytime;
  28. char timebuf[NUMBUFSIZE];
  29. int cnt=0;
  30. char cntbuf[60];
  31. char *p;
  32. int rc;
  33. hostnamebuf[sizeof(hostnamebuf)-1]=0;
  34. if (gethostname(hostnamebuf, sizeof(hostnamebuf)-1))
  35. hostnamebuf[0]=0;
  36. mypid=getpid();
  37. time(&mytime);
  38. str_pid_t(mypid, pidbuf);
  39. str_time_t(mytime, timebuf);
  40. for (;;)
  41. {
  42. sprintf(cntbuf, "%d", ++cnt);
  43. p=malloc(strlen(pidbuf)+strlen(timebuf)+
  44. strlen(cntbuf)+10);
  45. if (!p) rfc2045_enomem();
  46. sprintf(p, "=_%s-%s-%s", pidbuf, timebuf, cntbuf);
  47. if ((rc=rfc2045_try_boundary(s, fd, p)) == 0)
  48. break;
  49. free(p);
  50. if (rc < 0)
  51. return (NULL);
  52. }
  53. return (p);
  54. }