1From 8c27218d12e50d29143ee4478a649ab49ead6149 Mon Sep 17 00:00:00 2001
2From: Jerome Duval <jerome.duval@gmail.com>
3Date: Tue, 13 May 2014 17:18:52 +0000
4Subject: define __USE_GNU for wempcpy
5
6
7diff --git a/lib/fnmatch.c b/lib/fnmatch.c
8index 32cfb48..50ddd73 100644
9--- a/lib/fnmatch.c
10+++ b/lib/fnmatch.c
11@@ -23,6 +23,9 @@
12 #ifndef _GNU_SOURCE
13 # define _GNU_SOURCE    1
14 #endif
15+#ifndef __USE_GNU
16+# define __USE_GNU		1
17+#endif
18 
19 #include <fnmatch.h>
20 
21-- 
222.37.3
23
24
25From 85c5da8a71d0e1257bbb4f035172ddfb94ffb1e3 Mon Sep 17 00:00:00 2001
26From: Jerome Duval <jerome.duval@gmail.com>
27Date: Tue, 13 May 2014 17:22:10 +0000
28Subject: force declaration of rpl_inet_ntop
29
30
31diff --git a/lib/arpa_inet.in.h b/lib/arpa_inet.in.h
32index 80e6713..3b47607 100644
33--- a/lib/arpa_inet.in.h
34+++ b/lib/arpa_inet.in.h
35@@ -78,7 +78,7 @@
36 
37    For more details, see the POSIX:2008 specification
38    <https://pubs.opengroup.org/onlinepubs/9699919799/functions/inet_ntop.html>.  */
39-# if @REPLACE_INET_NTOP@
40+# if 1
41 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
42 #   undef inet_ntop
43 #   define inet_ntop rpl_inet_ntop
44-- 
452.37.3
46
47
48From 1474c5e6e8dfce8e7e9970b9c57d87e065d0ec49 Mon Sep 17 00:00:00 2001
49From: Jerome Duval <jerome.duval@gmail.com>
50Date: Tue, 13 May 2014 17:32:36 +0000
51Subject: Haiku defines mknod in unistd.h
52
53
54diff --git a/lib/mknod.c b/lib/mknod.c
55index 688f0fb..e007e73 100644
56--- a/lib/mknod.c
57+++ b/lib/mknod.c
58@@ -18,6 +18,7 @@
59 
60 #include <config.h>
61 
62+#include <unistd.h>
63 #include <sys/stat.h>
64 
65 #include <errno.h>
66-- 
672.37.3
68
69
70From 93de6ff9a879ab474397e516b04f3688864c44e7 Mon Sep 17 00:00:00 2001
71From: Jerome Duval <jerome.duval@gmail.com>
72Date: Tue, 13 May 2014 17:35:25 +0000
73Subject: protect the label, not used on Haiku
74
75
76diff --git a/lib/mountlist.c b/lib/mountlist.c
77index 6d38481..80648a1 100644
78--- a/lib/mountlist.c
79+++ b/lib/mountlist.c
80@@ -1089,7 +1089,8 @@ read_file_system_list (bool need_fs_type)
81   return mount_list;
82 
83 
84- free_then_fail: _GL_UNUSED_LABEL;
85+ #ifndef __HAIKU__
86+free_then_fail: _GL_UNUSED_LABEL;
87   {
88     int saved_errno = errno;
89     *mtail = NULL;
90@@ -1104,6 +1105,7 @@ read_file_system_list (bool need_fs_type)
91     errno = saved_errno;
92     return NULL;
93   }
94+#endif
95 }
96 
97 /* Free a mount entry as returned from read_file_system_list ().  */
98-- 
992.37.3
100
101
102From f77b2c1593a5845be6c584200405c0dd40b10f81 Mon Sep 17 00:00:00 2001
103From: Jerome Duval <jerome.duval@gmail.com>
104Date: Thu, 15 May 2014 15:40:32 +0000
105Subject: strchrnul needs __USE_GNU on Haiku
106
107
108diff --git a/lib/regex.h b/lib/regex.h
109index 9ef0252..6c453cf 100644
110--- a/lib/regex.h
111+++ b/lib/regex.h
112@@ -30,8 +30,10 @@ extern "C" {
113 /* Define __USE_GNU to declare GNU extensions that violate the
114    POSIX name space rules.  */
115 #ifdef _GNU_SOURCE
116+#ifndef __USE_GNU
117 # define __USE_GNU 1
118 #endif
119+#endif
120 
121 #ifdef _REGEX_LARGE_OFFSETS
122 
123diff --git a/lib/string.in.h b/lib/string.in.h
124index b6bf432..123822f 100644
125--- a/lib/string.in.h
126+++ b/lib/string.in.h
127@@ -37,6 +37,9 @@
128 #define _GL_ALREADY_INCLUDING_STRING_H
129 
130 /* The include_next requires a split double-inclusion guard.  */
131+#ifndef __USE_GNU
132+#define __USE_GNU
133+#endif
134 #@INCLUDE_NEXT@ @NEXT_STRING_H@
135 
136 #undef _GL_ALREADY_INCLUDING_STRING_H
137-- 
1382.37.3
139
140
141From 9c008dffc70a06fd44a8b02a699c07268f7dc45e Mon Sep 17 00:00:00 2001
142From: Jerome Duval <jerome.duval@gmail.com>
143Date: Thu, 15 May 2014 20:13:58 +0000
144Subject: don't build hostid, nice, users, who
145
146
147diff --git a/Makefile.in b/Makefile.in
148index f26504c..63091a2 100644
149--- a/Makefile.in
150+++ b/Makefile.in
151@@ -1158,8 +1158,8 @@ CONFIG_CLEAN_FILES =
152 CONFIG_CLEAN_VPATH_FILES =
153 am__EXEEXT_1 = src/arch$(EXEEXT) src/coreutils$(EXEEXT) \
154 	src/hostname$(EXEEXT)
155-am__EXEEXT_2 = src/chroot$(EXEEXT) src/df$(EXEEXT) src/hostid$(EXEEXT) \
156-	src/libstdbuf.so$(EXEEXT) src/nice$(EXEEXT) src/pinky$(EXEEXT) \
157+am__EXEEXT_2 = src/chroot$(EXEEXT) src/df$(EXEEXT) \
158+	src/libstdbuf.so$(EXEEXT) \
159 	src/stdbuf$(EXEEXT) src/stty$(EXEEXT) src/timeout$(EXEEXT) \
160 	src/uptime$(EXEEXT) src/users$(EXEEXT) src/who$(EXEEXT)
161 am__EXEEXT_3 = src/[$(EXEEXT) src/b2sum$(EXEEXT) src/base64$(EXEEXT) \
162@@ -6742,7 +6742,7 @@ WARN_ON_USE_H = $(top_srcdir)/lib/warn-on-use.h
163 # FIXME: once lib/ and gnulib-tests/ are also converted, hoist to Makefile.am
164 AM_CFLAGS = $(WERROR_CFLAGS)
165 no_install__progs = src/arch src/coreutils src/hostname
166-build_if_possible__progs = src/chroot src/df src/hostid \
167+build_if_possible__progs = src/chroot src/df \
168 	src/libstdbuf.so src/nice src/pinky src/stdbuf src/stty \
169 	src/timeout src/uptime src/users src/who
170 default__progs = src/[ src/b2sum src/base64 src/base32 src/basenc \
171-- 
1722.37.3
173
174
175From fa32a4ac99ec0d27d279114a0416cd4852460ebe Mon Sep 17 00:00:00 2001
176From: Jerome Duval <jerome.duval@gmail.com>
177Date: Fri, 6 Feb 2015 20:24:12 +0000
178Subject: import Haiku changes, fix warnings.
179
180
181diff --git a/INSTALL b/INSTALL
182index 6e3904a..a44e797 100644
183--- a/INSTALL
184+++ b/INSTALL
185@@ -245,10 +245,10 @@ directory contains several dysfunctional programs; working variants of
186 these programs are available in ���/usr/bin���.  So, if you need ���/usr/ucb���
187 in your ���PATH���, put it _after_ ���/usr/bin���.
188 
189-   On Haiku, software installed for all users goes in ���/boot/common���,
190+   On Haiku, software installed for all users goes in ���/boot/system���,
191 not ���/usr/local���.  It is recommended to use the following options:
192 
193-     ./configure --prefix=/boot/common
194+     ./configure --prefix=/boot/system
195 
196 Specifying the System Type
197 ==========================
198diff --git a/lib/localcharset.c b/lib/localcharset.c
199index 7ed9c95..ca6d890 100644
200--- a/lib/localcharset.c
201+++ b/lib/localcharset.c
202@@ -41,6 +41,13 @@
203 # ifndef OS2
204 #  define OS2
205 # endif
206+
207+# if defined __HAIKU__
208+	/* To avoid the troubles of installing a separate file in the same
209+	  directory as the DLL and of retrieving the DLL's directory at
210+	  runtime, simply inline the aliases here.  */
211+	cp = "UTF-8" "\0";
212+# endif
213 #endif
214 
215 #if !defined WINDOWS_NATIVE
216diff --git a/src/copy.c b/src/copy.c
217index 13d9332..af94f6b 100644
218--- a/src/copy.c
219+++ b/src/copy.c
220@@ -18,6 +18,7 @@
221 
222 #include <config.h>
223 #include <stdio.h>
224+#include <unistd.h>
225 #include <assert.h>
226 #include <sys/ioctl.h>
227 #include <sys/types.h>
228@@ -69,6 +70,10 @@
229 # define USE_XATTR false
230 #endif
231 
232+#if (defined(__BEOS__) || defined(__HAIKU__))
233+#	include <fs_attr.h>
234+#endif
235+
236 #if USE_XATTR
237 # include <attr/error_context.h>
238 # include <attr/libattr.h>
239@@ -697,6 +702,92 @@ is_ancestor (const struct stat *sb, const struct dir_list *ancestors)
240   return false;
241 }
242 
243+
244+static int
245+copy_attributes(int fromFd, int toFd)
246+{
247+	struct dirent *dirent;
248+	char buffer[65536];
249+
250+	DIR *attributes = fs_fopen_attr_dir(fromFd);
251+	if (attributes == NULL)
252+		return errno == B_UNSUPPORTED ? 0 : -1;
253+
254+	while ((dirent = fs_read_attr_dir(attributes)) != NULL) {
255+		struct stat stat;
256+		off_t pos = 0;
257+		int attrFromFD = fs_fopen_attr(fromFd, dirent->d_name, 0, O_RDONLY);
258+		int attrToFD;
259+
260+		if (attrFromFD < 0)
261+			continue;
262+
263+		if (fstat(attrFromFD, &stat) != 0) {
264+			close(attrFromFD);
265+			continue;
266+		}
267+
268+		attrToFD = fs_fopen_attr(toFd, dirent->d_name, stat.st_type,
269+			O_WRONLY | O_TRUNC | O_CREAT);
270+		if (attrToFD < 0) {
271+			close(attrFromFD);
272+			continue;
273+		}
274+
275+		while (true) {
276+			ssize_t bytesRead, bytesWritten;
277+
278+			bytesRead = read_pos(attrFromFD, pos, buffer, sizeof(buffer));
279+			if (bytesRead < 0) {
280+				fprintf(stderr, "error reading attribute '%s'", dirent->d_name);
281+				break;
282+			}
283+
284+			bytesWritten = write_pos(attrToFD, pos, buffer, bytesRead);
285+			if (bytesWritten != bytesRead) {
286+				fprintf(stderr, "error writing attribute '%s'", dirent->d_name);
287+				break;
288+			}
289+
290+			pos += bytesWritten;
291+			stat.st_size -= bytesWritten;
292+
293+			if (stat.st_size <= 0)
294+				break;
295+		}
296+		close(attrToFD);
297+		close(attrFromFD);
298+	}
299+
300+	fs_close_attr_dir(attributes);
301+	return 0;
302+}
303+
304+
305+static int
306+copy_attributes_by_name(const char *from, const char *to, int resolveLinks)
307+{
308+	int fromFd, toFd, result;
309+
310+	fromFd = open(from, O_RDONLY | (resolveLinks ? 0 : O_NOTRAVERSE));
311+	if (fromFd < 0)
312+		return -1;
313+
314+	toFd = open(to, O_RDONLY | (resolveLinks ? 0 : O_NOTRAVERSE));
315+	if (toFd < 0) {
316+		close(fromFd);
317+		return -1;
318+	}
319+
320+	result = copy_attributes(fromFd, toFd);
321+
322+	close(fromFd);
323+	close(toFd);
324+
325+	return result;
326+}
327+
328+
329 static bool
330 errno_unsupported (int err)
331 {
332@@ -840,6 +931,10 @@ copy_dir (char const *src_name_in, char const *dst_name_in,
333       error (0, errno, _("cannot access %s"), quoteaf (src_name_in));
334       return false;
335     }
336+    
337+  if (x->ignore_attributes == 0
338+  	&& copy_attributes_by_name(src_name_in, dst_name_in, true) != 0)
339+    fprintf(stderr, "%s: could not copy attributes\n", src_name_in);
340 
341   /* For cp's -H option, dereference command line arguments, but do not
342      dereference symlinks that are found via recursive traversal.  */
343@@ -1533,6 +1628,11 @@ copy_reg (char const *src_name, char const *dst_name,
344       return_val = false;
345       goto close_src_and_dst_desc;
346     }
347+    
348+  if (x->ignore_attributes == 0
349+        && copy_attributes(source_desc, dest_desc) != 0)
350+    fprintf(stderr, "%s: could not copy attributes\n", src_name);
351+
352 
353   /* If extra permissions needed for copy_xattr didn't happen (e.g.,
354      due to umask) chmod to add them temporarily; if that fails give
355@@ -2747,6 +2847,12 @@ skip:
356                                   true, x->verbose, dereference))
357             goto un_backup;
358 
359+          if (x->ignore_attributes == 0
360+              && copy_attributes_by_name (earlier_file, dst_name,
361+                  false) != 0)
362+            error (0, errno, "cannot copy attributes from %s\n",
363+                earlier_file);
364+
365           return true;
366         }
367     }
368@@ -3177,6 +3283,11 @@ skip:
369                  preserving owner/group is a potential security problem.  */
370             }
371         }
372+
373+      if (x->ignore_attributes == 0
374+            && copy_attributes_by_name(src_name, dst_name, false) != 0)
375+        fprintf(stderr, "%s: could not copy attributes\n", src_name);
376+
377     }
378   else
379     {
380diff --git a/src/copy.h b/src/copy.h
381index ea5023c..f84c3e0 100644
382--- a/src/copy.h
383+++ b/src/copy.h
384@@ -202,6 +202,9 @@ struct cp_options
385      must be false.  */
386   bool require_preserve;
387 
388+  /* If nonzero, attributes will be ignored when copying.  */
389+  int ignore_attributes;
390+
391   /* If true, attempt to preserve the SELinux security context, too.
392      Set this only if the kernel is SELinux enabled.  */
393   bool preserve_security_context;
394diff --git a/src/cp.c b/src/cp.c
395index 488770a..4251400 100644
396--- a/src/cp.c
397+++ b/src/cp.c
398@@ -61,6 +61,7 @@ struct dir_attr
399 enum
400 {
401   ATTRIBUTES_ONLY_OPTION = CHAR_MAX + 1,
402+  IGNORE_ATTRIBUTES,
403   COPY_CONTENTS_OPTION,
404   DEBUG_OPTION,
405   NO_PRESERVE_ATTRIBUTES_OPTION,
406@@ -121,6 +122,7 @@ static struct option const long_opts[] =
407   {"debug", no_argument, NULL, DEBUG_OPTION},
408   {"dereference", no_argument, NULL, 'L'},
409   {"force", no_argument, NULL, 'f'},
410+  {"ignore-attributes", no_argument, NULL, IGNORE_ATTRIBUTES},
411   {"interactive", no_argument, NULL, 'i'},
412   {"link", no_argument, NULL, 'l'},
413   {"no-clobber", no_argument, NULL, 'n'},
414@@ -182,6 +184,7 @@ Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.\n\
415   -f, --force                  if an existing destination file cannot be\n\
416                                  opened, remove it and try again (this option\n\
417                                  is ignored when the -n option is also used)\n\
418+      --ignore-attributes      do not copy attributes\n\
419   -i, --interactive            prompt before overwrite (overrides a previous -n\
420 \n\
421                                   option)\n\
422@@ -838,6 +841,7 @@ cp_option_init (struct cp_options *x)
423   x->data_copy_required = true;
424   x->require_preserve = false;
425   x->recursive = false;
426+  x->ignore_attributes = false;
427   x->sparse_mode = SPARSE_AUTO;
428   x->symbolic_link = false;
429   x->set_mode = false;
430@@ -1043,6 +1047,10 @@ main (int argc, char **argv)
431           x.dereference = DEREF_COMMAND_LINE_ARGUMENTS;
432           break;
433 
434+        case IGNORE_ATTRIBUTES:
435+          x.ignore_attributes = true;
436+          break;
437+
438         case 'i':
439           x.interactive = I_ASK_USER;
440           break;
441diff --git a/src/dircolors.h b/src/dircolors.h
442index 88f6a6b..0e71dce 100644
443--- a/src/dircolors.h
444+++ b/src/dircolors.h
445@@ -71,7 +71,7 @@ static char const G_line[] =
446   'S','E','T','G','I','D',' ','3','0',';','4','3',' ','#',' ','f','i','l','e',' ','t','h','a','t',' ','i','s',' ','s','e','t','g','i','d',' ','(','g','+','s',')',0,
447   'C','A','P','A','B','I','L','I','T','Y',' ','0','0',' ','#',' ','f','i','l','e',' ','w','i','t','h',' ','c','a','p','a','b','i','l','i','t','y',' ','(','v','e','r','y',' ','e','x','p','e','n','s','i','v','e',' ','t','o',' ','l','o','o','k','u','p',')',0,
448   'S','T','I','C','K','Y','_','O','T','H','E','R','_','W','R','I','T','A','B','L','E',' ','3','0',';','4','2',' ','#',' ','d','i','r',' ','t','h','a','t',' ','i','s',' ','s','t','i','c','k','y',' ','a','n','d',' ','o','t','h','e','r','-','w','r','i','t','a','b','l','e',' ','(','+','t',',','o','+','w',')',0,
449-  'O','T','H','E','R','_','W','R','I','T','A','B','L','E',' ','3','4',';','4','2',' ','#',' ','d','i','r',' ','t','h','a','t',' ','i','s',' ','o','t','h','e','r','-','w','r','i','t','a','b','l','e',' ','(','o','+','w',')',' ','a','n','d',' ','n','o','t',' ','s','t','i','c','k','y',0,
450+  'O','T','H','E','R','_','W','R','I','T','A','B','L','E',' ','3','4',';','4','3',' ','#',' ','d','i','r',' ','t','h','a','t',' ','i','s',' ','o','t','h','e','r','-','w','r','i','t','a','b','l','e',' ','(','o','+','w',')',' ','a','n','d',' ','n','o','t',' ','s','t','i','c','k','y',0,
451   'S','T','I','C','K','Y',' ','3','7',';','4','4',' ','#',' ','d','i','r',' ','w','i','t','h',' ','t','h','e',' ','s','t','i','c','k','y',' ','b','i','t',' ','s','e','t',' ','(','+','t',')',' ','a','n','d',' ','n','o','t',' ','o','t','h','e','r','-','w','r','i','t','a','b','l','e',0,
452   '#',' ','T','h','i','s',' ','i','s',' ','f','o','r',' ','f','i','l','e','s',' ','w','i','t','h',' ','e','x','e','c','u','t','e',' ','p','e','r','m','i','s','s','i','o','n',':',0,
453   'E','X','E','C',' ','0','1',';','3','2',0,
454diff --git a/src/dircolors.hin b/src/dircolors.hin
455index 262e1b5..9441659 100644
456--- a/src/dircolors.hin
457+++ b/src/dircolors.hin
458@@ -74,7 +74,7 @@ SETUID 37;41	# file that is setuid (u+s)
459 SETGID 30;43	# file that is setgid (g+s)
460 CAPABILITY 00	# file with capability (very expensive to lookup)
461 STICKY_OTHER_WRITABLE 30;42 # dir that is sticky and other-writable (+t,o+w)
462-OTHER_WRITABLE 34;42 # dir that is other-writable (o+w) and not sticky
463+OTHER_WRITABLE 34;43 # dir that is other-writable (o+w) and not sticky
464 STICKY 37;44	# dir with the sticky bit set (+t) and not other-writable
465 
466 # This is for files with execute permission:
467diff --git a/src/ls.c b/src/ls.c
468index 71d94fd..9e4fb98 100644
469--- a/src/ls.c
470+++ b/src/ls.c
471@@ -720,6 +720,11 @@ static struct ignore_pattern *hide_patterns;
472    want to mess up the terminal if control chars get sent to it, and some
473    quoting methods pass through control chars as-is.  */
474 static bool qmark_funny_chars;
475+#if defined(__HAIKU__)  /* Default to show UTF8 chars in Haiku terminal. */
476+#define QMARK_FUNNY_CHARS_TTY 0
477+#else
478+#define QMARK_FUNNY_CHARS_TTY 1
479+#endif
480 
481 /* Quoting options for file and dir name output.  */
482 
483@@ -4447,6 +4452,7 @@ print_long_format (const struct fileinfo *f)
484       p = buf;
485     }
486 
487+#if !defined(__HAIKU__)
488   if (f->stat_ok
489       && (S_ISCHR (f->stat.st_mode) || S_ISBLK (f->stat.st_mode)))
490     {
491@@ -4462,6 +4468,7 @@ print_long_format (const struct fileinfo *f)
492                     umaxtostr (minor (f->stat.st_rdev), minorbuf));
493     }
494   else
495+#endif
496     {
497       char hbuf[LONGEST_HUMAN_READABLE + 1];
498       char const *size =
499diff --git a/src/mv.c b/src/mv.c
500index fc2bf77..b5eeb66 100644
501--- a/src/mv.c
502+++ b/src/mv.c
503@@ -142,6 +142,7 @@ cp_option_init (struct cp_options *x)
504   x->reduce_diagnostics = false;
505   x->data_copy_required = true;
506   x->require_preserve = false;  /* FIXME: maybe make this an option */
507+  x->ignore_attributes = false;
508   x->require_preserve_context = false;
509   x->preserve_xattr = true;
510   x->require_preserve_xattr = false;
511diff --git a/src/remove.c b/src/remove.c
512index e1da19e..81cf9c8 100644
513--- a/src/remove.c
514+++ b/src/remove.c
515@@ -219,7 +219,7 @@ prompt (FTS const *fts, FTSENT const *ent, bool is_dir,
516       wp_errno = errno;
517     }
518 
519-  if (write_protected || x->interactive == RMI_ALWAYS)
520+  if (write_protected || errno || x->interactive == RMI_ALWAYS)
521     {
522       if (0 <= write_protected && dirent_type == DT_UNKNOWN)
523         {
524diff --git a/src/uname.c b/src/uname.c
525index 921a881..10cfedb 100644
526--- a/src/uname.c
527+++ b/src/uname.c
528@@ -44,6 +44,10 @@
529 # endif
530 #endif
531 
532+#ifdef __HAIKU__
533+# include <OS.h>
534+#endif
535+
536 #include "system.h"
537 #include "die.h"
538 #include "error.h"
539@@ -341,6 +345,30 @@ main (int argc, char **argv)
540             element = processor;
541         }
542 #endif
543+
544+#ifdef __HAIKU__
545+	  {
546+		cpu_topology_node_info root;
547+		uint32 count = 1;
548+		status_t error = get_cpu_topology_info(&root, &count);
549+		if (error != B_OK || count < 1)
550+			element = "unknown";
551+		else {
552+			switch (root.data.root.platform) {
553+				case B_CPU_x86:
554+					element = "x86";
555+					break;
556+				case B_CPU_x86_64:
557+					element = "x86_64";
558+					break;
559+				default:
560+					element = "other";
561+					break;
562+			}
563+		}
564+	  }
565+#endif
566+
567       if (! (toprint == UINT_MAX && element == unknown))
568         print_element (element);
569     }
570-- 
5712.37.3
572
573
574From 4e2fcb246b9ae5a417af873f938d6f4a954ab0b1 Mon Sep 17 00:00:00 2001
575From: Jerome Duval <jerome.duval@gmail.com>
576Date: Mon, 1 Nov 2021 21:08:55 +0100
577Subject: ln: handle negative errno
578
579explicit check for -1 which is a special value in this code.
580
581diff --git a/src/copy.c b/src/copy.c
582index af94f6b..480da37 100644
583--- a/src/copy.c
584+++ b/src/copy.c
585@@ -2225,7 +2225,7 @@ create_hard_link (char const *src_name, int src_dirfd, char const *src_relname,
586   int err = force_linkat (src_dirfd, src_relname, dst_dirfd, dst_relname,
587                           dereference ? AT_SYMLINK_FOLLOW : 0,
588                           replace, -1);
589-  if (0 < err)
590+  if (err != 0 && err != -1)
591     {
592 
593       char *a_src_name = NULL;
594@@ -2237,7 +2237,7 @@ create_hard_link (char const *src_name, int src_dirfd, char const *src_relname,
595       free (a_src_name);
596       return false;
597     }
598-  if (err < 0 && verbose)
599+  if (err == -1 && verbose)
600     printf (_("removed %s\n"), quoteaf (dst_name));
601   return true;
602 }
603@@ -3146,7 +3146,7 @@ skip:
604 
605       int err = force_symlinkat (src_name, dst_dirfd, dst_relname,
606                                  x->unlink_dest_after_failed_open, -1);
607-      if (0 < err)
608+      if (err != 0 && err != -1)
609         {
610           error (0, err, _("cannot create symbolic link %s to %s"),
611                  quoteaf_n (0, dst_name), quoteaf_n (1, src_name));
612@@ -3233,7 +3233,8 @@ skip:
613 
614       int symlink_err = force_symlinkat (src_link_val, dst_dirfd, dst_relname,
615                                          x->unlink_dest_after_failed_open, -1);
616-      if (0 < symlink_err && x->update && !new_dst && S_ISLNK (dst_sb.st_mode)
617+      if (symlink_err != 0 && symlink_err != -1 && x->update && !new_dst
618+          && S_ISLNK (dst_sb.st_mode)
619           && dst_sb.st_size == strlen (src_link_val))
620         {
621           /* See if the destination is already the desired symlink.
622@@ -3250,7 +3251,7 @@ skip:
623             }
624         }
625       free (src_link_val);
626-      if (0 < symlink_err)
627+      if (symlink_err != 0 && symlink_err != -1)
628         {
629           error (0, symlink_err, _("cannot create symbolic link %s"),
630                  quoteaf (dst_name));
631diff --git a/src/ln.c b/src/ln.c
632index 1c3307c..653db04 100644
633--- a/src/ln.c
634+++ b/src/ln.c
635@@ -154,7 +154,7 @@ convert_abs_rel (char const *from, char const *target)
636 
637 /* Link SOURCE to DESTDIR_FD + DEST_BASE atomically.  DESTDIR_FD is
638    the directory containing DEST_BASE.  Return 0 if successful, a
639-   positive errno value on failure, and -1 if an atomic link cannot be
640+   errno value on failure, and -1 if an atomic link cannot be
641    done.  This handles the common case where the destination does not
642    already exist and -r is not specified.  */
643 
644@@ -185,7 +185,7 @@ do_link (char const *source, int destdir_fd, char const *dest_base,
645   char *backup_base = NULL;
646   char *rel_source = NULL;
647   int nofollow_flag = logical ? 0 : AT_SYMLINK_NOFOLLOW;
648-  if (link_errno < 0)
649+  if (link_errno == -1)
650     link_errno = atomic_link (source, destdir_fd, dest_base);
651 
652   /* Get SOURCE_STATS if later code will need it, if only for sharper
653@@ -272,7 +272,7 @@ do_link (char const *source, int destdir_fd, char const *dest_base,
654                     }
655                 }
656 
657-              if (link_errno < 0 || link_errno == EEXIST)
658+              if (link_errno == -1 || link_errno == EEXIST)
659                 {
660                   if (interactive)
661                     {
662@@ -338,7 +338,7 @@ do_link (char const *source, int destdir_fd, char const *dest_base,
663          required removing the destination first.  */
664     }
665 
666-  if (link_errno <= 0)
667+  if (link_errno == 0 || link_errno == -1)
668     {
669       /* Right after creating a hard link, do this: (note dest name and
670          source_stats, which are also the just-linked-destinations stats) */
671@@ -393,7 +393,7 @@ do_link (char const *source, int destdir_fd, char const *dest_base,
672 
673   free (backup_base);
674   free (rel_source);
675-  return link_errno <= 0;
676+  return link_errno == 0 || link_errno == -1;
677 
678 fail:
679   free (rel_source);
680-- 
6812.37.3
682
683
684From 466cdffa0a76ea5acebc9167c9bb7a10dd04969e Mon Sep 17 00:00:00 2001
685From: Jerome Duval <jerome.duval@gmail.com>
686Date: Tue, 16 Nov 2021 10:22:30 +0100
687Subject: uptime: make utmp error not critical
688
689
690diff --git a/src/uptime.c b/src/uptime.c
691index 061b85c..8b94aa2 100644
692--- a/src/uptime.c
693+++ b/src/uptime.c
694@@ -105,7 +105,7 @@ print_uptime (size_t n, const STRUCT_UTMP *this)
695 #if HAVE_STRUCT_UTMP_UT_TYPE || HAVE_STRUCT_UTMPX_UT_TYPE
696   /* Loop through all the utmp entries we just read and count up the valid
697      ones, also in the process possibly gleaning boottime. */
698-  while (n--)
699+  while (this && n--)
700     {
701       entries += IS_USER_PROCESS (this);
702       if (UT_TYPE_BOOT_TIME (this))
703@@ -181,7 +181,11 @@ uptime (char const *filename, int options)
704 
705 #if HAVE_STRUCT_UTMP_UT_TYPE || HAVE_STRUCT_UTMPX_UT_TYPE
706   if (read_utmp (filename, &n_users, &utmp_buf, options) != 0)
707+#if HAVE_OS_H
708+     ;
709+#else
710     die (EXIT_FAILURE, errno, "%s", quotef (filename));
711+#endif
712 #endif
713 
714   print_uptime (n_users, utmp_buf);
715-- 
7162.37.3
717
718
719From 94a6b6e0d965407db1e8335749ebf8a8938ec701 Mon Sep 17 00:00:00 2001
720From: PulkoMandy <pulkomandy@pulkomandy.tk>
721Date: Fri, 30 Jun 2023 20:14:30 +0200
722Subject: stty: fix sign extension in check_speed
723
724Ou speed_t is only 8 bits, and is unsigned, so there is no sign
725expansion. So, if you set a speed_t to -1, it is converted to 255 and
726doesn't compare equal to -1.
727
728diff --git a/src/stty.c b/src/stty.c
729index 607a4e7..3bc0143 100644
730--- a/src/stty.c
731+++ b/src/stty.c
732@@ -2088,7 +2088,7 @@ display_all (struct termios *mode, char const *device_name)
733 static void
734 check_speed (struct termios *mode)
735 {
736-  if (last_ibaud != -1 && last_obaud != -1)
737+  if (last_ibaud != (speed_t)-1 && last_obaud != (speed_t)-1)
738     {
739       if (cfgetispeed (mode) != last_ibaud
740           || cfgetospeed (mode) != last_obaud)
741-- 
7422.37.3
743
744