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-2005 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 19 /** 20 * @file 21 * 22 * Returns an OS-independant basename() of a given filename. 23 */ 24 25 #ifndef OPAL_BASENAME_H 26 #define OPAL_BASENAME_H 27 28 #include "opal_config.h" 29 30 BEGIN_C_DECLS 31 32 /** 33 * Return the basename of a filename. 34 * 35 * @param filename The filename to examine 36 * 37 * @returns A string containing the basename, or NULL if there is an error 38 * 39 * The contents of the \em filename parameter are unchanged. This 40 * function returns a new string containing the basename of the 41 * filename (which must be eventually freed by the caller), or 42 * NULL if there is an error. Trailing "/" characters in the 43 * filename do not count, unless it is in the only part of the 44 * filename (e.g., "/" or "C:\"). 45 * 46 * This function will do the Right Things on POSIX and 47 * Windows-based operating systems. For example: 48 * 49 * foo.txt returns "foo.txt" 50 * 51 * /foo/bar/baz returns "baz" 52 * 53 * /yow.c returns "yow.c" 54 * 55 * / returns "/" 56 * 57 * C:\foo\bar\baz returns "baz" 58 * 59 * D:foo.txt returns "foo.txt" 60 * 61 * E:\yow.c returns "yow.c" 62 * 63 * F: returns "F:" 64 * 65 * G:\ returns "G:" 66 * 67 * The caller is responsible for freeing the returned string. 68 */ 69 OPAL_DECLSPEC char *opal_basename(const char* filename) __opal_attribute_malloc__ __opal_attribute_warn_unused_result__; 70 71 /** 72 * Return the dirname of a filename. 73 * 74 * @param filename The filename to examine 75 * 76 * @returns A string containing the dirname, or NULL if there is an error 77 * 78 * The contents of the \em filename parameter are unchanged. This 79 * function returns a new string containing the dirname of the 80 * filename (which must be eventually freed by the caller), or 81 * NULL if there is an error. Trailing "/" characters in the 82 * filename do not count, unless it is in the only part of the 83 * filename (e.g., "/" or "C:\"). 84 * 85 * This function will do the Right Things on POSIX and 86 * Windows-based operating systems. For example: 87 * 88 * foo.txt returns "foo.txt" 89 * 90 * /foo/bar/baz returns "/foo/bar" 91 * 92 * /yow.c returns "/" 93 * 94 * / returns "" 95 * 96 * C:\foo\bar\baz returns "C:\foo\bar" 97 * 98 * D:foo.txt returns "D:" 99 * 100 * E:\yow.c returns "E:" 101 * 102 * F: returns "" 103 * 104 * G:\ returns "" 105 * 106 * The caller is responsible for freeing the returned string. 107 */ 108 OPAL_DECLSPEC char *opal_dirname(const char* filename) __opal_attribute_malloc__ __opal_attribute_warn_unused_result__; 109 110 END_C_DECLS 111 112 #endif /* OPAL_BASENAME_H */