|
|
|
@ -933,12 +933,68 @@ ssize_t readLine(int fd, char *buffer, size_t n) { |
|
|
|
return totRead; |
|
|
|
}; |
|
|
|
|
|
|
|
ssize_t readLine( FILE *fd, char *buffer, size_t n) { |
|
|
|
ssize_t numRead; /* # of bytes fetched by last read() */ |
|
|
|
size_t totRead; /* Total bytes read so far */ |
|
|
|
char *buf; |
|
|
|
char ch; |
|
|
|
|
|
|
|
if (n <= 0 || buffer == NULL) { |
|
|
|
errno = EINVAL; |
|
|
|
return -1; |
|
|
|
} |
|
|
|
|
|
|
|
buf = buffer; /* No pointer arithmetic on "void *" */ |
|
|
|
|
|
|
|
totRead = 0; |
|
|
|
for (;;) { |
|
|
|
numRead = fread(&ch, 1, 1, fd); |
|
|
|
|
|
|
|
if (numRead == -1) { |
|
|
|
if (errno == EINTR) /* Interrupted --> restart read() */ |
|
|
|
continue; |
|
|
|
else |
|
|
|
return -1; /* Some other error */ |
|
|
|
|
|
|
|
} else if (numRead == 0) { /* EOF */ |
|
|
|
if (totRead == 0) /* No bytes read; return 0 */ |
|
|
|
return 0; |
|
|
|
else /* Some bytes read; add '\0' */ |
|
|
|
break; |
|
|
|
|
|
|
|
} else { /* 'numRead' must be 1 if we get here */ |
|
|
|
if (totRead < n - 1) { /* Discard > (n - 1) bytes */ |
|
|
|
totRead++; |
|
|
|
*buf++ = ch; |
|
|
|
} |
|
|
|
|
|
|
|
if (ch == '\n') |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
*buf = '\0'; |
|
|
|
return totRead; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
localIpAddresses g_vLocalIpAdressess; |
|
|
|
bool g_bAdressesAreDiscovered = false; |
|
|
|
#ifdef __linux__
|
|
|
|
|
|
|
|
bool isProcessUniq( CSTR pName ){ |
|
|
|
char tB[256]; |
|
|
|
FILE *fd; |
|
|
|
sprintf( tB, "pidof %s", pName ); |
|
|
|
fd = popen( tB, "r" ); |
|
|
|
if ( fd ) { |
|
|
|
int rs = readLine( fd, tB, 256 ); |
|
|
|
if ( rs > 2 ) { |
|
|
|
fclose( fd ); |
|
|
|
return false; |
|
|
|
}; |
|
|
|
fclose( fd ); |
|
|
|
}; |
|
|
|
return true; |
|
|
|
}; |
|
|
|
|
|
|
|
|