@@ -1073,3 +1073,107 @@ test "isatty" {
1073
1073
var file = try tmp .dir .createFile ("foo" , .{});
1074
1074
try expectEqual (os .isatty (file .handle ), false );
1075
1075
}
1076
+
1077
+ test "read with empty buffer" {
1078
+ if (native_os == .wasi and builtin .link_libc ) return error .SkipZigTest ;
1079
+ if (native_os == .wasi and ! builtin .link_libc ) try os .initPreopensWasi (std .heap .page_allocator , "/" );
1080
+
1081
+ var tmp = tmpDir (.{});
1082
+ defer tmp .cleanup ();
1083
+
1084
+ var arena = ArenaAllocator .init (testing .allocator );
1085
+ defer arena .deinit ();
1086
+ const allocator = arena .allocator ();
1087
+
1088
+ // Get base abs path
1089
+ const base_path = blk : {
1090
+ const relative_path = try fs .path .join (allocator , &[_ ][]const u8 { "zig-cache" , "tmp" , tmp .sub_path [0.. ] });
1091
+ break :blk try fs .realpathAlloc (allocator , relative_path );
1092
+ };
1093
+
1094
+ var file_path : []u8 = try fs .path .join (allocator , &[_ ][]const u8 { base_path , "some_file" });
1095
+ var file = try fs .cwd ().createFile (file_path , .{ .read = true });
1096
+ defer file .close ();
1097
+
1098
+ var bytes = try allocator .alloc (u8 , 0 );
1099
+
1100
+ _ = try os .read (file .handle , bytes );
1101
+ }
1102
+
1103
+ test "pread with empty buffer" {
1104
+ if (native_os == .wasi and builtin .link_libc ) return error .SkipZigTest ;
1105
+ if (native_os == .wasi and ! builtin .link_libc ) try os .initPreopensWasi (std .heap .page_allocator , "/" );
1106
+
1107
+ var tmp = tmpDir (.{});
1108
+ defer tmp .cleanup ();
1109
+
1110
+ var arena = ArenaAllocator .init (testing .allocator );
1111
+ defer arena .deinit ();
1112
+ const allocator = arena .allocator ();
1113
+
1114
+ // Get base abs path
1115
+ const base_path = blk : {
1116
+ const relative_path = try fs .path .join (allocator , &[_ ][]const u8 { "zig-cache" , "tmp" , tmp .sub_path [0.. ] });
1117
+ break :blk try fs .realpathAlloc (allocator , relative_path );
1118
+ };
1119
+
1120
+ var file_path : []u8 = try fs .path .join (allocator , &[_ ][]const u8 { base_path , "some_file" });
1121
+ var file = try fs .cwd ().createFile (file_path , .{ .read = true });
1122
+ defer file .close ();
1123
+
1124
+ var bytes = try allocator .alloc (u8 , 0 );
1125
+
1126
+ _ = try os .pread (file .handle , bytes , 0 );
1127
+ }
1128
+
1129
+ test "write with empty buffer" {
1130
+ if (native_os == .wasi and builtin .link_libc ) return error .SkipZigTest ;
1131
+ if (native_os == .wasi and ! builtin .link_libc ) try os .initPreopensWasi (std .heap .page_allocator , "/" );
1132
+
1133
+ var tmp = tmpDir (.{});
1134
+ defer tmp .cleanup ();
1135
+
1136
+ var arena = ArenaAllocator .init (testing .allocator );
1137
+ defer arena .deinit ();
1138
+ const allocator = arena .allocator ();
1139
+
1140
+ // Get base abs path
1141
+ const base_path = blk : {
1142
+ const relative_path = try fs .path .join (allocator , &[_ ][]const u8 { "zig-cache" , "tmp" , tmp .sub_path [0.. ] });
1143
+ break :blk try fs .realpathAlloc (allocator , relative_path );
1144
+ };
1145
+
1146
+ var file_path : []u8 = try fs .path .join (allocator , &[_ ][]const u8 { base_path , "some_file" });
1147
+ var file = try fs .cwd ().createFile (file_path , .{});
1148
+ defer file .close ();
1149
+
1150
+ var bytes = try allocator .alloc (u8 , 0 );
1151
+
1152
+ _ = try os .write (file .handle , bytes );
1153
+ }
1154
+
1155
+ test "pwrite with empty buffer" {
1156
+ if (native_os == .wasi and builtin .link_libc ) return error .SkipZigTest ;
1157
+ if (native_os == .wasi and ! builtin .link_libc ) try os .initPreopensWasi (std .heap .page_allocator , "/" );
1158
+
1159
+ var tmp = tmpDir (.{});
1160
+ defer tmp .cleanup ();
1161
+
1162
+ var arena = ArenaAllocator .init (testing .allocator );
1163
+ defer arena .deinit ();
1164
+ const allocator = arena .allocator ();
1165
+
1166
+ // Get base abs path
1167
+ const base_path = blk : {
1168
+ const relative_path = try fs .path .join (allocator , &[_ ][]const u8 { "zig-cache" , "tmp" , tmp .sub_path [0.. ] });
1169
+ break :blk try fs .realpathAlloc (allocator , relative_path );
1170
+ };
1171
+
1172
+ var file_path : []u8 = try fs .path .join (allocator , &[_ ][]const u8 { base_path , "some_file" });
1173
+ var file = try fs .cwd ().createFile (file_path , .{});
1174
+ defer file .close ();
1175
+
1176
+ var bytes = try allocator .alloc (u8 , 0 );
1177
+
1178
+ _ = try os .pwrite (file .handle , bytes , 0 );
1179
+ }
0 commit comments