summaryrefslogtreecommitdiff
path: root/win32
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
commite4602e1d275752f38a84c89ce4ddb87826f4fa17 (patch)
tree02e19c995b059a884c3c64633dcff93214b53842 /win32
parent2a9733a5c24cf57bc4774a97c1bb1b08337284e1 (diff)
* 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/trunk@10201 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'win32')
-rw-r--r--win32/win32.c49
1 files changed, 30 insertions, 19 deletions
diff --git a/win32/win32.c b/win32/win32.c
index 999ff68044..62a65d2346 100644
--- a/win32/win32.c
+++ b/win32/win32.c
@@ -2933,34 +2933,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;
-#undef getcwd
-#ifndef __BORLANDC__
-#define getcwd _getcwd
-#endif
- errno = 0;
- SetLastError(0);
- if (getcwd(buffer, size) == NULL) {
- if (!errno)
- errno = GetLastError() ? map_errno(GetLastError()) : ERANGE;
- return NULL;
+ len = GetCurrentDirectory(0, NULL);
+ if (!len) {
+ errno = map_errno(GetLastError());
+ return NULL;
}
- length = strlen(buffer);
- if (length >= size) {
- errno = ERANGE;
- return NULL;
+
+ if (p) {
+ if (size < len) {
+ errno = ERANGE;
+ return NULL;
+ }
+ }
+ else {
+ p = malloc(len);
+ size = len;
+ if (!p) {
+ errno = ENOMEM;
+ 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