Skip to content

Commit 8c0f635

Browse files
committed
unix: fix mkerrors.sh on OpenBSD by using strlcpy
On OpenBSD, strcpy causes an error message output that recommends the use of strlcpy[0]. Here, the result was that this output became part of the generated program code, causing gofmt to fail and create an empty zerrors_openbsd_GOARCH.go file. An ifdef guard has been added within the C code which uses the desired strlcpy function under OpenBSD. Other operating systems continue to use strcpy. [0] https://github.com/openbsd/src/blob/958bc3ae91838214c6d3bb7efc272663a5df7b01/lib/libc/string/strcpy.c#L34-L37
1 parent 81c8a6c commit 8c0f635

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

unix/mkerrors.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,11 @@ main(void)
741741
e = errors[i].num;
742742
if(i > 0 && errors[i-1].num == e)
743743
continue;
744+
#ifdef __OpenBSD__
745+
strlcpy(buf, strerror(e), sizeof(buf));
746+
#else
744747
strcpy(buf, strerror(e));
748+
#endif /* __OpenBSD __*/
745749
// lowercase first letter: Bad -> bad, but STREAM -> STREAM.
746750
if(A <= buf[0] && buf[0] <= Z && a <= buf[1] && buf[1] <= z)
747751
buf[0] += a - A;
@@ -760,7 +764,11 @@ main(void)
760764
e = signals[i].num;
761765
if(i > 0 && signals[i-1].num == e)
762766
continue;
767+
#ifdef __OpenBSD__
768+
strlcpy(buf, strsignal(e), sizeof(buf));
769+
#else
763770
strcpy(buf, strsignal(e));
771+
#endif /* __OpenBSD __*/
764772
// lowercase first letter: Bad -> bad, but STREAM -> STREAM.
765773
if(A <= buf[0] && buf[0] <= Z && a <= buf[1] && buf[1] <= z)
766774
buf[0] += a - A;

0 commit comments

Comments
 (0)