remove obsolete comment
[AROS.git] / test / unixio.c
blob0f2df01f7f31af56cc8d87c3a6699d41bf524107
1 /*
2 Copyright © 1995-2014, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <hidd/unixio.h>
7 #include <proto/exec.h>
8 #include <proto/dos.h>
9 #include <proto/oop.h>
10 #include <oop/oop.h>
12 #include <stdio.h>
14 #define O_RDONLY 0
15 #define O_WRONLY 1
16 #define O_RDWR 2
18 struct Library *OOPBase = NULL;
20 int main (int argc, char **argv)
22 int failed = 1;
23 struct Library *UnixIOBase = NULL;
24 OOP_Object *unixio = NULL;
25 int fd = -1;
26 int nbytes, ioerr;
27 char buf[1024];
29 if ((OOPBase = OpenLibrary("oop.library", 0)) == NULL) {
30 fprintf(stderr, "can't open oop.library\n");
31 goto exit;
34 UnixIOBase = OpenLibrary("DEVS:Drivers/unixio.hidd", 42);
35 if (!UnixIOBase)
37 fprintf(stderr, "can't open unixio.hidd\n");
38 goto exit;
41 if ((unixio = OOP_NewObject(NULL, CLID_Hidd_UnixIO, NULL)) == NULL) {
42 fprintf(stderr, "can't instantiate unixio hidd\n");
43 goto exit;
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);
51 if (fd == -1) {
52 printf("failed (ioerr is %d)\n)", ioerr);
53 goto exit;
55 printf("ok (fd is %d)\n", fd);
57 printf("reading... ");
58 nbytes = Hidd_UnixIO_ReadFile(unixio, fd, buf, 1024, &ioerr);
59 if (nbytes == -1) {
60 printf("failed (ioerr is %d\n)", ioerr);
61 goto exit;
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);
69 goto exit;
71 printf("ok\n\n\n");
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);
78 if (fd == -1) {
79 printf("failed (ioerr is %d)\n)", ioerr);
80 goto exit;
82 printf("ok (fd is %d)\n", fd);
84 printf("writing... ");
85 nbytes = Hidd_UnixIO_WriteFile(unixio, fd, buf, 1024, &ioerr);
86 if (nbytes == -1) {
87 printf("failed (ioerr is %d\n)", ioerr);
88 goto exit;
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);
96 goto exit;
98 printf("ok\n\n\n");
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);
105 if (fd == -1) {
106 printf("failed (ioerr is %d)\n)", ioerr);
107 goto exit;
109 printf("ok (fd is %d)\n", fd);
111 printf("reading... ");
112 nbytes = Hidd_UnixIO_ReadFile(unixio, fd, buf, 1024, &ioerr);
113 if (nbytes == -1) {
114 printf("failed (ioerr is %d\n)", ioerr);
115 goto exit;
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);
125 goto exit;
127 printf("ok\n\n\n");
129 fd = -1;
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);
139 if (nbytes == -1) {
140 printf("failed (ioerr is %d\n)", ioerr);
141 goto exit;
143 printf("ok (read %d bytes)\n", nbytes);
145 printf("you typed: %.*s\n\n", nbytes, buf);
148 exit:
149 if (fd >= 0) Hidd_UnixIO_CloseFile(unixio, fd, NULL);
150 if (unixio != NULL) OOP_DisposeObject(unixio);
151 if (UnixIOBase)
152 CloseLibrary(UnixIOBase);
153 if (OOPBase != NULL) CloseLibrary(OOPBase);
155 return failed ? 1 : 0;