File tree Expand file tree Collapse file tree
tests/wasix/dev-null-stat Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -256,9 +256,11 @@ impl FileSystem {
256256 file : Mutex :: new ( file) ,
257257 metadata : {
258258 let time = time ( ) ;
259+ let is_char_device = path. starts_with ( "/dev" ) ;
259260 Metadata {
260261 ft : FileType {
261- file : true ,
262+ file : !is_char_device,
263+ char_device : is_char_device,
262264 ..Default :: default ( )
263265 } ,
264266 accessed : time,
Original file line number Diff line number Diff line change @@ -2434,11 +2434,18 @@ impl FileSystem for FallbackFileSystem {
24342434}
24352435
24362436pub fn virtual_file_type_to_wasi_file_type ( file_type : virtual_fs:: FileType ) -> Filetype {
2437- // TODO: handle other file types
24382437 if file_type. is_dir ( ) {
24392438 Filetype :: Directory
24402439 } else if file_type. is_file ( ) {
24412440 Filetype :: RegularFile
2441+ } else if file_type. is_char_device ( ) {
2442+ Filetype :: CharacterDevice
2443+ } else if file_type. is_block_device ( ) {
2444+ Filetype :: BlockDevice
2445+ } else if file_type. is_socket ( ) {
2446+ Filetype :: SocketStream
2447+ } else if file_type. is_fifo ( ) {
2448+ Filetype :: Unknown
24422449 } else if file_type. is_symlink ( ) {
24432450 Filetype :: SymbolicLink
24442451 } else {
Original file line number Diff line number Diff line change 1+ #include <fcntl.h>
2+ #include <stdio.h>
3+ #include <stdlib.h>
4+ #include <sys/stat.h>
5+ #include <unistd.h>
6+
7+ static void fail (const char * msg ) {
8+ perror (msg );
9+ exit (1 );
10+ }
11+
12+ int main (void ) {
13+ struct stat st ;
14+
15+ if (stat ("/dev/null" , & st ) != 0 ) {
16+ fail ("stat /dev/null" );
17+ }
18+ if (!S_ISCHR (st .st_mode )) {
19+ fprintf (stderr , "stat(/dev/null) mode %#o is not char device\n" ,
20+ st .st_mode );
21+ return 1 ;
22+ }
23+
24+ int fd = open ("/dev/null" , O_RDWR );
25+ if (fd < 0 ) {
26+ fail ("open /dev/null" );
27+ }
28+ if (fstat (fd , & st ) != 0 ) {
29+ fail ("fstat /dev/null" );
30+ }
31+ if (!S_ISCHR (st .st_mode )) {
32+ fprintf (stderr , "fstat(/dev/null) mode %#o is not char device\n" ,
33+ st .st_mode );
34+ close (fd );
35+ return 1 ;
36+ }
37+
38+ close (fd );
39+ printf ("0" );
40+ return 0 ;
41+ }
Original file line number Diff line number Diff line change 1+ #! /bin/bash
2+ set -e
3+
4+ $WASMER_RUN ./main.wasm > output
5+
6+ printf " 0" | diff -u output - 1> /dev/null
You can’t perform that action at this time.
0 commit comments