This is the mail archive of the cygwin@sourceware.cygnus.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

DosDevIOCtl




Anyone knows what are the Win32 or ANSI C equvivalents of
DosDevIOCtl and DosGetInfoBlock?
I need the info for Cygwin-xfree port.
I got hold of a commercial
porting tool, which translates (rewrites) a code for OS/2 to Win32.
It does know know two OS/2 API's DosDevIOCtl and DosGetInfoBlock.
If anyone knows the answer, please e-mail me directly, instead of
starting an unrelated thread on Cygwin.

Thanks
Suhaib

----
/***************************************************************************
*
E:\Release7\PortTool\Test\PortTest2\xf86sup\example\NT\consel.c (000034):
[WinMain]: Must return a value, original main() may have been void main(...)
E:\Release7\PortTool\Test\PortTest2\xf86sup\example\NT\consel.c (000044):
DosOpen - Check access and share mode flags
E:\Release7\PortTool\Test\PortTest2\xf86sup\example\NT\consel.c (000058):
DosDevIOCtl - No equivalent API in Win32
E:\Release7\PortTool\Test\PortTest2\xf86sup\example\NT\consel.c (000070):
DosDevIOCtl - No equivalent API in Win32
****************************************************************************
/
/* Released to the public domain
 * Use this code freely for own developments
 */

/* This example is a simple receiver process for the /dev/console device.
 * It creates an OS/2 window which will display messages that are sent to
 * the /dev/console window.
 * Run this application with 'start consvr'.
 * Afterwards run one of the applications 'conexam' or 'ptyexam -l' to
 * test the console device.
 *
 * In order to keep the example most universal, this example program uses
 * the Dos* API rather than standard C library functions, which would be
 * also possible.
 */

#define INCL_DOSPROCESS
#define INCL_DOSFILEMGR
// #include <os2.h>
#include <windows.h>
#include <stdio.h>
#include <ctype.h>
#include <sys/types.h>
#include <sys/time.h>
#include "../api/consos2.h"

// int main(int argc, char *argv[])
int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine,
int nCmdShow)
{
	char buf[200];
	APIRET rc;
	ULONG action,arg,argsz, nread;
// 	HFILE fd;
	HANDLE fd;

	/* open device */
// 	rc = DosOpen((PSZ)"\\dev\\console$", &fd, &action, 0,
	rc = fd = CreateFile((PSZ)"\\dev\\console$", GENERIC_READ |
GENERIC_WRITE|OPEN_SHARE_DENYNONE, GENERIC_READ |
GENERIC_WRITE|OPEN_SHARE_DENYNONE, NULL, FILE_OPEN, FILE_ATTRIBUTE_NORMAL,
0);


	if (rc) {
		fprintf(stderr,
			"!!! Cannot open console device, rc=%d\n",
			rc);
		fputs("Probably the XF86SUP device driver was not properly installed.\n",
			stderr);
		exit(1);
	}

	/* grab the console */
	arg = 1;
	rc = DosDevIOCtl(fd, XFREE86_CONS, CONS_TIOCCONS,
		&arg, sizeof(arg),&argsz,
		NULL, 0, NULL);
	if (rc) {
		fprintf(stderr,"!!! Cannot grab console, status = %d\n",rc);
		fputs("Possibly another process currently owns the console\n",
			stderr);
// 		DosClose(fd);
		CloseHandle(fd);
		exit(2);
	}

	rc = DosDevIOCtl(fd, XFREE86_CONS, CONS_OWNER,
		NULL, 0, NULL,
		(PULONG)&buf, sizeof(buf),&argsz);
	if (rc) {
		fprintf(stderr,"!!! Cannot get console owner, status = %d\n",rc);
		fputs("Possibly another process currently owns the console\n",
			stderr);
// 		DosClose(fd);
		CloseHandle(fd);
		exit(2);
	}
	printf("Owner of console is: %s\n",buf);

	fd = _imphandle(fd);


	for(;;) {
		fd_set rfds,wfds,efds;
		int rc;

		/* read some chars */
		memset(buf,0,200);

		FD_ZERO(&rfds);
		FD_ZERO(&wfds);
		FD_ZERO(&efds);
		FD_SET(fd,&rfds);
printf("%d %x %x %x\n",fd+1,(&rfds)[0],(&rfds)[1],(&rfds)[2]);
		rc = select(fd+1,&rfds,&wfds,&efds,NULL);
printf("rc(select)=%d\n",rc);


// 		rc = DosRead(fd,(PVOID)buf,199,&nread);
		rc = ReadFile(fd, (PVOID)buf, 199, &nread, NULL);
		if (rc) {
			fprintf(stderr,
				"!!! Read from console returned status=%d\n",
				rc);
			break;
		}
		if (nread) {
			fputs(buf,stdout);
			if (nread < 199) {
				/* wait some time */
// 				DosSleep(50); /* 50 msec */
				Sleep(50); /* 50 msec */
			}
		}
	}
// 	DosClose(fd);
	CloseHandle(fd);
	exit(0);
	return 0;
}


--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe@sourceware.cygnus.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]