[PATCH] libga68: Fix posix perror
Pietro Monteiro
pietro@sociotechnical.xyz
Sat Apr 12 01:19:49 GMT 2025
The message passed into the function wasn't being printed. Print it and add a
test for posix perror.
ChangeLog:
* libga68/ga68-posix.c (_libga68_posixperror): Print the message passed
by the user.
gcc/testsuite/ChangeLog:
* algol68/execute/posix-perror-1.a68: New test.
Signed-off-by: Pietro Monteiro <pietro@sociotechnical.xyz>
---
gcc/testsuite/algol68/execute/posix-perror-1.a68 | 7 +++++++
libga68/ga68-posix.c | 5 +++--
2 files changed, 10 insertions(+), 2 deletions(-)
create mode 100644 gcc/testsuite/algol68/execute/posix-perror-1.a68
diff --git a/gcc/testsuite/algol68/execute/posix-perror-1.a68 b/gcc/testsuite/algol68/execute/posix-perror-1.a68
new file mode 100644
index 00000000000..ea1f21c3474
--- /dev/null
+++ b/gcc/testsuite/algol68/execute/posix-perror-1.a68
@@ -0,0 +1,7 @@
+# { dg-output "^something unique: " } #
+BEGIN INT fd = fopen ("doesn't exist", file o default);
+ IF fd = -1 THEN
+ ASSERT (strerror (errno) /= "");
+ perror ("something unique")
+ FI
+END
diff --git a/libga68/ga68-posix.c b/libga68/ga68-posix.c
index 78f0ac2b178..645831b6de0 100644
--- a/libga68/ga68-posix.c
+++ b/libga68/ga68-posix.c
@@ -53,10 +53,11 @@ void
_libga68_posixperror (uint32_t *s, size_t len, size_t stride)
{
size_t u8len;
- uint8_t *u8s = _libga68_u32_to_u8 (s, len, stride, NULL, &u8len);
+ uint8_t *u8str = _libga68_u32_to_u8 (s, len, stride, NULL, &u8len);
const char *errstr = strerror (_libga68_errno);
- (void) write (2, "error: ", 7);
+ (void) write (2, u8str, u8len);
+ (void) write (2, ": ", 2);
(void) write (2, errstr, strlen (errstr));
(void) write (2, "\n", 1);
}
--
2.47.0
More information about the Algol68
mailing list