static char isPtyDevice()

in src/main/c/Posix/PosixHelperFunctions.c [298:320]


static char isPtyDevice(const char *deviceLink)
{
	// Attempt to read the path that the potential PTY device link points to
	struct stat fileInfo;
	char *symlink = NULL, isPtyDevice = 0;
	if ((lstat(deviceLink, &fileInfo) == 0) && fileInfo.st_size && ((fileInfo.st_mode & S_IFMT) == S_IFLNK))
	{
		ssize_t bufferSize = fileInfo.st_size + 1;
		symlink = (char*)malloc(bufferSize);
		if (symlink)
		{
			ssize_t symlinkSize = readlink(deviceLink, symlink, bufferSize);
			if (symlinkSize >= 0)
			{
				symlink[symlinkSize] = '\0';
				if (strstr(symlink, "dev/pt"))
					isPtyDevice = 1;
			}
			free(symlink);
		}
	}
	return isPtyDevice;
}