1 #include <hidd/unixio.h>
2 #include <proto/exec.h>
13 struct Library
*OOPBase
= NULL
;
15 int main (int argc
, char **argv
)
18 struct Library
*UnixIOBase
= NULL
;
19 OOP_Object
*unixio
= NULL
;
24 if ((OOPBase
= OpenLibrary("oop.library", 0)) == NULL
) {
25 fprintf(stderr
, "can't open oop.library\n");
29 UnixIOBase
= OpenLibrary("DEVS:Drivers/unixio.hidd", 42);
32 fprintf(stderr
, "can't open unixio.hidd\n");
36 if ((unixio
= OOP_NewObject(NULL
, CLID_Hidd_UnixIO
, NULL
)) == NULL
) {
37 fprintf(stderr
, "can't instantiate unixio hidd\n");
42 printf("first, a trivial file read test\n\n");
44 printf("opening /dev/zero for read... ");
45 fd
= Hidd_UnixIO_OpenFile(unixio
, "/dev/zero", O_RDONLY
, 0, &ioerr
);
47 printf("failed (ioerr is %d)\n)", ioerr
);
50 printf("ok (fd is %d)\n", fd
);
52 printf("reading... ");
53 nbytes
= Hidd_UnixIO_ReadFile(unixio
, fd
, buf
, 1024, &ioerr
);
55 printf("failed (ioerr is %d\n)", ioerr
);
58 printf("ok (read %d bytes)\n", nbytes
);
60 printf("closing file... ");
61 if (Hidd_UnixIO_CloseFile(unixio
, fd
, &ioerr
) == -1)
63 printf("failed (ioerr is %d\n)", ioerr
);
69 printf("next, an equally trivial file write test\n\n");
71 printf("opening /dev/null for write... ");
72 fd
= Hidd_UnixIO_OpenFile(unixio
, "/dev/null", O_WRONLY
, 0, &ioerr
);
74 printf("failed (ioerr is %d)\n)", ioerr
);
77 printf("ok (fd is %d)\n", fd
);
79 printf("writing... ");
80 nbytes
= Hidd_UnixIO_WriteFile(unixio
, fd
, buf
, 1024, &ioerr
);
82 printf("failed (ioerr is %d\n)", ioerr
);
85 printf("ok (wrote %d bytes)\n", nbytes
);
87 printf("closing file... ");
88 if (Hidd_UnixIO_CloseFile(unixio
, fd
, &ioerr
) == -1)
90 printf("failed (ioerr is %d\n)", ioerr
);
96 printf("just for fun, lets read and print the contents of a file\n\n");
98 printf("opening /etc/hosts for read... ");
99 fd
= Hidd_UnixIO_OpenFile(unixio
, "/etc/hosts", O_RDONLY
, 0, &ioerr
);
101 printf("failed (ioerr is %d)\n)", ioerr
);
104 printf("ok (fd is %d)\n", fd
);
106 printf("reading... ");
107 nbytes
= Hidd_UnixIO_ReadFile(unixio
, fd
, buf
, 1024, &ioerr
);
109 printf("failed (ioerr is %d\n)", ioerr
);
112 printf("ok (read %d bytes)\n", nbytes
);
114 printf("system hosts file:\n\n%.*s\n", nbytes
, buf
);
116 printf("closing file... ");
117 if (Hidd_UnixIO_CloseFile(unixio
, fd
, &ioerr
) == -1)
119 printf("failed (ioerr is %d\n)", ioerr
);
127 printf("now type something on the unix console that you\n"
128 "ran aros from, then press enter. I'll wait...\n");
130 Hidd_UnixIO_Wait(unixio
, 0, vHidd_UnixIO_Read
);
132 printf("reading it... ");
133 nbytes
= Hidd_UnixIO_ReadFile(unixio
, 0, buf
, 1024, &ioerr
);
135 printf("failed (ioerr is %d\n)", ioerr
);
138 printf("ok (read %d bytes)\n", nbytes
);
140 printf("you typed: %.*s\n\n", nbytes
, buf
);
144 if (fd
>= 0) Hidd_UnixIO_CloseFile(unixio
, fd
, NULL
);
145 if (unixio
!= NULL
) OOP_DisposeObject(unixio
);
147 CloseLibrary(UnixIOBase
);
148 if (OOPBase
!= NULL
) CloseLibrary(OOPBase
);
150 return failed
? 1 : 0;