mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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
This commit is contained in:
parent
2a9733a5c2
commit
e4602e1d27
2 changed files with 37 additions and 20 deletions
|
@ -1,3 +1,9 @@
|
||||||
|
Thu Jun 1 16:17:26 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:33:32 2006 NAKAMURA Usaku <usa@ruby-lang.org>
|
Thu Jun 1 11:33:32 2006 NAKAMURA Usaku <usa@ruby-lang.org>
|
||||||
|
|
||||||
* win32/win32.c (rb_w32_getcwd): set errno if not set.
|
* win32/win32.c (rb_w32_getcwd): set errno if not set.
|
||||||
|
|
|
@ -2933,34 +2933,45 @@ gettimeofday(struct timeval *tv, struct timezone *tz)
|
||||||
char *
|
char *
|
||||||
rb_w32_getcwd(char *buffer, int size)
|
rb_w32_getcwd(char *buffer, int size)
|
||||||
{
|
{
|
||||||
int length;
|
char *p = buffer;
|
||||||
char *bp;
|
char *bp;
|
||||||
int save_errno = errno;
|
int len;
|
||||||
|
|
||||||
#undef getcwd
|
len = GetCurrentDirectory(0, NULL);
|
||||||
#ifndef __BORLANDC__
|
if (!len) {
|
||||||
#define getcwd _getcwd
|
errno = map_errno(GetLastError());
|
||||||
#endif
|
return NULL;
|
||||||
errno = 0;
|
|
||||||
SetLastError(0);
|
|
||||||
if (getcwd(buffer, size) == NULL) {
|
|
||||||
if (!errno)
|
|
||||||
errno = GetLastError() ? map_errno(GetLastError()) : ERANGE;
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
length = strlen(buffer);
|
|
||||||
if (length >= size) {
|
|
||||||
errno = ERANGE;
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
errno = save_errno;
|
|
||||||
|
|
||||||
for (bp = buffer; *bp != '\0'; bp = CharNext(bp)) {
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (bp = p; *bp != '\0'; bp = CharNext(bp)) {
|
||||||
if (*bp == '\\') {
|
if (*bp == '\\') {
|
||||||
*bp = '/';
|
*bp = '/';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return buffer;
|
|
||||||
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
|
Loading…
Add table
Reference in a new issue