Add new strings.
[AROS.git] / test / unixio.c
blob177a0a4dd9df81227bd7f8395175dd96b0559f05
1 #include <hidd/unixio.h>
2 #include <proto/exec.h>
3 #include <proto/dos.h>
4 #include <proto/oop.h>
5 #include <oop/oop.h>
6 #include <stdio.h>
8 #define O_RDONLY 0
9 #define O_WRONLY 1
10 #define O_RDWR 2
12 struct Library *OOPBase = NULL;
14 int main (int argc, char **argv) {
15 int failed = 1;
16 HIDD *unixio = NULL;
17 int fd = -1;
18 int nbytes, ioerr;
19 char buf[1024];
21 if ((OOPBase = OpenLibrary("oop.library", 0)) == NULL) {
22 fprintf(stderr, "can't open oop.library\n");
23 goto exit;
26 if ((unixio = OOP_NewObject(NULL, CLID_Hidd_UnixIO, NULL)) == NULL) {
27 fprintf(stderr, "can't instantiate unixio hidd\n");
28 goto exit;
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);
36 if (ioerr != 0) {
37 printf("failed (ioerr is %d)\n)", ioerr);
38 goto exit;
40 printf("ok (fd is %d)\n", fd);
42 printf("reading... ");
43 nbytes = Hidd_UnixIO_ReadFile(unixio, fd, buf, 1024, &ioerr);
44 if (ioerr != 0) {
45 printf("failed (ioerr is %d\n)", ioerr);
46 goto exit;
48 printf("ok (read %d bytes)\n", nbytes);
50 printf("closing file... ");
51 Hidd_UnixIO_CloseFile(unixio, fd, &ioerr);
52 if (ioerr != 0) {
53 printf("failed (ioerr is %d\n)", ioerr);
54 goto exit;
56 printf("ok\n\n\n");
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);
63 if (ioerr != 0) {
64 printf("failed (ioerr is %d)\n)", ioerr);
65 goto exit;
67 printf("ok (fd is %d)\n", fd);
69 printf("writing... ");
70 nbytes = Hidd_UnixIO_WriteFile(unixio, fd, buf, 1024, &ioerr);
71 if (ioerr != 0) {
72 printf("failed (ioerr is %d\n)", ioerr);
73 goto exit;
75 printf("ok (wrote %d bytes)\n", nbytes);
77 printf("closing file... ");
78 Hidd_UnixIO_CloseFile(unixio, fd, &ioerr);
79 if (ioerr != 0) {
80 printf("failed (ioerr is %d\n)", ioerr);
81 goto exit;
83 printf("ok\n\n\n");
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);
90 if (ioerr != 0) {
91 printf("failed (ioerr is %d)\n)", ioerr);
92 goto exit;
94 printf("ok (fd is %d)\n", fd);
96 printf("reading... ");
97 nbytes = Hidd_UnixIO_ReadFile(unixio, fd, buf, 1024, &ioerr);
98 if (ioerr != 0) {
99 printf("failed (ioerr is %d\n)", ioerr);
100 goto exit;
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);
108 if (ioerr != 0) {
109 printf("failed (ioerr is %d\n)", ioerr);
110 goto exit;
112 printf("ok\n\n\n");
114 fd = -1;
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);
124 if (ioerr != 0) {
125 printf("failed (ioerr is %d\n)", ioerr);
126 goto exit;
128 printf("ok (read %d bytes)\n", nbytes);
130 printf("you typed: %.*s\n\n", nbytes, buf);
133 exit:
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;