2004-05-26 06:23:01 +04:00
|
|
|
/*
|
|
|
|
* $HEADER$
|
|
|
|
*/
|
|
|
|
|
2004-06-07 19:33:53 +04:00
|
|
|
#include "ompi_config.h"
|
2004-05-26 06:23:01 +04:00
|
|
|
|
|
|
|
#include <string.h>
|
2004-10-20 05:03:09 +04:00
|
|
|
#ifdef HAVE_UNISTD_H
|
2004-05-26 06:23:01 +04:00
|
|
|
#include <unistd.h>
|
2004-10-20 05:03:09 +04:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_LIBGEN_H
|
2004-05-26 06:23:01 +04:00
|
|
|
#include <libgen.h>
|
2004-10-20 05:03:09 +04:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_SYS_PARAM_H
|
2004-05-26 06:23:01 +04:00
|
|
|
#include <sys/param.h>
|
2004-10-20 05:03:09 +04:00
|
|
|
#endif
|
2004-07-15 19:08:54 +04:00
|
|
|
#include <stdlib.h>
|
2004-10-14 23:39:21 +04:00
|
|
|
#include <stdarg.h>
|
2004-05-26 06:23:01 +04:00
|
|
|
|
2004-05-26 23:00:47 +04:00
|
|
|
#include "include/constants.h"
|
2004-05-26 06:23:01 +04:00
|
|
|
#include "util/os_path.h"
|
|
|
|
#include "util/sys_info.h"
|
|
|
|
|
|
|
|
char *ompi_os_path(bool relative, ...)
|
|
|
|
{
|
|
|
|
va_list ap, ap1;
|
|
|
|
char *element, *path;
|
|
|
|
int num_elements, total_length;
|
|
|
|
|
|
|
|
va_start(ap, relative);
|
|
|
|
va_start(ap1, relative);
|
|
|
|
|
|
|
|
/* make sure system info is filled and separator is non-NULL */
|
|
|
|
ompi_sys_info();
|
|
|
|
if (NULL == ompi_system_info.path_sep) {
|
|
|
|
return(NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* no way to protect ourselves from reading too far, so have to trust caller
|
|
|
|
that they ended the list with the NULL */
|
|
|
|
|
|
|
|
num_elements = 0;
|
|
|
|
total_length = 0;
|
|
|
|
while (NULL != (element=va_arg(ap, char*))) {
|
|
|
|
num_elements++;
|
|
|
|
total_length = total_length + strlen(element);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (0 == num_elements) { /* must be looking for a simple answer */
|
|
|
|
path = (char *)malloc(2);
|
2004-06-17 21:29:47 +04:00
|
|
|
path[0] = 0;
|
2004-05-26 06:23:01 +04:00
|
|
|
if (relative) {
|
|
|
|
strcpy(path, ".");
|
2004-11-02 22:12:11 +03:00
|
|
|
strcat(path, ompi_system_info.path_sep);
|
2004-05-26 06:23:01 +04:00
|
|
|
}
|
|
|
|
else {
|
2004-11-02 22:12:11 +03:00
|
|
|
#ifndef WIN32
|
2004-05-26 06:23:01 +04:00
|
|
|
strcpy(path, ompi_system_info.path_sep);
|
2004-11-02 22:12:11 +03:00
|
|
|
#endif
|
2004-05-26 06:23:01 +04:00
|
|
|
}
|
|
|
|
return(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* setup path with enough room for the string terminator, the elements, and
|
|
|
|
the separator between each of the elements */
|
|
|
|
total_length = total_length + num_elements + 1;
|
|
|
|
if (total_length > MAXPATHLEN) { /* path length is too long - reject it */
|
|
|
|
return(NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
path = (char *)malloc(2 + total_length + num_elements-1);
|
|
|
|
if (NULL == path) {
|
|
|
|
return(NULL);
|
|
|
|
}
|
2004-06-17 21:29:47 +04:00
|
|
|
path[0] = 0;
|
2004-05-26 06:23:01 +04:00
|
|
|
|
|
|
|
if (relative) {
|
|
|
|
strcpy(path, ".");
|
|
|
|
}
|
|
|
|
|
2004-11-02 22:12:11 +03:00
|
|
|
/* get the first element here so that we don't have duplicate first
|
|
|
|
seperators */
|
|
|
|
if (NULL != (element = va_arg(ap1, char*))) {
|
|
|
|
strcat(path, element);
|
|
|
|
}
|
|
|
|
|
2004-05-26 06:23:01 +04:00
|
|
|
while (NULL != (element=va_arg(ap1, char*))) {
|
|
|
|
strcat(path, ompi_system_info.path_sep);
|
|
|
|
strcat(path, element);
|
|
|
|
}
|
|
|
|
|
|
|
|
va_end(ap);
|
|
|
|
va_end(ap1);
|
|
|
|
return(path);
|
|
|
|
}
|