1
1

On windows make sure we add the initial path separator only if we are

creating a relative path. Use BEGIN_C_DECLS and END_C_DECLS on some
header files.

This commit was SVN r15254.
Этот коммит содержится в:
George Bosilca 2007-07-01 17:51:34 +00:00
родитель 951e4929b9
Коммит 003d1b8665
4 изменённых файлов: 89 добавлений и 103 удалений

Просмотреть файл

@ -25,85 +25,82 @@
#ifndef OPAL_BASENAME_H #ifndef OPAL_BASENAME_H
#define OPAL_BASENAME_H #define OPAL_BASENAME_H
#if defined(c_plusplus) || defined(__cplusplus) BEGIN_C_DECLS
extern "C" {
#endif
/**
* Return the basename of a filename.
*
* @param filename The filename to examine
*
* @returns A string containing the basename, or NULL if there is an error
*
* The contents of the \em filename parameter are unchanged. This
* function returns a new string containing the basename of the
* filename (which must be eventually freed by the caller), or
* NULL if there is an error. Trailing "/" characters in the
* filename do not count, unless it is in the only part of the
* filename (e.g., "/" or "C:\").
*
* This function will do the Right Things on POSIX and
* Windows-based operating systems. For example:
*
* foo.txt returns "foo.txt"
*
* /foo/bar/baz returns "baz"
*
* /yow.c returns "yow.c"
*
* / returns "/"
*
* C:\foo\bar\baz returns "baz"
*
* D:foo.txt returns "foo.txt"
*
* E:\yow.c returns "yow.c"
*
* F: returns "F:"
*
* G:\ returns "G:"
*/
OPAL_DECLSPEC char *opal_basename(const char* filename);
/** /**
* Return the dirname of a filename. * Return the basename of a filename.
* *
* @param filename The filename to examine * @param filename The filename to examine
* *
* @returns A string containing the dirname, or NULL if there is an error * @returns A string containing the basename, or NULL if there is an error
* *
* The contents of the \em filename parameter are unchanged. This * The contents of the \em filename parameter are unchanged. This
* function returns a new string containing the dirname of the * function returns a new string containing the basename of the
* filename (which must be eventually freed by the caller), or * filename (which must be eventually freed by the caller), or
* NULL if there is an error. Trailing "/" characters in the * NULL if there is an error. Trailing "/" characters in the
* filename do not count, unless it is in the only part of the * filename do not count, unless it is in the only part of the
* filename (e.g., "/" or "C:\"). * filename (e.g., "/" or "C:\").
* *
* This function will do the Right Things on POSIX and * This function will do the Right Things on POSIX and
* Windows-based operating systems. For example: * Windows-based operating systems. For example:
* *
* foo.txt returns "foo.txt" * foo.txt returns "foo.txt"
* *
* /foo/bar/baz returns "/foo/bar" * /foo/bar/baz returns "baz"
* *
* /yow.c returns "/" * /yow.c returns "yow.c"
* *
* / returns "" * / returns "/"
* *
* C:\foo\bar\baz returns "C:\foo\bar" * C:\foo\bar\baz returns "baz"
* *
* D:foo.txt returns "D:" * D:foo.txt returns "foo.txt"
* *
* E:\yow.c returns "E:" * E:\yow.c returns "yow.c"
* *
* F: returns "" * F: returns "F:"
* *
* G:\ returns "" * G:\ returns "G:"
*/ */
OPAL_DECLSPEC char *opal_dirname(const char* filename); OPAL_DECLSPEC char *opal_basename(const char* filename);
#if defined(c_plusplus) || defined(__cplusplus) /**
} * Return the dirname of a filename.
#endif *
* @param filename The filename to examine
*
* @returns A string containing the dirname, or NULL if there is an error
*
* The contents of the \em filename parameter are unchanged. This
* function returns a new string containing the dirname of the
* filename (which must be eventually freed by the caller), or
* NULL if there is an error. Trailing "/" characters in the
* filename do not count, unless it is in the only part of the
* filename (e.g., "/" or "C:\").
*
* This function will do the Right Things on POSIX and
* Windows-based operating systems. For example:
*
* foo.txt returns "foo.txt"
*
* /foo/bar/baz returns "/foo/bar"
*
* /yow.c returns "/"
*
* / returns ""
*
* C:\foo\bar\baz returns "C:\foo\bar"
*
* D:foo.txt returns "D:"
*
* E:\yow.c returns "E:"
*
* F: returns ""
*
* G:\ returns ""
*/
OPAL_DECLSPEC char *opal_dirname(const char* filename);
END_C_DECLS
#endif /* OPAL_BASENAME_H */ #endif /* OPAL_BASENAME_H */

Просмотреть файл

@ -52,9 +52,7 @@
#include "opal_config.h" #include "opal_config.h"
#if defined(c_plusplus) || defined(__cplusplus) BEGIN_C_DECLS
extern "C" {
#endif
/** /**
* Convert a size_t to an int. * Convert a size_t to an int.
@ -76,8 +74,6 @@ extern "C" {
*/ */
OPAL_DECLSPEC int opal_size2int(size_t in, int *out, bool want_check) __opal_attribute_nonnull__(2); OPAL_DECLSPEC int opal_size2int(size_t in, int *out, bool want_check) __opal_attribute_nonnull__(2);
#if defined(c_plusplus) || defined(__cplusplus) END_C_DECLS
}
#endif
#endif #endif

Просмотреть файл

@ -41,17 +41,11 @@
#define OPAL_OS_DIRPATH_CREATE_H #define OPAL_OS_DIRPATH_CREATE_H
#include "opal_config.h" #include "opal_config.h"
#include <stdio.h>
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#ifdef HAVE_SYS_STAT_H #ifdef HAVE_SYS_STAT_H
#include <sys/stat.h> #include <sys/stat.h>
#endif #endif
#if defined(c_plusplus) || defined(__cplusplus) BEGIN_C_DECLS
extern "C" {
#endif
/** /**
* @param path A pointer to a string that contains the path name to be built. * @param path A pointer to a string that contains the path name to be built.
@ -119,8 +113,6 @@ OPAL_DECLSPEC int opal_os_dirpath_destroy(const char *path,
bool recursive, bool recursive,
opal_os_dirpath_destroy_callback_fn_t cbfunc); opal_os_dirpath_destroy_callback_fn_t cbfunc);
#if defined(c_plusplus) || defined(__cplusplus) END_C_DECLS
}
#endif
#endif #endif

Просмотреть файл

@ -47,9 +47,10 @@ char *opal_os_path(bool relative, ...)
num_elements = 0; num_elements = 0;
total_length = 0; total_length = 0;
while (NULL != (element=va_arg(ap, char*))) { while (NULL != (element = va_arg(ap, char*))) {
num_elements++; num_elements++;
total_length = total_length + strlen(element); total_length = total_length + strlen(element);
if( path_sep[0] != element[0] ) total_length++;
} }
if (0 == num_elements) { /* must be looking for a simple answer */ if (0 == num_elements) { /* must be looking for a simple answer */
@ -58,8 +59,7 @@ char *opal_os_path(bool relative, ...)
if (relative) { if (relative) {
strcpy(path, "."); strcpy(path, ".");
strcat(path, path_sep); strcat(path, path_sep);
} } else {
else {
#ifndef __WINDOWS__ #ifndef __WINDOWS__
strcpy(path, path_sep); strcpy(path, path_sep);
#endif #endif
@ -89,12 +89,13 @@ char *opal_os_path(bool relative, ...)
} }
/* Windows does not require to have the initial separator. */ /* Windows does not require to have the initial separator. */
if( NULL != (element=va_arg(ap1, char*)) ) { if( NULL != (element = va_arg(ap1, char*)) ) {
#ifndef __WINDOWS__
if (path_sep[0] != element[0]) { if (path_sep[0] != element[0]) {
strcat(path, path_sep); #ifdef __WINDOWS__
} if( relative )
#endif /* __WINDOWS__ */ #endif /* __WINDOWS__ */
strcat(path, path_sep);
}
strcat(path, element); strcat(path, element);
} }
while (NULL != (element=va_arg(ap1, char*))) { while (NULL != (element=va_arg(ap1, char*))) {