@@ -1963,6 +1963,8 @@ export fn _fwrite_buf(ptr: [*]const u8, size: usize, stream: *c.FILE) callconv(.
19631963
19641964const FormatLength = enum {
19651965 none ,
1966+ short ,
1967+ char ,
19661968 long ,
19671969 long_long ,
19681970 size ,
@@ -2092,7 +2094,16 @@ fn vformat(out_written: *usize, writer: *FormatWriter, fmt: [*:0]const u8, args:
20922094 }
20932095
20942096 var spec_length : FormatLength = .none ;
2095- if (fmt_slice [i ] == 'l' ) {
2097+ if (fmt_slice [i ] == 'h' ) {
2098+ if (i + 1 < fmt_slice .len and fmt_slice [i + 1 ] == 'h' ) {
2099+ spec_length = .char ;
2100+ i += 2 ;
2101+ } else {
2102+ spec_length = .short ;
2103+ i += 1 ;
2104+ }
2105+ if (i >= fmt_slice .len ) return false ;
2106+ } else if (fmt_slice [i ] == 'l' ) {
20962107 if (i + 1 < fmt_slice .len and fmt_slice [i + 1 ] == 'l' ) {
20972108 spec_length = .long_long ;
20982109 i += 2 ;
@@ -2133,6 +2144,8 @@ fn vformat(out_written: *usize, writer: *FormatWriter, fmt: [*:0]const u8, args:
21332144 var buf : [100 ]u8 = undefined ;
21342145 const len = switch (spec_length ) {
21352146 .none = > formatIntCompat (& buf , vaArgCompat (args , c_int ), 10 ),
2147+ .short = > formatIntCompat (& buf , @as (i16 , @intCast (vaArgCompat (args , c_int ))), 10 ),
2148+ .char = > formatIntCompat (& buf , @as (i8 , @intCast (vaArgCompat (args , c_int ))), 10 ),
21362149 .long = > formatIntCompat (& buf , vaArgCompat (args , c_long ), 10 ),
21372150 .long_long = > formatIntCompat (& buf , vaArgCompat (args , c_longlong ), 10 ),
21382151 .size = > formatIntCompat (& buf , vaArgCompat (args , isize ), 10 ),
@@ -2147,6 +2160,8 @@ fn vformat(out_written: *usize, writer: *FormatWriter, fmt: [*:0]const u8, args:
21472160 var buf : [100 ]u8 = undefined ;
21482161 const len = switch (spec_length ) {
21492162 .none = > formatIntCompat (& buf , vaArgCompat (args , c_uint ), base ),
2163+ .short = > formatIntCompat (& buf , @as (u16 , @intCast (vaArgCompat (args , c_uint ))), base ),
2164+ .char = > formatIntCompat (& buf , @as (u8 , @intCast (vaArgCompat (args , c_uint ))), base ),
21502165 .long = > formatIntCompat (& buf , vaArgCompat (args , c_ulong ), base ),
21512166 .long_long = > formatIntCompat (& buf , vaArgCompat (args , c_ulonglong ), base ),
21522167 .size = > formatIntCompat (& buf , vaArgCompat (args , usize ), base ),
@@ -2155,6 +2170,18 @@ fn vformat(out_written: *usize, writer: *FormatWriter, fmt: [*:0]const u8, args:
21552170 out_written .* += written ;
21562171 if (written != len ) return false ;
21572172 },
2173+ 'p' = > {
2174+ if (spec_length != .none or precision != precision_none ) return false ;
2175+ const ptr_value = @intFromPtr (vaArgCompat (args , ? * const anyopaque ) orelse @as (? * const anyopaque , null ));
2176+ var buf : [2 + (@sizeOf (usize ) * 2 )]u8 = undefined ;
2177+ buf [0 ] = '0' ;
2178+ buf [1 ] = 'x' ;
2179+ const hex_len = formatIntCompat (buf [2.. ], ptr_value , 16 );
2180+ const total_len = 2 + hex_len ;
2181+ const written = writer .write (buf [0.. total_len ]);
2182+ out_written .* += written ;
2183+ if (written != total_len ) return false ;
2184+ },
21582185 else = > return false ,
21592186 }
21602187
@@ -2942,9 +2969,12 @@ fn ceilCompat(x: f64) f64 {
29422969// --------------------------------------------------------------------------------
29432970// locale
29442971// --------------------------------------------------------------------------------
2945- export fn setlocale (category : c_int , locale : [* :0 ]const u8 ) callconv (.c ) ? [* :0 ]u8 {
2972+ export fn setlocale (category : c_int , locale : ? [* :0 ]const u8 ) callconv (.c ) ? [* :0 ]u8 {
29462973 _ = category ;
2947- const requested = std .mem .span (locale );
2974+ if (locale == null ) {
2975+ return @as ([* :0 ]u8 , @ptrCast (& global .current_locale ));
2976+ }
2977+ const requested = std .mem .span (locale .? );
29482978 if (requested .len == 0 or std .mem .eql (u8 , requested , "C" ) or std .mem .eql (u8 , requested , "POSIX" )) {
29492979 global .current_locale [0 ] = 'C' ;
29502980 global .current_locale [1 ] = 0 ;
0 commit comments