forked from enlightenment/efl
Fix and simpligy windows behaviour.
Author: Vincent Torri
This commit is contained in:
parent
0a068ac549
commit
d234458dfc
|
@ -126,6 +126,7 @@ tests_evil_evil_suite_SOURCES = \
|
|||
tests/evil/evil_suite.c \
|
||||
tests/evil/evil_suite.h \
|
||||
tests/evil/evil_test_dlfcn.c \
|
||||
tests/evil/evil_test_libgen.c \
|
||||
tests/evil/evil_test_main.c \
|
||||
tests/evil/evil_test_stdio.c \
|
||||
tests/evil/evil_test_stdlib.c
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
#include <limits.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/stat.h>
|
||||
#include <libgen.h>
|
||||
|
||||
#include <Ecore_Evas.h>
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <pwd.h>
|
||||
#include <libgen.h>
|
||||
|
||||
#ifdef HAVE_SYSTEMD
|
||||
# include <systemd/sd-daemon.h>
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <libgen.h>
|
||||
|
||||
#include "Ecore.h"
|
||||
#include "ecore_private.h"
|
||||
|
|
|
@ -5,11 +5,8 @@
|
|||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifndef _MSC_VER
|
||||
# include <unistd.h>
|
||||
# include <libgen.h>
|
||||
#endif
|
||||
#include <unistd.h>
|
||||
#include <libgen.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
# include <direct.h>
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
#include <libgen.h>
|
||||
|
||||
#include <Efl.h>
|
||||
#include <Eina.h>
|
||||
|
|
|
@ -1,100 +0,0 @@
|
|||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif /* HAVE_CONFIG_H */
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "evil_macro.h"
|
||||
#include "evil_libgen.h"
|
||||
|
||||
char _evil_basename_buf[PATH_MAX];
|
||||
char _evil_dirname_buf[PATH_MAX];
|
||||
|
||||
char *
|
||||
evil_basename(char *path)
|
||||
{
|
||||
char *p1;
|
||||
char *p2;
|
||||
size_t length;
|
||||
|
||||
/* path must begin by "?:\" or "?:/" */
|
||||
if ((!path) || !evil_path_is_absolute(path))
|
||||
{
|
||||
memcpy(_evil_basename_buf, "C:\\", 4);
|
||||
return _evil_basename_buf;
|
||||
}
|
||||
|
||||
/* '/' --> '\\' */
|
||||
length = strlen(path);
|
||||
p1 = strdup(path);
|
||||
if (!p1)
|
||||
{
|
||||
memcpy(_evil_basename_buf, "C:\\", 4);
|
||||
return _evil_basename_buf;
|
||||
}
|
||||
|
||||
EVIL_PATH_SEP_UNIX_TO_WIN32(p1);
|
||||
|
||||
/* remove trailing backslashes */
|
||||
p2 = p1 + (length - 1);
|
||||
if (*p2 == '\\')
|
||||
{
|
||||
while (*p2 == '\\')
|
||||
p2--;
|
||||
}
|
||||
*(p2 + 1) = '\0';
|
||||
|
||||
p2 = strrchr(p1, '\\');
|
||||
memcpy(_evil_basename_buf, p2 + 1, (p1 + length + 1) - p2);
|
||||
|
||||
free(p1);
|
||||
|
||||
return _evil_basename_buf;
|
||||
}
|
||||
|
||||
char *
|
||||
evil_dirname(char *path)
|
||||
{
|
||||
char *p1;
|
||||
char *p2;
|
||||
size_t length;
|
||||
|
||||
/* path must begin by "?:\" or "?:/" */
|
||||
if ((!path) || !evil_path_is_absolute(path))
|
||||
{
|
||||
memcpy(_evil_dirname_buf, "C:\\", 4);
|
||||
return _evil_dirname_buf;
|
||||
}
|
||||
|
||||
/* '/' --> '\\' */
|
||||
length = strlen(path);
|
||||
p1 = strdup(path);
|
||||
if (!p1)
|
||||
{
|
||||
memcpy(_evil_dirname_buf, "C:\\", 4);
|
||||
return _evil_dirname_buf;
|
||||
}
|
||||
p2 = p1;
|
||||
while (*p2)
|
||||
{
|
||||
if (*p2 == '/') *p2 = '\\';
|
||||
p2++;
|
||||
}
|
||||
|
||||
/* remove trailing backslashes */
|
||||
p2 = p1 + (length - 1);
|
||||
if (*p2 == '\\')
|
||||
{
|
||||
while (*p2 == '\\')
|
||||
p2--;
|
||||
}
|
||||
*(p2 + 1) = '\0';
|
||||
|
||||
p2 = strrchr(p1, '\\');
|
||||
*p2 = '\0';
|
||||
memcpy(_evil_dirname_buf, p1, strlen(p1) + 1);
|
||||
|
||||
free(p1);
|
||||
|
||||
return _evil_dirname_buf;
|
||||
}
|
|
@ -1,89 +0,0 @@
|
|||
#ifndef __EVIL_LIBGEN_H__
|
||||
#define __EVIL_LIBGEN_H__
|
||||
|
||||
|
||||
/**
|
||||
* @file evil_libgen.h
|
||||
* @brief The file that provides functions ported from Unix in libgen.h.
|
||||
* @defgroup Evil_Libgen_Group Libgen.h functions.
|
||||
* @ingroup Evil
|
||||
*
|
||||
* This header provides functions ported from Unix in libgen.h.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Parse the base name component of a path.
|
||||
*
|
||||
* @param path The path to parse.
|
||||
* @return The component following the final '/'.
|
||||
*
|
||||
* This function parses @p path and returns its component following
|
||||
* the final '\'. Trailing '\' are not taken into account. On Windows
|
||||
* XP, @p path must beginning by a drive letter followed by ':/' or
|
||||
* ':\', otherwise "C:\" is returned. All characters '/' are replaced by '\'. On
|
||||
* error (memory allocation failure), "C:\" is returned, otherwise the
|
||||
* component following the final '\' is returned as a statically
|
||||
* allocated memory. Hence the returns value must not be freed.
|
||||
*
|
||||
* Concatenating the string returned by dirname(), a "\", and the
|
||||
* string returned by basename() yields a complete pathname.
|
||||
*
|
||||
* @see evil_dirname()
|
||||
* @see dirname()
|
||||
*
|
||||
* Conformity: Non applicable.
|
||||
*
|
||||
* Supported OS: Windows XP.
|
||||
*/
|
||||
EAPI char *evil_basename(char *path);
|
||||
|
||||
/**
|
||||
* @def basename(p)
|
||||
*
|
||||
* Wrapper around evil_basename().
|
||||
*/
|
||||
#define basename(p) evil_basename(p)
|
||||
|
||||
/**
|
||||
* @brief Parse the dir name component of a path.
|
||||
*
|
||||
* @param path The path to parse.
|
||||
* @return The component up to, but not including, the final '/'.
|
||||
*
|
||||
* This function parses @p path and returns its component up to, but
|
||||
* not including, the final '/'. Trailing '\' are not taken into
|
||||
* account. On Windows XP, @p path must beginning by a drive letter
|
||||
* followed by ':/' or ':\', otherwise "C:\" is returned. All
|
||||
* characters '/' are replaced by '\'. On error (memory allocation
|
||||
* failure), "C:\" is returned, otherwise, the component up to, but
|
||||
* not including, the final '/' is returned as a statically allocated
|
||||
* memory. Hence the returns value must not be freed.
|
||||
*
|
||||
* Concatenating the string returned by dirname(), a "\", and the
|
||||
* string returned by basename() yields a complete pathname.
|
||||
*
|
||||
* @see evil_basename()
|
||||
* @see basename()
|
||||
*
|
||||
* Conformity: Non applicable.
|
||||
*
|
||||
* Supported OS: Windows XP.
|
||||
*/
|
||||
EAPI char *evil_dirname(char *path);
|
||||
|
||||
/**
|
||||
* @def dirname(p)
|
||||
*
|
||||
* Wrapper around evil_dirname().
|
||||
*/
|
||||
#define dirname(p) evil_dirname(p)
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
#endif /* __EVIL_LIBGEN_H__ */
|
|
@ -2,6 +2,8 @@
|
|||
# include "elementary_config.h"
|
||||
#endif
|
||||
|
||||
#include <libgen.h>
|
||||
|
||||
#define ELM_INTERNAL_API_ARGESFSDFEFC
|
||||
|
||||
#include "elm_suite.h"
|
||||
|
|
|
@ -34,6 +34,7 @@ static const Efl_Test_Case etc[] = {
|
|||
/* { "Inet", evil_test_inet }, */
|
||||
/* { "Langinfo", evil_test_langinfo }, */
|
||||
/* { "Link", evil_test_link }, */
|
||||
{ "Libgen", evil_test_libgen },
|
||||
{ "Main", evil_test_main },
|
||||
/* { "Mman", evil_test_mman }, */
|
||||
/* { "Pwd", evil_test_pwd }, */
|
||||
|
|
|
@ -28,6 +28,7 @@ void evil_test_dlfcn(TCase *tc);
|
|||
/* void evil_test_inet(TCase *tc); */
|
||||
/* void evil_test_langinfo(TCase *tc); */
|
||||
/* void evil_test_link(TCase *tc); */
|
||||
void evil_test_libgen(TCase *tc);
|
||||
void evil_test_main(TCase *tc);
|
||||
/* void evil_test_mman(TCase *tc); */
|
||||
/* void evil_test_pwd(TCase *tc); */
|
||||
|
|
Loading…
Reference in New Issue