1 #include <hidd/unixio.h>
2 #include <hidd/unixio_inline.h>
3 #include <proto/exec.h>
14 struct Library
*OOPBase
= NULL
;
16 int main (int argc
, char **argv
)
19 struct Library
*UnixIOBase
= NULL
;
20 OOP_Object
*unixio
= NULL
;
25 if ((OOPBase
= OpenLibrary("oop.library", 0)) == NULL
) {
26 fprintf(stderr
, "can't open oop.library\n");
30 UnixIOBase
= OpenLibrary("DEVS:Drivers/unixio.hidd", 42);
33 fprintf(stderr
, "can't open unixio.hidd\n");
37 if ((unixio
= OOP_NewObject(NULL
, CLID_Hidd_UnixIO
, NULL
)) == NULL
) {
38 fprintf(stderr
, "can't instantiate unixio hidd\n");
43 printf("first, a trivial file read test\n\n");
45 printf("opening /dev/zero for read... ");
46 fd
= Hidd_UnixIO_OpenFile(unixio
, "/dev/zero", O_RDONLY
, 0, &ioerr
);
48 printf("failed (ioerr is %d)\n)", ioerr
);
51 printf("ok (fd is %d)\n", fd
);
53 printf("reading... ");
54 nbytes
= Hidd_UnixIO_ReadFile(unixio
, fd
, buf
, 1024, &ioerr
);
56 printf("failed (ioerr is %d\n)", ioerr
);
59 printf("ok (read %d bytes)\n", nbytes
);
61 printf("closing file... ");
62 if (Hidd_UnixIO_CloseFile(unixio
, fd
, &ioerr
) == -1)
64 printf("failed (ioerr is %d\n)", ioerr
);
70 printf("next, an equally trivial file write test\n\n");
72 printf("opening /dev/null for write... ");
73 fd
= Hidd_UnixIO_OpenFile(unixio
, "/dev/null", O_WRONLY
, 0, &ioerr
);
75 printf("failed (ioerr is %d)\n)", ioerr
);
78 printf("ok (fd is %d)\n", fd
);
80 printf("writing... ");
81 nbytes
= Hidd_UnixIO_WriteFile(unixio
, fd
, buf
, 1024, &ioerr
);
83 printf("failed (ioerr is %d\n)", ioerr
);
86 printf("ok (wrote %d bytes)\n", nbytes
);
88 printf("closing file... ");
89 if (Hidd_UnixIO_CloseFile(unixio
, fd
, &ioerr
) == -1)
91 printf("failed (ioerr is %d\n)", ioerr
);
97 printf("just for fun, lets read and print the contents of a file\n\n");
99 printf("opening /etc/hosts for read... ");
100 fd
= Hidd_UnixIO_OpenFile(unixio
, "/etc/hosts", O_RDONLY
, 0, &ioerr
);
102 printf("failed (ioerr is %d)\n)", ioerr
);
105 printf("ok (fd is %d)\n", fd
);
107 printf("reading... ");
108 nbytes
= Hidd_UnixIO_ReadFile(unixio
, fd
, buf
, 1024, &ioerr
);
110 printf("failed (ioerr is %d\n)", ioerr
);
113 printf("ok (read %d bytes)\n", nbytes
);
115 printf("system hosts file:\n\n%.*s\n", nbytes
, buf
);
117 printf("closing file... ");
118 if (Hidd_UnixIO_CloseFile(unixio
, fd
, &ioerr
) == -1)
120 printf("failed (ioerr is %d\n)", ioerr
);
128 printf("now type something on the unix console that you\n"
129 "ran aros from, then press enter. I'll wait...\n");
131 Hidd_UnixIO_Wait(unixio
, 0, vHidd_UnixIO_Read
);
133 printf("reading it... ");
134 nbytes
= Hidd_UnixIO_ReadFile(unixio
, 0, buf
, 1024, &ioerr
);
136 printf("failed (ioerr is %d\n)", ioerr
);
139 printf("ok (read %d bytes)\n", nbytes
);
141 printf("you typed: %.*s\n\n", nbytes
, buf
);
145 if (fd
>= 0) Hidd_UnixIO_CloseFile(unixio
, fd
, NULL
);
146 if (unixio
!= NULL
) OOP_DisposeObject(unixio
);
148 CloseLibrary(UnixIOBase
);
149 if (OOPBase
!= NULL
) CloseLibrary(OOPBase
);
151 return failed
? 1 : 0;