[ntp:hackers] /dev/ntpsymlink1 -> COM1: for ntpd on Windows

Dave Hart davehart at gmail.com
Sun May 31 18:49:47 UTC 2009


This is the code I currently have, complete with excessive diagnostic output:

	DPRINTF(1, ("common_serial_open given %s\n", dev));

	pch = NULL;
	if ('/' == dev[0]) {
		pch = dev + strlen(dev) - 1;

		//DPRINTF(1, ("common_serial_open initial %s\n", pch));
		if (isdigit(pch[0])) {
			while (isdigit(pch[0])) {
				pch--;
				//DPRINTF(1, ("common_serial_open backed up to %s\n", pch));
			}
			pch++;
		}
		DPRINTF(1, ("common_serial_open skipped to ending digits leaving %s\n", pch));
	} else if ('c' == tolower(dev[0])
		   && 'o' == tolower(dev[1])
		   && 'm' == tolower(dev[2])) {
		pch = dev + 3;
		DPRINTF(1, ("common_serial_open skipped COM leaving %s\n", pch));
	}

	if (!pch || !isdigit(pch[0])) {
		DPRINTF(1, ("not a digit: %s\n", pch ? pch : "[NULL]"));
		return INVALID_HANDLE_VALUE;
	}

	if (1 != sscanf(pch, "%d", &unit)
	    || unit > MAX_SERIAL
	    || unit < 0) {
		DPRINTF(1, ("sscanf failure of %s\n", pch));
		return INVALID_HANDLE_VALUE;
	}

	if (!SerialHandles[unit]) {
		snprintf(windev, sizeof(windev), "COM%d:", unit);

Cheers,
Dave Hart


More information about the hackers mailing list