patch-unix_uudeview_c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. $OpenBSD: patch-unix_uudeview_c,v 1.1.1.1 2014/11/20 21:14:54 jca Exp $
  2. - mkstemp(3) support
  3. - Debian patch
  4. --- unix/uudeview.c.orig Sun Apr 13 01:33:55 2003
  5. +++ unix/uudeview.c Mon Jan 27 21:44:47 2014
  6. @@ -443,18 +443,45 @@ proc_stdin (void)
  7. FILE *target;
  8. size_t bytes;
  9. int res;
  10. +#ifdef HAVE_MKSTEMP
  11. + int tmpfd;
  12. + const char *tmpprefix = "uuXXXXXXXXXX";
  13. + char *tmpdir = NULL;
  14. +#endif /* HAVE_MKSTEMP */
  15. if (stdinput) {
  16. fprintf (stderr, "proc_stdin: cannot process stdin twice\n");
  17. return 0;
  18. }
  19. +#ifdef HAVE_MKSTEMP
  20. + if ((getuid()==geteuid()) && (getgid()==getegid())) {
  21. + tmpdir=getenv("TMPDIR");
  22. + }
  23. +
  24. + if (!tmpdir) {
  25. + tmpdir = "/tmp";
  26. + }
  27. + stdfile = malloc(strlen(tmpdir)+strlen(tmpprefix)+2);
  28. +
  29. + if (!stdfile) {
  30. +#else
  31. if ((stdfile = tempnam (NULL, "uu")) == NULL) {
  32. +#endif
  33. fprintf (stderr, "proc_stdin: cannot get temporary file\n");
  34. return 0;
  35. }
  36. +#ifdef HAVE_MKSTEMP
  37. + strcpy(stdfile, tmpdir);
  38. + strcat(stdfile, "/");
  39. + strcat(stdfile, tmpprefix);
  40. +
  41. + if ((tmpfd = mkstemp(stdfile)) == -1 ||
  42. + (target = fdopen(tmpfd, "wb")) == NULL) {
  43. +#else
  44. if ((target = fopen (stdfile, "wb")) == NULL) {
  45. +#endif
  46. fprintf (stderr, "proc_stdin: cannot open temp file %s for writing: %s\n",
  47. stdfile, strerror (errno));
  48. _FP_free (stdfile);
  49. @@ -657,9 +684,6 @@ work_comline (int argc, char *argv[])
  50. else switch (*(argv[number] + 1)) {
  51. case '\0':
  52. interact = 0;
  53. - if (overwrite == 0) {
  54. - overwrite = 1;
  55. - }
  56. proc_stdin ();
  57. break;
  58. case 'a':
  59. @@ -699,10 +723,7 @@ work_comline (int argc, char *argv[])
  60. fprintf (stderr, "WARNING: cannot interact when reading from stdin\n");
  61. }
  62. else {
  63. - interact = (*argv[number] == '+') ? 1 : 0;
  64. - if (overwrite == 0 && *argv[number] == '-') {
  65. - overwrite = 1;
  66. - }
  67. + interact = (*argv[number] == '+') ? 1 : 0;
  68. }
  69. break;
  70. case 'm':
  71. @@ -773,6 +794,8 @@ work_comline (int argc, char *argv[])
  72. break;
  73. }
  74. }
  75. + if (overwrite == 0 && interact == 0 && autoren == 0)
  76. + overwrite = 1;
  77. return 1;
  78. }