patch-unixos_c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. $OpenBSD: patch-unixos_c,v 1.6 2012/12/11 11:01:31 sthen Exp $
  2. Fixes from Sebastian Pipping/gentoo.
  3. --- unixos.c.orig Mon Jul 21 21:54:05 2003
  4. +++ unixos.c Tue Dec 11 10:52:04 2012
  5. @@ -30,6 +30,7 @@
  6. #include <sys/param.h>
  7. #include <netdb.h>
  8. #include <fcntl.h>
  9. +#include <stdlib.h>
  10. #include "xmalloc.h"
  11. #include "common.h"
  12. #include "part.h"
  13. @@ -38,10 +39,6 @@
  14. #define MAXHOSTNAMELEN 64
  15. #endif
  16. -extern int errno;
  17. -extern char *malloc();
  18. -extern char *getenv();
  19. -
  20. int overwrite_files = 0;
  21. int didchat;
  22. @@ -90,7 +87,7 @@ char *os_idtodir(char *id)
  23. strcpy(buf, getenv("TMPDIR"));
  24. }
  25. else {
  26. - strcpy(buf, "/usr/tmp");
  27. + strcpy(buf, "/var/tmp");
  28. }
  29. strcat(buf, "/m-prts-");
  30. p = getenv("USER");
  31. @@ -136,11 +133,7 @@ FILE *os_createnewfile(char *fname)
  32. int fd;
  33. FILE *ret;
  34. -#ifdef O_EXCL
  35. - fd=open(fname, O_RDWR|O_CREAT|O_EXCL, 0644);
  36. -#else
  37. - fd=open(fname, O_RDWR|O_CREAT|O_TRUNC, 0644);
  38. -#endif
  39. + fd=open(fname, O_RDWR|O_CREAT|O_EXCL, 0600);
  40. if (fd == -1)
  41. return NULL;
  42. @@ -149,7 +142,19 @@ FILE *os_createnewfile(char *fname)
  43. return ret;
  44. }
  45. -
  46. +FILE *os_resetfile(char *fname)
  47. +{
  48. + int fd;
  49. + FILE *ret;
  50. +
  51. + fd=open(fname, O_RDWR|O_CREAT|O_TRUNC, 0600);
  52. + if (fd == -1)
  53. + return NULL;
  54. +
  55. + ret=fdopen(fd, "w");
  56. + return ret;
  57. +}
  58. +
  59. /*
  60. * Create a new file, with suggested filename "fname".
  61. * "fname" may have come from an insecure source, so clean it up first.