Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 690136 | Differences between
and this patch

Collapse All | Expand All

(-)a/src/inp.c (-2 / +10 lines)
Lines 238-245 plan_a (char const *filename) Link Here
238
    {
238
    {
239
      if (S_ISREG (instat.st_mode))
239
      if (S_ISREG (instat.st_mode))
240
        {
240
        {
241
	  int ifd = safe_open (filename, O_RDONLY|binary_transput, 0);
241
	  int flags = O_RDONLY | binary_transput;
242
	  size_t buffered = 0, n;
242
	  size_t buffered = 0, n;
243
	  int ifd;
244
245
	  if (! follow_symlinks)
246
	    flags |= O_NOFOLLOW;
247
	  ifd = safe_open (filename, flags, 0);
243
	  if (ifd < 0)
248
	  if (ifd < 0)
244
	    pfatal ("can't open file %s", quotearg (filename));
249
	    pfatal ("can't open file %s", quotearg (filename));
245
250
Lines 340-345 plan_a (char const *filename) Link Here
340
static void
345
static void
341
plan_b (char const *filename)
346
plan_b (char const *filename)
342
{
347
{
348
  int flags = O_RDONLY | binary_transput;
343
  int ifd;
349
  int ifd;
344
  FILE *ifp;
350
  FILE *ifp;
345
  int c;
351
  int c;
Lines 353-359 plan_b (char const *filename) Link Here
353
359
354
  if (instat.st_size == 0)
360
  if (instat.st_size == 0)
355
    filename = NULL_DEVICE;
361
    filename = NULL_DEVICE;
356
  if ((ifd = safe_open (filename, O_RDONLY | binary_transput, 0)) < 0
362
  if (! follow_symlinks)
363
    flags |= O_NOFOLLOW;
364
  if ((ifd = safe_open (filename, flags, 0)) < 0
357
      || ! (ifp = fdopen (ifd, binary_transput ? "rb" : "r")))
365
      || ! (ifp = fdopen (ifd, binary_transput ? "rb" : "r")))
358
    pfatal ("Can't open file %s", quotearg (filename));
366
    pfatal ("Can't open file %s", quotearg (filename));
359
  if (TMPINNAME_needs_removal)
367
  if (TMPINNAME_needs_removal)
(-)a/src/util.c (-4 / +11 lines)
Lines 388-394 create_backup (char const *to, const struct stat *to_st, bool leave_original) Link Here
388
388
389
	  try_makedirs_errno = ENOENT;
389
	  try_makedirs_errno = ENOENT;
390
	  safe_unlink (bakname);
390
	  safe_unlink (bakname);
391
	  while ((fd = safe_open (bakname, O_CREAT | O_WRONLY | O_TRUNC, 0666)) < 0)
391
	  while ((fd = safe_open (bakname, O_CREAT | O_EXCL | O_WRONLY | O_TRUNC, 0666)) < 0)
392
	    {
392
	    {
393
	      if (errno != try_makedirs_errno)
393
	      if (errno != try_makedirs_errno)
394
		pfatal ("Can't create file %s", quotearg (bakname));
394
		pfatal ("Can't create file %s", quotearg (bakname));
Lines 579-588 create_file (char const *file, int open_flags, mode_t mode, Link Here
579
static void
579
static void
580
copy_to_fd (const char *from, int tofd)
580
copy_to_fd (const char *from, int tofd)
581
{
581
{
582
  int from_flags = O_RDONLY | O_BINARY;
582
  int fromfd;
583
  int fromfd;
583
  ssize_t i;
584
  ssize_t i;
584
585
585
  if ((fromfd = safe_open (from, O_RDONLY | O_BINARY, 0)) < 0)
586
  if (! follow_symlinks)
587
    from_flags |= O_NOFOLLOW;
588
  if ((fromfd = safe_open (from, from_flags, 0)) < 0)
586
    pfatal ("Can't reopen file %s", quotearg (from));
589
    pfatal ("Can't reopen file %s", quotearg (from));
587
  while ((i = read (fromfd, buf, bufsize)) != 0)
590
  while ((i = read (fromfd, buf, bufsize)) != 0)
588
    {
591
    {
Lines 625-630 copy_file (char const *from, char const *to, struct stat *tost, Link Here
625
  else
628
  else
626
    {
629
    {
627
      assert (S_ISREG (mode));
630
      assert (S_ISREG (mode));
631
      if (! follow_symlinks)
632
	to_flags |= O_NOFOLLOW;
628
      tofd = create_file (to, O_WRONLY | O_BINARY | to_flags, mode,
633
      tofd = create_file (to, O_WRONLY | O_BINARY | to_flags, mode,
629
			  to_dir_known_to_exist);
634
			  to_dir_known_to_exist);
630
      copy_to_fd (from, tofd);
635
      copy_to_fd (from, tofd);
Lines 640-648 copy_file (char const *from, char const *to, struct stat *tost, Link Here
640
void
645
void
641
append_to_file (char const *from, char const *to)
646
append_to_file (char const *from, char const *to)
642
{
647
{
648
  int to_flags = O_WRONLY | O_APPEND | O_BINARY;
643
  int tofd;
649
  int tofd;
644
650
645
  if ((tofd = safe_open (to, O_WRONLY | O_BINARY | O_APPEND, 0)) < 0)
651
  if (! follow_symlinks)
652
    to_flags |= O_NOFOLLOW;
653
  if ((tofd = safe_open (to, to_flags, 0)) < 0)
646
    pfatal ("Can't reopen file %s", quotearg (to));
654
    pfatal ("Can't reopen file %s", quotearg (to));
647
  copy_to_fd (from, tofd);
655
  copy_to_fd (from, tofd);
648
  if (close (tofd) != 0)
656
  if (close (tofd) != 0)
649
- 

Return to bug 690136