This source file includes following definitions.
- pmix_os_path
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 #include <src/include/pmix_config.h>
21
22
23 #include <string.h>
24 #ifdef HAVE_UNISTD_H
25 #include <unistd.h>
26 #endif
27 #ifdef HAVE_SYS_PARAM_H
28 #include <sys/param.h>
29 #endif
30 #include <stdlib.h>
31 #include <stdarg.h>
32
33 #include "src/util/os_path.h"
34
35 static const char *path_sep = PMIX_PATH_SEP;
36
37 char *pmix_os_path(int relative, ...)
38 {
39 va_list ap;
40 char *element, *path;
41 size_t num_elements, total_length;
42
43 va_start(ap, relative);
44
45
46
47
48 num_elements = 0;
49 total_length = 0;
50 while (NULL != (element = va_arg(ap, char*))) {
51 num_elements++;
52 total_length = total_length + strlen(element);
53 if( path_sep[0] != element[0] ) total_length++;
54 }
55 va_end(ap);
56
57 if (0 == num_elements) {
58 path = (char *)malloc(3);
59 path[0] = '\0';
60 if (relative) {
61 strcpy(path, ".");
62 strcat(path, path_sep);
63 } else {
64 strcpy(path, path_sep);
65 }
66 return(path);
67 }
68
69
70
71 total_length = total_length + num_elements * strlen(path_sep) + 1;
72 if(relative) {
73 total_length++;
74 }
75
76 if (total_length > PMIX_PATH_MAX) {
77 return(NULL);
78 }
79
80 path = (char *)malloc(total_length);
81 if (NULL == path) {
82 return(NULL);
83 }
84 path[0] = 0;
85
86 if (relative) {
87 strcpy(path, ".");
88 }
89
90 va_start(ap, relative);
91 if( NULL != (element = va_arg(ap, char*)) ) {
92 if (path_sep[0] != element[0]) {
93 strcat(path, path_sep);
94 }
95 strcat(path, element);
96 }
97 while (NULL != (element=va_arg(ap, char*))) {
98 if (path_sep[0] != element[0]) {
99 strcat(path, path_sep);
100 }
101 strcat(path, element);
102 }
103
104 va_end(ap);
105 return pmix_make_filename_os_friendly(path);
106 }