Hi all,
In Phar we have an internal Windows-only function named
phar_unixify_path_separators(), which is needed because Phar is intended to
be used with web apps.
Phar inherits from SPL, which currently uses the system-specific
DEFAULT_SLASH when returning directory paths. This isn't actually a problem
in Phar (at least, as far as I'm aware) but it does look... well, untidy.
The attached patch implements spl_unixify_path_separators(). If it's
accepted, we can probably kill the version in Phar and rely on the
definition in SPL. However I'm concerned that some other extension might be
relying on SPL's current behaviour, unlikely tho' it may seem.
I haven't found any change in behaviour running the test suite for: ext/spl,
ext/phar, ext/standard/array, ext/simplexml. I haven't tested: ext/pdo,
ext/sqlite, ext/mysqli or pecl/spl_types, and I'm not certain if there
should be any more on that list.
If you find/can see any problems with this change at all, pls adv. If there
are no objections, I plan to commit at the end of this week.
Thanks,
- Steph
Index: ext/spl/spl_directory.c
===================================================================
RCS file: /repository/php-src/ext/spl/spl_directory.c,v
retrieving revision 1.45.2.27.2.23.2.22
diff -u -r1.45.2.27.2.23.2.22 spl_directory.c
--- ext/spl/spl_directory.c 18 Jun 2008 10:05:29 -0000
1.45.2.27.2.23.2.22
+++ ext/spl/spl_directory.c 18 Jun 2008 17:16:39 -0000
@@ -185,6 +185,9 @@
intern->file_name_len = spprintf(&intern->file_name, 0,
"%s%c%s",
spl_filesystem_object_get_path(intern, NULL TSRMLS_CC),
DEFAULT_SLASH,
intern->u.dir.entry.d_name);
+#ifdef PHP_WIN32
+ spl_unixify_path_separators(intern->file_name,
intern->file_name_len);
+#endif
break;
}
}
@@ -1196,6 +1199,9 @@
subdir->u.dir.sub_path_len =
strlen(intern->u.dir.entry.d_name);
subdir->u.dir.sub_path =
estrndup(intern->u.dir.entry.d_name, subdir->u.dir.sub_path_len);
}
+#ifdef PHP_WIN32
+ spl_unixify_path_separators(intern->u.dir.sub_path,
intern->u.dir.sub_path_len);
+#endif
subdir->info_class = intern->info_class;
subdir->file_class = intern->file_class;
subdir->oth = intern->oth;
@@ -1227,6 +1233,9 @@
if (intern->u.dir.sub_path) {
len = spprintf(&sub_name, 0, "%s%c%s", intern->u.dir.sub_path,
DEFAULT_SLASH, intern->u.dir.entry.d_name);
+#ifdef PHP_WIN32
+ spl_unixify_path_separators(sub_name, len);
+#endif
RETURN_STRINGL(sub_name, len, 0);
} else {
RETURN_STRING(intern->u.dir.entry.d_name, 1);
Index: ext/spl/spl_directory.h
===================================================================
RCS file: /repository/php-src/ext/spl/spl_directory.h,v
retrieving revision 1.12.2.5.2.4.2.10
diff -u -r1.12.2.5.2.4.2.10 spl_directory.h
--- ext/spl/spl_directory.h 20 May 2008 21:46:50 -0000
1.12.2.5.2.4.2.10
+++ ext/spl/spl_directory.h 18 Jun 2008 17:10:18 -0000
@@ -112,6 +112,20 @@
return (spl_filesystem_object*)((char*)it -
XtOffsetOf(spl_filesystem_object, it));
}
+#ifdef PHP_WIN32
+static inline void spl_unixify_path_separators(char *path, int path_len)
+{
+ char *s;
+
+ /* unixify win paths */
+ for (s = path; s - path < path_len; ++s) {
+ if (*s == '\\') {
+ *s = '/';
+ }
+ }
+}
+#endif
+
#define SPL_FILE_OBJECT_DROP_NEW_LINE 0x00000001 /* drop new lines */
#define SPL_FILE_OBJECT_READ_AHEAD 0x00000002 /* read on rewind/next */
#define SPL_FILE_OBJECT_SKIP_EMPTY 0x00000006 /* skip empty lines */
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php