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