1 #include <hidd/unixio.h>
2 #include <proto/exec.h>
12 struct Library
*OOPBase
= NULL
;
14 int main (int argc
, char **argv
)
17 struct Library
*UnixIOBase
= NULL
;
18 OOP_Object
*unixio
= NULL
;
23 if ((OOPBase
= OpenLibrary("oop.library", 0)) == NULL
) {
24 fprintf(stderr
, "can't open oop.library\n");
28 UnixIOBase
= OpenLibrary("DEVS:Drivers/unixio.hidd", 42);
31 fprintf(stderr
, "can't open unixio.hidd\n");
35 if ((unixio
= OOP_NewObject(NULL
, CLID_Hidd_UnixIO
, NULL
)) == NULL
) {
36 fprintf(stderr
, "can't instantiate unixio hidd\n");
41 printf("first, a trivial file read test\n\n");
43 printf("opening /dev/zero for read... ");
44 fd
= Hidd_UnixIO_OpenFile(unixio
, "/dev/zero", O_RDONLY
, 0, &ioerr
);
46 printf("failed (ioerr is %d)\n)", ioerr
);
49 printf("ok (fd is %d)\n", fd
);
51 printf("reading... ");
52 nbytes
= Hidd_UnixIO_ReadFile(unixio
, fd
, buf
, 1024, &ioerr
);
54 printf("failed (ioerr is %d\n)", ioerr
);
57 printf("ok (read %d bytes)\n", nbytes
);
59 printf("closing file... ");
60 if (Hidd_UnixIO_CloseFile(unixio
, fd
, &ioerr
) == -1)
62 printf("failed (ioerr is %d\n)", ioerr
);
68 printf("next, an equally trivial file write test\n\n");
70 printf("opening /dev/null for write... ");
71 fd
= Hidd_UnixIO_OpenFile(unixio
, "/dev/null", O_WRONLY
, 0, &ioerr
);
73 printf("failed (ioerr is %d)\n)", ioerr
);
76 printf("ok (fd is %d)\n", fd
);
78 printf("writing... ");
79 nbytes
= Hidd_UnixIO_WriteFile(unixio
, fd
, buf
, 1024, &ioerr
);
81 printf("failed (ioerr is %d\n)", ioerr
);
84 printf("ok (wrote %d bytes)\n", nbytes
);
86 printf("closing file... ");
87 if (Hidd_UnixIO_CloseFile(unixio
, fd
, &ioerr
) == -1)
89 printf("failed (ioerr is %d\n)", ioerr
);
95 printf("just for fun, lets read and print the contents of a file\n\n");
97 printf("opening /etc/hosts for read... ");
98 fd
= Hidd_UnixIO_OpenFile(unixio
, "/etc/hosts", O_RDONLY
, 0, &ioerr
);
100 printf("failed (ioerr is %d)\n)", ioerr
);
103 printf("ok (fd is %d)\n", fd
);
105 printf("reading... ");
106 nbytes
= Hidd_UnixIO_ReadFile(unixio
, fd
, buf
, 1024, &ioerr
);
108 printf("failed (ioerr is %d\n)", ioerr
);
111 printf("ok (read %d bytes)\n", nbytes
);
113 printf("system hosts file:\n\n%.*s\n", nbytes
, buf
);
115 printf("closing file... ");
116 if (Hidd_UnixIO_CloseFile(unixio
, fd
, &ioerr
) == -1)
118 printf("failed (ioerr is %d\n)", ioerr
);
126 printf("now type something on the unix console that you\n"
127 "ran aros from, then press enter. I'll wait...\n");
129 Hidd_UnixIO_Wait(unixio
, 0, vHidd_UnixIO_Read
);
131 printf("reading it... ");
132 nbytes
= Hidd_UnixIO_ReadFile(unixio
, 0, buf
, 1024, &ioerr
);
134 printf("failed (ioerr is %d\n)", ioerr
);
137 printf("ok (read %d bytes)\n", nbytes
);
139 printf("you typed: %.*s\n\n", nbytes
, buf
);
143 if (fd
>= 0) Hidd_UnixIO_CloseFile(unixio
, fd
, NULL
);
144 if (unixio
!= NULL
) OOP_DisposeObject(unixio
);
146 CloseLibrary(UnixIOBase
);
147 if (OOPBase
!= NULL
) CloseLibrary(OOPBase
);
149 return failed
? 1 : 0;