summaryrefslogtreecommitdiff
path: root/src/lib/evil
diff options
context:
space:
mode:
authorAndy Williams <andy@andywilliams.me>2017-12-31 16:08:31 +0000
committerAndy Williams <andy@andywilliams.me>2017-12-31 16:08:31 +0000
commitd234458dfcd9202c33f75049da6ebdad7888f4c5 (patch)
tree12f6e7584f1faf8e0e1dad1b940b69a31b1be8ba /src/lib/evil
parent0a068ac549e0dbdc27fec5925a99934ec09d9855 (diff)
Fix and simpligy windows behaviour.
Author: Vincent Torri
Diffstat (limited to 'src/lib/evil')
-rw-r--r--src/lib/evil/evil_libgen.c100
-rw-r--r--src/lib/evil/evil_libgen.h89
2 files changed, 0 insertions, 189 deletions
diff --git a/src/lib/evil/evil_libgen.c b/src/lib/evil/evil_libgen.c
deleted file mode 100644
index d96ba5bae8..0000000000
--- a/src/lib/evil/evil_libgen.c
+++ /dev/null
@@ -1,100 +0,0 @@
1#ifdef HAVE_CONFIG_H
2# include "config.h"
3#endif /* HAVE_CONFIG_H */
4
5#include <string.h>
6
7#include "evil_macro.h"
8#include "evil_libgen.h"
9
10char _evil_basename_buf[PATH_MAX];
11char _evil_dirname_buf[PATH_MAX];
12
13char *
14evil_basename(char *path)
15{
16 char *p1;
17 char *p2;
18 size_t length;
19
20 /* path must begin by "?:\" or "?:/" */
21 if ((!path) || !evil_path_is_absolute(path))
22 {
23 memcpy(_evil_basename_buf, "C:\\", 4);
24 return _evil_basename_buf;
25 }
26
27 /* '/' --> '\\' */
28 length = strlen(path);
29 p1 = strdup(path);
30 if (!p1)
31 {
32 memcpy(_evil_basename_buf, "C:\\", 4);
33 return _evil_basename_buf;
34 }
35
36 EVIL_PATH_SEP_UNIX_TO_WIN32(p1);
37
38 /* remove trailing backslashes */
39 p2 = p1 + (length - 1);
40 if (*p2 == '\\')
41 {
42 while (*p2 == '\\')
43 p2--;
44 }
45 *(p2 + 1) = '\0';
46
47 p2 = strrchr(p1, '\\');
48 memcpy(_evil_basename_buf, p2 + 1, (p1 + length + 1) - p2);
49
50 free(p1);
51
52 return _evil_basename_buf;
53}
54
55char *
56evil_dirname(char *path)
57{
58 char *p1;
59 char *p2;
60 size_t length;
61
62 /* path must begin by "?:\" or "?:/" */
63 if ((!path) || !evil_path_is_absolute(path))
64 {
65 memcpy(_evil_dirname_buf, "C:\\", 4);
66 return _evil_dirname_buf;
67 }
68
69 /* '/' --> '\\' */
70 length = strlen(path);
71 p1 = strdup(path);
72 if (!p1)
73 {
74 memcpy(_evil_dirname_buf, "C:\\", 4);
75 return _evil_dirname_buf;
76 }
77 p2 = p1;
78 while (*p2)
79 {
80 if (*p2 == '/') *p2 = '\\';
81 p2++;
82 }
83
84 /* remove trailing backslashes */
85 p2 = p1 + (length - 1);
86 if (*p2 == '\\')
87 {
88 while (*p2 == '\\')
89 p2--;
90 }
91 *(p2 + 1) = '\0';
92
93 p2 = strrchr(p1, '\\');
94 *p2 = '\0';
95 memcpy(_evil_dirname_buf, p1, strlen(p1) + 1);
96
97 free(p1);
98
99 return _evil_dirname_buf;
100}
diff --git a/src/lib/evil/evil_libgen.h b/src/lib/evil/evil_libgen.h
deleted file mode 100644
index b832d620ed..0000000000
--- a/src/lib/evil/evil_libgen.h
+++ /dev/null
@@ -1,89 +0,0 @@
1#ifndef __EVIL_LIBGEN_H__
2#define __EVIL_LIBGEN_H__
3
4
5/**
6 * @file evil_libgen.h
7 * @brief The file that provides functions ported from Unix in libgen.h.
8 * @defgroup Evil_Libgen_Group Libgen.h functions.
9 * @ingroup Evil
10 *
11 * This header provides functions ported from Unix in libgen.h.
12 *
13 * @{
14 */
15
16/**
17 * @brief Parse the base name component of a path.
18 *
19 * @param path The path to parse.
20 * @return The component following the final '/'.
21 *
22 * This function parses @p path and returns its component following
23 * the final '\'. Trailing '\' are not taken into account. On Windows
24 * XP, @p path must beginning by a drive letter followed by ':/' or
25 * ':\', otherwise "C:\" is returned. All characters '/' are replaced by '\'. On
26 * error (memory allocation failure), "C:\" is returned, otherwise the
27 * component following the final '\' is returned as a statically
28 * allocated memory. Hence the returns value must not be freed.
29 *
30 * Concatenating the string returned by dirname(), a "\", and the
31 * string returned by basename() yields a complete pathname.
32 *
33 * @see evil_dirname()
34 * @see dirname()
35 *
36 * Conformity: Non applicable.
37 *
38 * Supported OS: Windows XP.
39 */
40EAPI char *evil_basename(char *path);
41
42/**
43 * @def basename(p)
44 *
45 * Wrapper around evil_basename().
46 */
47#define basename(p) evil_basename(p)
48
49/**
50 * @brief Parse the dir name component of a path.
51 *
52 * @param path The path to parse.
53 * @return The component up to, but not including, the final '/'.
54 *
55 * This function parses @p path and returns its component up to, but
56 * not including, the final '/'. Trailing '\' are not taken into
57 * account. On Windows XP, @p path must beginning by a drive letter
58 * followed by ':/' or ':\', otherwise "C:\" is returned. All
59 * characters '/' are replaced by '\'. On error (memory allocation
60 * failure), "C:\" is returned, otherwise, the component up to, but
61 * not including, the final '/' is returned as a statically allocated
62 * memory. Hence the returns value must not be freed.
63 *
64 * Concatenating the string returned by dirname(), a "\", and the
65 * string returned by basename() yields a complete pathname.
66 *
67 * @see evil_basename()
68 * @see basename()
69 *
70 * Conformity: Non applicable.
71 *
72 * Supported OS: Windows XP.
73 */
74EAPI char *evil_dirname(char *path);
75
76/**
77 * @def dirname(p)
78 *
79 * Wrapper around evil_dirname().
80 */
81#define dirname(p) evil_dirname(p)
82
83
84/**
85 * @}
86 */
87
88
89#endif /* __EVIL_LIBGEN_H__ */