Merge branch 'printf-m-modifier' into 'master'

Add %m to printf & fix CI

See merge request redox-os/relibc!682
This commit is contained in:
Jeremy Soller
2025-08-11 14:09:37 -06:00
6 changed files with 25 additions and 3 deletions
+1 -1
View File
@@ -17,4 +17,4 @@ pub const O_PATH: c_int = 0x20_0000;
pub const FD_CLOEXEC: c_int = 0x8_0000;
// Defined for compatibility
pub const O_NDELAY: c_int = O_NONBLOCK;
pub const O_NDELAY: c_int = O_NONBLOCK;
+1 -1
View File
@@ -26,4 +26,4 @@ pub const FD_CLOEXEC: c_int = 0x0100_0000;
pub const O_NOCTTY: c_int = 0x00000200;
// Defined for compatibility
pub const O_NDELAY: c_int = O_NONBLOCK;
pub const O_NDELAY: c_int = O_NONBLOCK;
+13 -1
View File
@@ -7,7 +7,7 @@ use alloc::{
use core::{cmp, ffi::VaList, fmt, num::FpCategory, ops::Range, slice};
use crate::{
header::errno::EILSEQ,
header::errno::{self, EILSEQ},
platform::{self, types::*},
};
@@ -588,6 +588,18 @@ impl Iterator for PrintfIter {
b'c' => FmtKind::Char,
b'p' => FmtKind::Pointer,
b'n' => FmtKind::GetWritten,
b'm' => {
// %m is technically for syslog only, but musl and glibc implement it for
// printf because it is difficult and error prone to implement a format
// specifier for just *one* function.
self.format = self.format.add(1);
return Some(Ok(PrintfFmt::Plain(
errno::STR_ERROR
.get(platform::ERRNO.get() as usize)
.map(|e| e.as_bytes())
.unwrap_or(b"unknown error"),
)));
}
_ => return Some(Err(())),
};
self.format = self.format.add(1);
@@ -67,6 +67,8 @@ printed: test string, value: 11
printed: test string 2, value: 13
printed: test string 2, value: 13
%m: Owner died
C23:
Binary %b: 100
Binary %b alternate: 0b100
@@ -67,6 +67,8 @@ printed: test string, value: 11
printed: test string 2, value: 13
printed: test string 2, value: 13
%m: Owner died
C23:
Binary %b: 100
Binary %b alternate: 0b100
+6
View File
@@ -1,3 +1,4 @@
#include <errno.h>
#include <stdio.h>
#include <stdlib.h> // free()
#include <math.h> // INFINITY, NAN constants
@@ -91,9 +92,14 @@ int main(void) {
printf("printed: %s, value: %d\n", s, res);
free(s);
errno = EOWNERDEAD;
printf("\n%%m: %m\n");
puts("\nC23:");
printf("Binary %%b: %b\n", 4);
printf("Binary %%b alternate: %#b\n", 4);
printf("Binary %%B: %B\n", 4);
printf("Binary %%B alternate: %#B\n", 4);
return EXIT_SUCCESS;
}