OpenMPI  0.1.1
path.h
1 /*
2  * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
3  * University Research and Technology
4  * Corporation. All rights reserved.
5  * Copyright (c) 2004-2007 The University of Tennessee and The University
6  * of Tennessee Research Foundation. All rights
7  * reserved.
8  * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
9  * University of Stuttgart. All rights reserved.
10  * Copyright (c) 2004-2005 The Regents of the University of California.
11  * All rights reserved.
12  * $COPYRIGHT$
13  *
14  * Additional copyrights may follow
15  *
16  * $HEADER$
17  *
18  * @file
19  */
20 
21 #ifndef OPAL_PATH_H
22 #define OPAL_PATH_H
23 
24 #include "opal_config.h"
25 
26 #ifdef HAVE_UNISTD_H
27 #include <unistd.h>
28 #endif
29 
30 BEGIN_C_DECLS
31 
32 /**
33  * Locates a file with certain permissions
34  *
35  * @param fname File name
36  * @param pathv Array of search directories
37  * @param mode Permissions which must be satisfied (see access(2))
38  * @param envv Pointer to string containing environment
39  *
40  * @retval Full pathname of located file Success
41  * @retval NULL Failure
42  *
43  * Environment variables can appear in the form $variable at the
44  * start of a prefix path and will be replaced by the environment
45  * value if it is defined; otherwise the whole prefix is ignored.
46  * Environment variables must be followed by a path delimiter or
47  * end-of-string.
48  *
49  * The caller is responsible for freeing the returned string.
50  */
51 OPAL_DECLSPEC char *opal_path_find(char *fname, char **pathv, int mode,
52  char **envv) __opal_attribute_malloc__ __opal_attribute_warn_unused_result__;
53 
54 /**
55  * Locates a file with certain permissions from a list of search
56  * paths
57  *
58  * @param fname File name
59  * @param mode Target permissions which must be satisfied (see access(2))
60  * @param envv Pointer to environment list
61  * @param wrkdir Working directory
62  *
63  * @retval Full pathname of located file Success
64  * @retval NULL Failure
65  *
66  * Locates a file with certain permissions from the list of paths
67  * given by the $PATH environment variable. Replaces "." in the
68  * path with the working dir.
69  *
70  * The caller is responsible for freeing the returned string.
71  */
72 OPAL_DECLSPEC char *opal_path_findv(char *fname, int mode,
73  char **envv, char *wrkdir) __opal_attribute_malloc__ __opal_attribute_warn_unused_result__;
74 /**
75  * Detect if the requested path is absolute or relative.
76  *
77  * @param path File name
78  *
79  * @retval true if the path is absolute
80  * @retval false otherwise
81  *
82  * Detect if a path is absolute or relative. Handle Windows
83  * with special care as an absolute path on Windows starts
84  * with [A-Za-z]: or \\ instead of the usual / on UNIX.
85  */
86 OPAL_DECLSPEC bool opal_path_is_absolute( const char *path );
87 
88 /**
89  * Find the absolute path for an executable and return it.
90  *
91  * @param app_name Executable name
92  *
93  * @retval The absolute path if the application can be reached,
94  * @retval NULL otherwise.
95  *
96  * Try to figure out the absolute path based on the application name
97  * (usually argv[0]). If the path is already absolute return a copy, if
98  * it start with . look into the current directory, if not dig into
99  * the $PATH.
100  * In case of error or if executable was not found (as an example if
101  * the application did a cwd between the start and this call), the
102  * function will return NULL. Otherwise, an newly allocated string
103  * will be returned.
104  */
105 OPAL_DECLSPEC char* opal_find_absolute_path( char* app_name ) __opal_attribute_warn_unused_result__;
106 
107 /**
108  * Forms a complete pathname and checks it for existance and
109  * permissions
110  *
111  * @param fname File name
112  * @param path Path prefix, if NULL then fname is an absolute path
113  * @param mode Target permissions which must be satisfied (see access(2))
114  *
115  * @retval NULL Failure
116  * @retval Full pathname of the located file on Success
117  *
118  * The caller is responsible for freeing the returned string.
119  */
120 OPAL_DECLSPEC char *opal_path_access(char *fname, char *path, int mode) __opal_attribute_malloc__ __opal_attribute_warn_unused_result__;
121 
122 
123 /**
124  * @brief Figure out, whether fname is on network file system
125  *
126  * Try to figure out, whether the file name specified through fname is
127  * on any network file system (currently NFS, Lustre and Panasas).
128  *
129  * If the file is not created, the parent directory is checked.
130  * This allows checking for NFS prior to opening the file.
131  *
132  * @param[in] fname File name to check
133  *
134  * @retval true If fname is on NFS, Lustre or Panasas
135  * @retval false otherwise
136  */
137 OPAL_DECLSPEC bool opal_path_nfs(char *fname) __opal_attribute_warn_unused_result__;
138 
139 END_C_DECLS
140 #endif /* OPAL_PATH_H */
141