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