2 Copyright © 1995-2014, The AROS Development Team. All rights reserved.
6 #include <hidd/unixio.h>
7 #include <proto/exec.h>
18 struct Library
*OOPBase
= NULL
;
20 int main (int argc
, char **argv
)
23 struct Library
*UnixIOBase
= NULL
;
24 OOP_Object
*unixio
= NULL
;
29 if ((OOPBase
= OpenLibrary("oop.library", 0)) == NULL
) {
30 fprintf(stderr
, "can't open oop.library\n");
34 UnixIOBase
= OpenLibrary("DEVS:Drivers/unixio.hidd", 42);
37 fprintf(stderr
, "can't open unixio.hidd\n");
41 if ((unixio
= OOP_NewObject(NULL
, CLID_Hidd_UnixIO
, NULL
)) == NULL
) {
42 fprintf(stderr
, "can't instantiate unixio hidd\n");
47 printf("first, a trivial file read test\n\n");
49 printf("opening /dev/zero for read... ");
50 fd
= Hidd_UnixIO_OpenFile(unixio
, "/dev/zero", O_RDONLY
, 0, &ioerr
);
52 printf("failed (ioerr is %d)\n)", ioerr
);
55 printf("ok (fd is %d)\n", fd
);
57 printf("reading... ");
58 nbytes
= Hidd_UnixIO_ReadFile(unixio
, fd
, buf
, 1024, &ioerr
);
60 printf("failed (ioerr is %d\n)", ioerr
);
63 printf("ok (read %d bytes)\n", nbytes
);
65 printf("closing file... ");
66 if (Hidd_UnixIO_CloseFile(unixio
, fd
, &ioerr
) == -1)
68 printf("failed (ioerr is %d\n)", ioerr
);
74 printf("next, an equally trivial file write test\n\n");
76 printf("opening /dev/null for write... ");
77 fd
= Hidd_UnixIO_OpenFile(unixio
, "/dev/null", O_WRONLY
, 0, &ioerr
);
79 printf("failed (ioerr is %d)\n)", ioerr
);
82 printf("ok (fd is %d)\n", fd
);
84 printf("writing... ");
85 nbytes
= Hidd_UnixIO_WriteFile(unixio
, fd
, buf
, 1024, &ioerr
);
87 printf("failed (ioerr is %d\n)", ioerr
);
90 printf("ok (wrote %d bytes)\n", nbytes
);
92 printf("closing file... ");
93 if (Hidd_UnixIO_CloseFile(unixio
, fd
, &ioerr
) == -1)
95 printf("failed (ioerr is %d\n)", ioerr
);
101 printf("just for fun, lets read and print the contents of a file\n\n");
103 printf("opening /etc/hosts for read... ");
104 fd
= Hidd_UnixIO_OpenFile(unixio
, "/etc/hosts", O_RDONLY
, 0, &ioerr
);
106 printf("failed (ioerr is %d)\n)", ioerr
);
109 printf("ok (fd is %d)\n", fd
);
111 printf("reading... ");
112 nbytes
= Hidd_UnixIO_ReadFile(unixio
, fd
, buf
, 1024, &ioerr
);
114 printf("failed (ioerr is %d\n)", ioerr
);
117 printf("ok (read %d bytes)\n", nbytes
);
119 printf("system hosts file:\n\n%.*s\n", nbytes
, buf
);
121 printf("closing file... ");
122 if (Hidd_UnixIO_CloseFile(unixio
, fd
, &ioerr
) == -1)
124 printf("failed (ioerr is %d\n)", ioerr
);
132 printf("now type something on the unix console that you\n"
133 "ran aros from, then press enter. I'll wait...\n");
135 Hidd_UnixIO_Wait(unixio
, 0, vHidd_UnixIO_Read
);
137 printf("reading it... ");
138 nbytes
= Hidd_UnixIO_ReadFile(unixio
, 0, buf
, 1024, &ioerr
);
140 printf("failed (ioerr is %d\n)", ioerr
);
143 printf("ok (read %d bytes)\n", nbytes
);
145 printf("you typed: %.*s\n\n", nbytes
, buf
);
149 if (fd
>= 0) Hidd_UnixIO_CloseFile(unixio
, fd
, NULL
);
150 if (unixio
!= NULL
) OOP_DisposeObject(unixio
);
152 CloseLibrary(UnixIOBase
);
153 if (OOPBase
!= NULL
) CloseLibrary(OOPBase
);
155 return failed
? 1 : 0;