1 #include <hidd/unixio.h>
2 #include <proto/exec.h>
12 struct Library
*OOPBase
= NULL
;
14 int main (int argc
, char **argv
) {
21 if ((OOPBase
= OpenLibrary("oop.library", 0)) == NULL
) {
22 fprintf(stderr
, "can't open oop.library\n");
26 if ((unixio
= OOP_NewObject(NULL
, CLID_Hidd_UnixIO
, NULL
)) == NULL
) {
27 fprintf(stderr
, "can't instantiate unixio hidd\n");
32 printf("first, a trivial file read test\n\n");
34 printf("opening /dev/zero for read... ");
35 fd
= Hidd_UnixIO_OpenFile(unixio
, "/dev/zero", O_RDONLY
, 0, &ioerr
);
37 printf("failed (ioerr is %d)\n)", ioerr
);
40 printf("ok (fd is %d)\n", fd
);
42 printf("reading... ");
43 nbytes
= Hidd_UnixIO_ReadFile(unixio
, fd
, buf
, 1024, &ioerr
);
45 printf("failed (ioerr is %d\n)", ioerr
);
48 printf("ok (read %d bytes)\n", nbytes
);
50 printf("closing file... ");
51 Hidd_UnixIO_CloseFile(unixio
, fd
, &ioerr
);
53 printf("failed (ioerr is %d\n)", ioerr
);
59 printf("next, an equally trivial file write test\n\n");
61 printf("opening /dev/null for write... ");
62 fd
= Hidd_UnixIO_OpenFile(unixio
, "/dev/null", O_WRONLY
, 0, &ioerr
);
64 printf("failed (ioerr is %d)\n)", ioerr
);
67 printf("ok (fd is %d)\n", fd
);
69 printf("writing... ");
70 nbytes
= Hidd_UnixIO_WriteFile(unixio
, fd
, buf
, 1024, &ioerr
);
72 printf("failed (ioerr is %d\n)", ioerr
);
75 printf("ok (wrote %d bytes)\n", nbytes
);
77 printf("closing file... ");
78 Hidd_UnixIO_CloseFile(unixio
, fd
, &ioerr
);
80 printf("failed (ioerr is %d\n)", ioerr
);
86 printf("just for fun, lets read and print the contents of a file\n\n");
88 printf("opening /etc/motd for read... ");
89 fd
= Hidd_UnixIO_OpenFile(unixio
, "/etc/motd", O_RDONLY
, 0, &ioerr
);
91 printf("failed (ioerr is %d)\n)", ioerr
);
94 printf("ok (fd is %d)\n", fd
);
96 printf("reading... ");
97 nbytes
= Hidd_UnixIO_ReadFile(unixio
, fd
, buf
, 1024, &ioerr
);
99 printf("failed (ioerr is %d\n)", ioerr
);
102 printf("ok (read %d bytes)\n", nbytes
);
104 printf("system motd:\n\n%.*s\n", nbytes
, buf
);
106 printf("closing file... ");
107 Hidd_UnixIO_CloseFile(unixio
, fd
, &ioerr
);
109 printf("failed (ioerr is %d\n)", ioerr
);
117 printf("now type something on the unix console that you\n"
118 "ran aros from, then press enter. I'll wait...\n");
120 Hidd_UnixIO_Wait(unixio
, 0, vHidd_UnixIO_Read
, NULL
, NULL
, SysBase
);
122 printf("reading it... ");
123 nbytes
= Hidd_UnixIO_ReadFile(unixio
, 0, buf
, 1024, &ioerr
);
125 printf("failed (ioerr is %d\n)", ioerr
);
128 printf("ok (read %d bytes)\n", nbytes
);
130 printf("you typed: %.*s\n\n", nbytes
, buf
);
134 if (fd
>= 0) Hidd_UnixIO_CloseFile(unixio
, fd
, NULL
);
135 if (unixio
!= NULL
) OOP_DisposeObject((OOP_Object
) unixio
);
136 if (OOPBase
!= NULL
) CloseLibrary(OOPBase
);
138 return failed
? 1 : 0;