2 Copyright © 2004-2016, The AROS Development Team. All rights reserved.
6 #include <aros/debug.h>
10 #include <devices/conunit.h>
11 #include <dos/dosextens.h>
12 #include <sys/ioctl.h>
13 #include <proto/dos.h>
19 static int send_action_packet(struct MsgPort
*port
, BPTR arg
)
21 struct MsgPort
*replyport
;
22 struct StandardPacket
*packet
;
25 replyport
= CreatePort(NULL
,0L);
30 packet
= (struct StandardPacket
*) AllocMem(sizeof(struct StandardPacket
),
31 MEMF_PUBLIC
|MEMF_CLEAR
);
34 DeletePort(replyport
);
38 packet
->sp_Msg
.mn_Node
.ln_Name
= (char *)&(packet
->sp_Pkt
);
39 packet
->sp_Pkt
.dp_Link
= &(packet
->sp_Msg
);
40 packet
->sp_Pkt
.dp_Port
= replyport
;
41 packet
->sp_Pkt
.dp_Type
= ACTION_DISK_INFO
;
42 packet
->sp_Pkt
.dp_Arg1
= (SIPTR
) arg
;
44 PutMsg(port
, (struct Message
*) packet
);
48 ret
= packet
->sp_Pkt
.dp_Res1
;
50 FreeMem(packet
, sizeof(struct StandardPacket
));
51 DeletePort(replyport
);
56 static int fill_consize(APTR fd
, struct winsize
*ws
)
58 struct ConUnit
*console_unit
= NULL
;
59 struct InfoData
*info_data
;
60 BPTR action_disk_info_arg
;
61 void *console
= ((struct FileHandle
*) BADDR(fd
))->fh_Type
;
68 info_data
= AllocMem(sizeof(*info_data
), MEMF_PUBLIC
);
75 action_disk_info_arg
= MKBADDR(info_data
);
76 if(send_action_packet((struct MsgPort
*) console
, action_disk_info_arg
))
78 console_unit
= (void *) ((struct IOStdReq
*) info_data
->id_InUse
)->io_Unit
;
81 /* info_data not required anymore */
82 FreeMem(info_data
, sizeof(*info_data
));
84 if (console_unit
== NULL
)
89 ws
->ws_row
= (unsigned short) console_unit
->cu_YMax
+1;
90 ws
->ws_col
= (unsigned short) console_unit
->cu_XMax
+1;
91 if(console_unit
->cu_Window
)
93 /* does a console always have a window? might be iconified? */
94 ws
->ws_xpixel
= (unsigned short) console_unit
->cu_Window
->Width
;
95 ws
->ws_ypixel
= (unsigned short) console_unit
->cu_Window
->Height
;
101 /*****************************************************************************
105 #include <sys/ioctl.h>
115 Control device. Function to manipulate and fetch special device
120 request - ioctl request id, containing request type, input or output
121 type and argument size in bytes. Use macros and defines
124 TIOCGWINSZ - fill in rows, columns, width and height of
127 ... - Other arguments for the specified request
130 EBADF - fd is not valid
131 EFAULT - no valid argument
132 ENOTTY - fd is not of required type
135 Width and height are the width and height of the intuition window.
140 #include <sys/ioctl.h>
145 ret = ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
148 printf("ERROR: %d\n", ret);
152 printf ("columns: %4d\n", w.ws_col);
153 printf ("lines: %4d\n", w.ws_row);
154 printf ("width: %4d\n", w.ws_xpixel);
155 printf ("height: %4d\n", w.ws_ypixel);
160 Only the requests listed above are implented.
166 ******************************************************************************/
172 if(request
!= TIOCGWINSZ
)
174 /* FIXME: Implement missing ioctl() parameters */
175 AROS_FUNCTION_NOT_IMPLEMENTED("posixc");
182 case STDIN_FILENO
: desc
=BADDR(Input());
184 case STDOUT_FILENO
: desc
=BADDR(Output());
187 desc
=__getfdesc(fd
); /* FIXME: is this correct? why does it not work for STDOUT/STDIN? */
190 if(!desc
|| !IsInteractive(desc
))
195 va_start(args
, request
);
196 ws
=(struct winsize
*) va_arg(args
, struct winsize
*);
199 if(!ws
|| !fill_consize(desc
, ws
))