root/opal/util/path.h

/* [<][>][^][v][top][bottom][index][help] */

INCLUDED FROM


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

/* [<][>][^][v][top][bottom][index][help] */