summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2006-06-01 07:18:12 +0000
committerusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2006-06-01 07:18:12 +0000
commit02821cc03880c453797755f96a849d82920a4060 (patch)
tree3a0aad3ca3d32bbbd2177823f61c6222222af847
parent0395b953b51105a0f221dd46bca08dcca4f85e03 (diff)
downloadruby-02821cc03880c453797755f96a849d82920a4060.tar.gz
* win32/win32.c (rb_w32_getcwd): runtime's getcwd() will not success
if the length of the cwd is longer than MAX_PATH. fixed [ruby-list:42335] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@10201 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog6
-rw-r--r--win32/win32.c46
2 files changed, 36 insertions, 16 deletions
diff --git a/ChangeLog b/ChangeLog
index 1b2a8b8fc1..0420366a5d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Thu Jun 1 16:14:41 2006 NAKAMURA Usaku <usa@ruby-lang.org>
+
+ * win32/win32.c (rb_w32_getcwd): runtime's getcwd() will not success
+ if the length of the cwd is longer than MAX_PATH.
+ fixed [ruby-list:42335]
+
Thu Jun 1 11:29:14 2006 NAKAMURA Usaku <usa@ruby-lang.org>
* win32/win32.c (rb_w32_getcwd): set errno if not set.
diff --git a/win32/win32.c b/win32/win32.c
index c044efdd22..f06073e001 100644
--- a/win32/win32.c
+++ b/win32/win32.c
@@ -2609,31 +2609,45 @@ gettimeofday(struct timeval *tv, struct timezone *tz)
char *
rb_w32_getcwd(char *buffer, int size)
{
- int length;
+ char *p = buffer;
char *bp;
- int save_errno = errno;
+ int len;
+
+ len = GetCurrentDirectory(0, NULL);
+ if (!len) {
+ errno = map_errno(GetLastError());
+ return NULL;
+ }
-#undef getcwd
- errno = 0;
- SetLastError(0);
- if (getcwd(buffer, size) == NULL) {
- if (!errno)
- errno = GetLastError() ? map_errno(GetLastError()) : ERANGE;
- return NULL;
+ if (p) {
+ if (size < len) {
+ errno = ERANGE;
+ return NULL;
+ }
+ }
+ else {
+ p = malloc(len);
+ size = len;
+ if (!p) {
+ errno = ENOMEM;
+ return NULL;
+ }
}
- length = strlen(buffer);
- if (length >= size) {
- errno = ERANGE;
- return NULL;
+
+ if (!GetCurrentDirectory(size, p)) {
+ errno = map_errno(GetLastError());
+ if (!buffer)
+ free(p);
+ return NULL;
}
- errno = save_errno;
- for (bp = buffer; *bp != '\0'; bp = CharNext(bp)) {
+ for (bp = p; *bp != '\0'; bp = CharNext(bp)) {
if (*bp == '\\') {
*bp = '/';
}
}
- return buffer;
+
+ return p;
}
int