in src/main/c/Posix/PosixHelperFunctions.c [241:272]
static void retrievePhysicalPortPrefixes(stringVector* prefixes)
{
// Open the TTY drivers file
FILE *input = fopen("/proc/tty/drivers", "rb");
if (input)
{
// Read the file line by line
int maxLineSize = 256;
char *line = (char*)malloc(maxLineSize);
while (fgets(line, maxLineSize, input))
{
// Parse the prefix, name, and type fields
int i = 0;
char *token, *remainder = line, *prefix = NULL, *name = NULL, *type = NULL;
while ((token = strtok_r(remainder, " \t\r\n", &remainder)))
if (++i == 1)
name = token;
else if (i == 2)
prefix = token;
else if (i == 5)
type = token;
// Add a new prefix to the vector if the driver type and name are both "serial"
if (prefix && type && name && (strcmp(type, "serial") == 0) && (strcmp(name, "serial") == 0))
pushBackString(prefixes, prefix);
}
// Close the drivers file and clean up memory
free(line);
fclose(input);
}
}