11diff --git a/src/cat.c b/src/cat.c
2- index dcf537bc9..1f1290c42 100644
2+ index c02210301..cbdfae75f 100644
33--- a/src/cat.c
44+++ b/src/cat.c
5- @@ -708 ,6 +708 ,7 @@ main (int argc, char **argv)
6-
7- if ( stat_buf.st_dev == out_dev && stat_buf.st_ino == out_ino)
5+ @@ -717 ,6 +717 ,7 @@ main (int argc, char **argv)
6+ && have_out_dev
7+ && stat_buf.st_dev == out_dev && stat_buf.st_ino == out_ino)
88 {
99+ #ifndef _WIN32
10- if (out_flags < -1)
11- out_flags = fcntl (STDOUT_FILENO, F_GETFL);
12- bool exhausting = 0 <= out_flags && out_flags & O_APPEND;
13- @@ -717,6 +718,9 @@ main (int argc, char **argv)
14- if (0 <= in_pos)
15- exhausting = in_pos < lseek (STDOUT_FILENO, 0, SEEK_CUR);
16- }
17- + #else
18- + bool exhausting = out_isreg && (lseek (input_desc, 0, SEEK_CUR) < stat_buf.st_size);
19- + #endif
20- if (exhausting)
10+ off_t in_pos = lseek (input_desc, 0, SEEK_CUR);
11+ if (0 <= in_pos)
2112 {
22- error (0, 0, _("%s: input file is output file"), quotef (infile));
13+ @@ -725,6 +726,9 @@ main (int argc, char **argv)
14+ int whence = (0 <= out_flags && out_flags & O_APPEND
15+ ? SEEK_END : SEEK_CUR);
16+ if (in_pos < lseek (STDOUT_FILENO, 0, whence))
17+ + #else
18+ + if (out_isreg && (lseek (input_desc, 0, SEEK_CUR) < stat_buf.st_size)
19+ + #endif
20+ {
21+ error (0, 0, _("%s: input file is output file"),
22+ quotef (infile));
2323diff --git a/src/copy.c b/src/copy.c
24- index 7ffb998f6..57f805617 100644
24+ index 22d9830ba..106d6bd59 100644
2525--- a/src/copy.c
2626+++ b/src/copy.c
2727@@ -22,6 +22,10 @@
@@ -35,7 +35,7 @@ index 7ffb998f6..57f805617 100644
3535 #if HAVE_HURD_H
3636 # include <hurd.h>
3737 #endif
38- @@ -920 ,6 +924 ,9 @@ set_owner (const struct cp_options *x, char const *dst_name,
38+ @@ -928 ,6 +932 ,9 @@ set_owner (const struct cp_options *x, char const *dst_name,
3939 struct stat const *src_sb, bool new_dst,
4040 struct stat const *dst_sb)
4141 {
@@ -45,7 +45,7 @@ index 7ffb998f6..57f805617 100644
4545 uid_t uid = src_sb->st_uid;
4646 gid_t gid = src_sb->st_gid;
4747
48- @@ -1263 ,7 +1270 ,7 @@ copy_reg (char const *src_name, char const *dst_name,
48+ @@ -1271 ,7 +1278 ,7 @@ copy_reg (char const *src_name, char const *dst_name,
4949
5050 /* Compare the source dev/ino from the open file to the incoming,
5151 saved ones obtained via a previous call to stat. */
@@ -54,7 +54,7 @@ index 7ffb998f6..57f805617 100644
5454 {
5555 error (0, 0,
5656 _("skipping file %s, as it was replaced while being copied"),
57- @@ -1741 ,7 +1748 ,7 @@ same_file_ok (char const *src_name, struct stat const *src_sb,
57+ @@ -1749 ,7 +1756 ,7 @@ same_file_ok (char const *src_name, struct stat const *src_sb,
5858 struct stat tmp_src_sb;
5959
6060 bool same_link;
@@ -63,7 +63,7 @@ index 7ffb998f6..57f805617 100644
6363
6464 *return_now = false;
6565
66- @@ -1802 ,7 +1809 ,7 @@ same_file_ok (char const *src_name, struct stat const *src_sb,
66+ @@ -1810 ,7 +1817 ,7 @@ same_file_ok (char const *src_name, struct stat const *src_sb,
6767 src_sb_link = &tmp_src_sb;
6868 dst_sb_link = &tmp_dst_sb;
6969
@@ -72,7 +72,7 @@ index 7ffb998f6..57f805617 100644
7272
7373 /* If both are symlinks, then it's ok, but only if the destination
7474 will be unlinked before being opened. This is like the test
75- @@ -1890 ,7 +1897 ,7 @@ same_file_ok (char const *src_name, struct stat const *src_sb,
75+ @@ -1898 ,7 +1905 ,7 @@ same_file_ok (char const *src_name, struct stat const *src_sb,
7676 hard links to the same file. */
7777 if (!S_ISLNK (src_sb_link->st_mode) && !S_ISLNK (dst_sb_link->st_mode))
7878 {
@@ -81,7 +81,7 @@ index 7ffb998f6..57f805617 100644
8181 return true;
8282
8383 /* If they are the same file, it's ok if we're making hard links. */
84- @@ -1951 ,7 +1958 ,7 @@ same_file_ok (char const *src_name, struct stat const *src_sb,
84+ @@ -1959 ,7 +1966 ,7 @@ same_file_ok (char const *src_name, struct stat const *src_sb,
8585 else if (fstatat (dst_dirfd, dst_relname, &tmp_dst_sb, 0) != 0)
8686 return true;
8787
@@ -90,7 +90,7 @@ index 7ffb998f6..57f805617 100644
9090 return true;
9191
9292 if (x->hard_link)
93- @@ -2171 ,7 +2178 ,7 @@ source_is_dst_backup (char const *srcbase, struct stat const *src_st,
93+ @@ -2179 ,7 +2186 ,7 @@ source_is_dst_backup (char const *srcbase, struct stat const *src_st,
9494 struct stat dst_back_sb;
9595 int dst_back_status = fstatat (dst_dirfd, dst_back, &dst_back_sb, 0);
9696 free (dst_back);
@@ -99,7 +99,7 @@ index 7ffb998f6..57f805617 100644
9999 }
100100
101101 /* Copy the file SRC_NAME to the file DST_NAME aka DST_DIRFD+DST_RELNAME.
102- @@ -2246 ,7 +2253 ,7 @@ copy_internal (char const *src_name, char const *dst_name,
102+ @@ -2254 ,7 +2261 ,7 @@ copy_internal (char const *src_name, char const *dst_name,
103103
104104 src_mode = src_sb.st_mode;
105105
@@ -108,7 +108,7 @@ index 7ffb998f6..57f805617 100644
108108 {
109109 error (0, 0, ! x->install_mode /* cp */
110110 ? _("-r not specified; omitting directory %s")
111- @@ -2269 ,7 +2276 ,7 @@ copy_internal (char const *src_name, char const *dst_name,
111+ @@ -2277 ,7 +2284 ,7 @@ copy_internal (char const *src_name, char const *dst_name,
112112 This check is enabled only if x->src_info is non-null. */
113113 if (command_line_arg && x->src_info)
114114 {
@@ -117,7 +117,7 @@ index 7ffb998f6..57f805617 100644
117117 && x->backup_type == no_backups
118118 && seen_file (x->src_info, src_name, &src_sb))
119119 {
120- @@ -2352 ,7 +2359 ,7 @@ copy_internal (char const *src_name, char const *dst_name,
120+ @@ -2360 ,7 +2367 ,7 @@ copy_internal (char const *src_name, char const *dst_name,
121121 return false;
122122 }
123123
@@ -126,7 +126,7 @@ index 7ffb998f6..57f805617 100644
126126 {
127127 /* When preserving timestamps (but not moving within a file
128128 system), don't worry if the destination timestamp is
129- @@ -2875 ,7 +2882 ,7 @@ skip:
129+ @@ -2883 ,7 +2890 ,7 @@ skip:
130130 if (! set_process_security_ctx (src_name, dst_name, src_mode, new_dst, x))
131131 return false;
132132
@@ -135,7 +135,7 @@ index 7ffb998f6..57f805617 100644
135135 {
136136 struct dir_list *dir;
137137
138- @@ -2898 ,7 +2905 ,7 @@ skip:
138+ @@ -2906 ,7 +2913 ,7 @@ skip:
139139 dir->ino = src_sb.st_ino;
140140 dir->dev = src_sb.st_dev;
141141
@@ -144,7 +144,7 @@ index 7ffb998f6..57f805617 100644
144144 {
145145 /* POSIX says mkdir's behavior is implementation-defined when
146146 (src_mode & ~S_IRWXUGO) != 0. However, common practice is
147- @@ -3007 ,7 +3014 ,7 @@ skip:
147+ @@ -3015 ,7 +3022 ,7 @@ skip:
148148 || stat (".", &dot_sb) != 0
149149 || (fstatat (dst_dirfd, dst_parent, &dst_parent_sb,
150150 0) != 0)
@@ -306,10 +306,10 @@ index 4e914336b..6083c20c3 100644
306306
307307 /* The main loop. */
308308diff --git a/src/df.c b/src/df.c
309- index 5c7efd81f..3c4008958 100644
309+ index a969c5c9b..f82a0b58f 100644
310310--- a/src/df.c
311311+++ b/src/df.c
312- @@ -744 ,6 +744 ,9 @@ filter_mount_list (bool devices_only)
312+ @@ -745 ,6 +745 ,9 @@ filter_mount_list (bool devices_only)
313313 else
314314 {
315315 /* If we've already seen this device... */
@@ -319,7 +319,7 @@ index 5c7efd81f..3c4008958 100644
319319 struct devlist *seen_dev = devlist_for_dev (buf.st_dev);
320320
321321 if (seen_dev)
322- @@ -1074 ,7 +1077 ,10 @@ get_dev (char const *device, char const *mount_point, char const *file,
322+ @@ -1075 ,7 +1078 ,10 @@ get_dev (char const *device, char const *mount_point, char const *file,
323323 }
324324 }
325325 }
@@ -332,7 +332,7 @@ index 5c7efd81f..3c4008958 100644
332332 return;
333333
334334diff --git a/src/digest.c b/src/digest.c
335- index d9810c10b..be6f81f12 100644
335+ index 1f65c73b4..0dcaefdd7 100644
336336--- a/src/digest.c
337337+++ b/src/digest.c
338338@@ -1367,7 +1367,11 @@ main (int argc, char **argv)
@@ -348,7 +348,7 @@ index d9810c10b..be6f81f12 100644
348348 #if HASH_ALGO_SUM
349349 char const *short_opts = "rs";
350350diff --git a/src/du.c b/src/du.c
351- index d87800aa6..0ad10c601 100644
351+ index 0e5d860a9..bcc0b3629 100644
352352--- a/src/du.c
353353+++ b/src/du.c
354354@@ -412,6 +412,7 @@ print_size (const struct duinfo *pdui, char const *string)
@@ -368,7 +368,7 @@ index d87800aa6..0ad10c601 100644
368368
369369 /* This function checks whether any of the directories in the cycle that
370370diff --git a/src/env.c b/src/env.c
371- index 17254c303..2ed7329a8 100644
371+ index 17254c303..8a1f9b615 100644
372372--- a/src/env.c
373373+++ b/src/env.c
374374@@ -53,7 +53,9 @@ enum SIGNAL_MODE {
@@ -397,6 +397,50 @@ index 17254c303..2ed7329a8 100644
397397 return;
398398 }
399399
400+ @@ -755,7 +765,29 @@ initialize_signals (void)
401+
402+ return;
403+ }
404+ -
405+ + #ifdef _WIN32
406+ + int clearenv(void)
407+ + {
408+ + char* envp, * s;
409+ + char name[MAX_LONG_PATH];
410+ +
411+ + while (environ && (envp = *environ)) {
412+ + if ((s = strchr(envp, '=')) != NULL) {
413+ + strncpy(name, envp, s - envp + 1);
414+ + strncpy_s(name, sizeof(name), envp, s - envp+1);
415+ + name[s - envp + 1+1] = 0;
416+ +
417+ + if (_putenv(name) == -1) {
418+ + return -1;
419+ + }
420+ + }
421+ + else {
422+ + return -1;
423+ + }
424+ + }
425+ + return 0;
426+ + }
427+ + #endif
428+ int
429+ main (int argc, char **argv)
430+ {
431+ @@ -839,8 +871,12 @@ main (int argc, char **argv)
432+ if (ignore_environment)
433+ {
434+ devmsg ("cleaning environ\n");
435+ + #ifndef _WIN32
436+ static char *dummy_environ[] = { nullptr };
437+ environ = dummy_environ;
438+ + #else
439+ + clearenv();
440+ + #endif
441+ }
442+ else
443+ unset_envvars ();
400444diff --git a/src/expr.c b/src/expr.c
401445index cd87763df..82634ee65 100644
402446--- a/src/expr.c
@@ -525,7 +569,7 @@ index 76ffc49c0..c4b24420f 100644
525569 || same_nameat (AT_FDCWD, source,
526570 destdir_fd, dest_base)))
527571diff --git a/src/ls.c b/src/ls.c
528- index f67167f16..0c4f0651b 100644
572+ index 23309b812..19418351b 100644
529573--- a/src/ls.c
530574+++ b/src/ls.c
531575@@ -52,7 +52,9 @@
@@ -592,7 +636,7 @@ index f67167f16..0c4f0651b 100644
592636 j = interrupt_signal;
593637 if (j)
594638 raise (j);
595- @@ -2268 ,7 +2282 ,9 @@ decode_switches (int argc, char **argv)
639+ @@ -2273 ,7 +2287 ,9 @@ decode_switches (int argc, char **argv)
596640 break;
597641
598642 case 'Z':
@@ -602,7 +646,7 @@ index f67167f16..0c4f0651b 100644
602646 break;
603647
604648 case ZERO_OPTION:
605- @@ -2327 ,6 +2343 ,13 @@ decode_switches (int argc, char **argv)
649+ @@ -2332 ,6 +2348 ,13 @@ decode_switches (int argc, char **argv)
606650 && 0 < ws.ws_col)
607651 linelen = ws.ws_col <= MIN (PTRDIFF_MAX, SIZE_MAX) ? ws.ws_col : 0;
608652 }
@@ -616,7 +660,7 @@ index f67167f16..0c4f0651b 100644
616660 #endif
617661 if (linelen < 0)
618662 {
619- @@ -3700 ,7 +3723 ,11 @@ get_link_name (char const *filename, struct fileinfo *f, bool command_line_arg)
663+ @@ -3708 ,7 +3731 ,11 @@ get_link_name (char const *filename, struct fileinfo *f, bool command_line_arg)
620664 {
621665 f->linkname = areadlink_with_size (filename, f->stat.st_size);
622666 if (f->linkname == nullptr)
@@ -628,7 +672,7 @@ index f67167f16..0c4f0651b 100644
628672 filename);
629673 }
630674
631- @@ -4899 ,12 +4926 ,12 @@ get_type_indicator (bool stat_ok, mode_t mode, enum filetype type)
675+ @@ -4907 ,12 +4934 ,12 @@ get_type_indicator (bool stat_ok, mode_t mode, enum filetype type)
632676 }
633677 else
634678 {
@@ -644,7 +688,7 @@ index f67167f16..0c4f0651b 100644
644688 else if (stat_ok ? S_ISFIFO (mode) : type == fifo)
645689 c = '|';
646690 else if (stat_ok ? S_ISSOCK (mode) : type == sock)
647- @@ -5000 ,6 +5027 ,8 @@ get_color_indicator (const struct fileinfo *f, bool symlink_target)
691+ @@ -5008 ,6 +5035 ,8 @@ get_color_indicator (const struct fileinfo *f, bool symlink_target)
648692 else if ((1 < f->stat.st_nlink) && is_colored (C_MULTIHARDLINK))
649693 type = C_MULTIHARDLINK;
650694 }
@@ -653,7 +697,7 @@ index f67167f16..0c4f0651b 100644
653697 else if (S_ISDIR (mode))
654698 {
655699 type = C_DIR;
656- @@ -5012 ,8 +5041 ,6 @@ get_color_indicator (const struct fileinfo *f, bool symlink_target)
700+ @@ -5020 ,8 +5049 ,6 @@ get_color_indicator (const struct fileinfo *f, bool symlink_target)
657701 else if ((mode & S_ISVTX) != 0 && is_colored (C_STICKY))
658702 type = C_STICKY;
659703 }
@@ -1013,7 +1057,7 @@ index 03a260243..3949ff0b2 100644
10131057 }
10141058
10151059diff --git a/src/sort.c b/src/sort.c
1016- index 0928fd57c..11d8e83d7 100644
1060+ index 4473987ef..aa63952cd 100644
10171061--- a/src/sort.c
10181062+++ b/src/sort.c
10191063@@ -715,7 +715,11 @@ static pid_t
@@ -1028,7 +1072,7 @@ index 0928fd57c..11d8e83d7 100644
10281072
10291073 if (cpid < 0)
10301074 error (SORT_FAILURE, errno, _("waiting for %s [-d]"),
1031- @@ -4395 ,7 +4399 ,11 @@ main (int argc, char **argv)
1075+ @@ -4394 ,7 +4398 ,11 @@ main (int argc, char **argv)
10321076 static int const sig[] =
10331077 {
10341078 /* The usual suspects. */
@@ -1040,7 +1084,7 @@ index 0928fd57c..11d8e83d7 100644
10401084 #ifdef SIGPOLL
10411085 SIGPOLL,
10421086 #endif
1043- @@ -4441 ,8 +4449 ,9 @@ main (int argc, char **argv)
1087+ @@ -4440 ,8 +4448 ,9 @@ main (int argc, char **argv)
10441088 }
10451089 #endif
10461090 }
@@ -1347,7 +1391,7 @@ index 3ea7da7f5..733ff4b07 100644
13471391 case 'm':
13481392 fail |= out_mount_point (filename, pformat, prefix_len, statbuf);
13491393diff --git a/src/sync.c b/src/sync.c
1350- index 26ebbc806..58dc62559 100644
1394+ index 7c518b5fa..e4a4fb0d7 100644
13511395--- a/src/sync.c
13521396+++ b/src/sync.c
13531397@@ -116,6 +116,7 @@ sync_arg (enum sync_mode mode, char const *file)
@@ -1368,10 +1412,10 @@ index 26ebbc806..58dc62559 100644
13681412 {
13691413 int sync_status = -1;
13701414diff --git a/src/system.h b/src/system.h
1371- index 10fddf4fe..b5eb512e2 100644
1415+ index 4a47e15ca..a0aeadcfb 100644
13721416--- a/src/system.h
13731417+++ b/src/system.h
1374- @@ -655 ,7 +655 ,12 @@ emit_ancillary_info (char const *program)
1418+ @@ -662 ,7 +662 ,12 @@ emit_ancillary_info (char const *program)
13751419
13761420 /* Don't output this redundant message for English locales.
13771421 Note we still output for 'C' so that it gets included in the man page. */
@@ -1490,7 +1534,7 @@ index 1ed1c4fab..69430d3f2 100644
14901534 error (0, 0, _("warning: --pid=PID is not supported on this system"));
14911535 nbpids = 0;
14921536diff --git a/src/wc.c b/src/wc.c
1493- index 7f2e0c047..6fe0a10d8 100644
1537+ index ed4ad62c4..e19de55c1 100644
14941538--- a/src/wc.c
14951539+++ b/src/wc.c
14961540@@ -739,7 +739,11 @@ main (int argc, char **argv)
0 commit comments