2000-05-01 05:42:38 -04:00
|
|
|
/**********************************************************************
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
util.c -
|
|
|
|
|
|
|
|
$Author$
|
|
|
|
$Date$
|
|
|
|
created at: Fri Mar 10 17:22:34 JST 1995
|
|
|
|
|
2003-01-16 02:34:03 -05:00
|
|
|
Copyright (C) 1993-2003 Yukihiro Matsumoto
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2000-05-01 05:42:38 -04:00
|
|
|
**********************************************************************/
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2002-05-14 02:22:31 -04:00
|
|
|
#include "ruby.h"
|
|
|
|
|
2002-05-29 01:20:39 -04:00
|
|
|
#include <ctype.h>
|
1999-01-19 23:59:39 -05:00
|
|
|
#include <stdio.h>
|
2001-11-08 01:43:14 -05:00
|
|
|
#include <errno.h>
|
1999-01-19 23:59:39 -05:00
|
|
|
|
* configure.in, defines.h, dir.c, dir.h, dln.c, error.c,
eval.c, file.c, hash.c, io.c, main.c, missing.c,
process.c, ruby.c, rubysig.h, signal.c, st.c, util.c, util.h,
bcc/Makefile.sub, win32/Makefile.sub, win32/win32.h,
ext/Win32API/Win32API.c, ext/socket/getaddrinfo.c,
ext/socket/getnameinfo.c, ext/socket/socket.c,
ext/tcltklib/stubs.c
: replace "NT" with "_WIN32", add DOSISH_DRIVE_LETTER
* wince/exe.mak : delete \r at the end of lines.
* wince/mswince-ruby17.def : delete rb_obj_become
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3148 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-12-14 22:18:08 -05:00
|
|
|
#ifdef _WIN32
|
1999-01-19 23:59:39 -05:00
|
|
|
#include "missing/file.h"
|
|
|
|
#endif
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
#include "util.h"
|
1998-01-16 07:19:22 -05:00
|
|
|
#ifndef HAVE_STRING_H
|
* bignum.c: changed `foo _((boo))' to `foo(boo)`. [ruby-dev:27056]
* defines.h, dir.c, dln.h, enumerator.c, env.h, error.c, eval.c, file.c,
gc.c, hash.c, inits.c, intern.h, io.c, lex.c, marshal.c, missing.h,
node.h, numeric.c, pack.c, process.c, re.h, ruby.c, ruby.h, rubyio.h,
rubysig.h, signal.c, sprintf.c, st.h, string.c, struct.c, time.c,
util.c, util.h, variable.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9155 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-14 02:32:32 -04:00
|
|
|
char *strchr(char*,char);
|
1998-01-16 07:13:05 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
unsigned long
|
|
|
|
scan_oct(start, len, retlen)
|
2002-08-28 04:05:23 -04:00
|
|
|
const char *start;
|
|
|
|
int len;
|
|
|
|
int *retlen;
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
1999-08-13 01:45:20 -04:00
|
|
|
register const char *s = start;
|
1998-01-16 07:13:05 -05:00
|
|
|
register unsigned long retval = 0;
|
|
|
|
|
|
|
|
while (len-- && *s >= '0' && *s <= '7') {
|
|
|
|
retval <<= 3;
|
|
|
|
retval |= *s++ - '0';
|
|
|
|
}
|
|
|
|
*retlen = s - start;
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned long
|
|
|
|
scan_hex(start, len, retlen)
|
2002-08-28 04:05:23 -04:00
|
|
|
const char *start;
|
|
|
|
int len;
|
|
|
|
int *retlen;
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2001-11-28 09:56:32 -05:00
|
|
|
static char hexdigit[] = "0123456789abcdef0123456789ABCDEF";
|
1999-08-13 01:45:20 -04:00
|
|
|
register const char *s = start;
|
1998-01-16 07:13:05 -05:00
|
|
|
register unsigned long retval = 0;
|
|
|
|
char *tmp;
|
|
|
|
|
|
|
|
while (len-- && *s && (tmp = strchr(hexdigit, *s))) {
|
|
|
|
retval <<= 4;
|
|
|
|
retval |= (tmp - hexdigit) & 15;
|
|
|
|
s++;
|
|
|
|
}
|
|
|
|
*retlen = s - start;
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
1999-08-13 01:45:20 -04:00
|
|
|
#if defined(HAVE_FCNTL_H)
|
1998-01-16 07:13:05 -05:00
|
|
|
#include <fcntl.h>
|
1999-01-19 23:59:39 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef S_ISDIR
|
|
|
|
# define S_ISDIR(m) ((m & S_IFMT) == S_IFDIR)
|
|
|
|
#endif
|
|
|
|
|
* configure.in, defines.h, dir.c, dir.h, dln.c, error.c,
eval.c, file.c, hash.c, io.c, main.c, missing.c,
process.c, ruby.c, rubysig.h, signal.c, st.c, util.c, util.h,
bcc/Makefile.sub, win32/Makefile.sub, win32/win32.h,
ext/Win32API/Win32API.c, ext/socket/getaddrinfo.c,
ext/socket/getnameinfo.c, ext/socket/socket.c,
ext/tcltklib/stubs.c
: replace "NT" with "_WIN32", add DOSISH_DRIVE_LETTER
* wince/exe.mak : delete \r at the end of lines.
* wince/mswince-ruby17.def : delete rb_obj_become
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3148 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-12-14 22:18:08 -05:00
|
|
|
#if defined(MSDOS) || defined(__CYGWIN32__) || defined(_WIN32)
|
1998-01-16 07:13:05 -05:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1993, Intergraph Corporation
|
|
|
|
*
|
|
|
|
* You may distribute under the terms of either the GNU General Public
|
|
|
|
* License or the Artistic License, as specified in the perl README file.
|
|
|
|
*
|
|
|
|
* Various Unix compatibility functions and NT specific functions.
|
|
|
|
*
|
|
|
|
* Some of this code was derived from the MSDOS port(s) and the OS/2 port.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Suffix appending for in-place editing under MS-DOS and OS/2 (and now NT!).
|
|
|
|
*
|
|
|
|
* Here are the rules:
|
|
|
|
*
|
|
|
|
* Style 0: Append the suffix exactly as standard perl would do it.
|
|
|
|
* If the filesystem groks it, use it. (HPFS will always
|
|
|
|
* grok it. So will NTFS. FAT will rarely accept it.)
|
|
|
|
*
|
|
|
|
* Style 1: The suffix begins with a '.'. The extension is replaced.
|
|
|
|
* If the name matches the original name, use the fallback method.
|
|
|
|
*
|
|
|
|
* Style 2: The suffix is a single character, not a '.'. Try to add the
|
|
|
|
* suffix to the following places, using the first one that works.
|
|
|
|
* [1] Append to extension.
|
|
|
|
* [2] Append to filename,
|
|
|
|
* [3] Replace end of extension,
|
|
|
|
* [4] Replace end of filename.
|
|
|
|
* If the name matches the original name, use the fallback method.
|
|
|
|
*
|
|
|
|
* Style 3: Any other case: Ignore the suffix completely and use the
|
|
|
|
* fallback method.
|
|
|
|
*
|
|
|
|
* Fallback method: Change the extension to ".$$$". If that matches the
|
|
|
|
* original name, then change the extension to ".~~~".
|
|
|
|
*
|
|
|
|
* If filename is more than 1000 characters long, we die a horrible
|
|
|
|
* death. Sorry.
|
|
|
|
*
|
|
|
|
* The filename restriction is a cheat so that we can use buf[] to store
|
|
|
|
* assorted temporary goo.
|
|
|
|
*
|
|
|
|
* Examples, assuming style 0 failed.
|
|
|
|
*
|
|
|
|
* suffix = ".bak" (style 1)
|
|
|
|
* foo.bar => foo.bak
|
|
|
|
* foo.bak => foo.$$$ (fallback)
|
|
|
|
* foo.$$$ => foo.~~~ (fallback)
|
|
|
|
* makefile => makefile.bak
|
|
|
|
*
|
|
|
|
* suffix = "~" (style 2)
|
|
|
|
* foo.c => foo.c~
|
|
|
|
* foo.c~ => foo.c~~
|
|
|
|
* foo.c~~ => foo~.c~~
|
|
|
|
* foo~.c~~ => foo~~.c~~
|
|
|
|
* foo~~~~~.c~~ => foo~~~~~.$$$ (fallback)
|
|
|
|
*
|
|
|
|
* foo.pas => foo~.pas
|
|
|
|
* makefile => makefile.~
|
|
|
|
* longname.fil => longname.fi~
|
|
|
|
* longname.fi~ => longnam~.fi~
|
|
|
|
* longnam~.fi~ => longnam~.$$$
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
static int valid_filename(char *s);
|
|
|
|
|
|
|
|
static char suffix1[] = ".$$$";
|
|
|
|
static char suffix2[] = ".~~~";
|
|
|
|
|
|
|
|
#define ext (&buf[1000])
|
|
|
|
|
|
|
|
#define strEQ(s1,s2) (strcmp(s1,s2) == 0)
|
|
|
|
|
|
|
|
void
|
1999-01-19 23:59:39 -05:00
|
|
|
ruby_add_suffix(str, suffix)
|
|
|
|
VALUE str;
|
|
|
|
char *suffix;
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
|
|
|
int baselen;
|
|
|
|
int extlen = strlen(suffix);
|
|
|
|
char *s, *t, *p;
|
2002-08-21 11:47:54 -04:00
|
|
|
long slen;
|
1998-01-16 07:13:05 -05:00
|
|
|
char buf[1024];
|
|
|
|
|
1998-01-16 07:19:22 -05:00
|
|
|
if (RSTRING(str)->len > 1000)
|
2002-05-28 14:11:07 -04:00
|
|
|
rb_fatal("Cannot do inplace edit on long filename (%ld characters)",
|
1999-01-19 23:59:39 -05:00
|
|
|
RSTRING(str)->len);
|
1998-01-16 07:13:05 -05:00
|
|
|
|
* configure.in, defines.h, dir.c, dir.h, dln.c, error.c,
eval.c, file.c, hash.c, io.c, main.c, missing.c,
process.c, ruby.c, rubysig.h, signal.c, st.c, util.c, util.h,
bcc/Makefile.sub, win32/Makefile.sub, win32/win32.h,
ext/Win32API/Win32API.c, ext/socket/getaddrinfo.c,
ext/socket/getnameinfo.c, ext/socket/socket.c,
ext/tcltklib/stubs.c
: replace "NT" with "_WIN32", add DOSISH_DRIVE_LETTER
* wince/exe.mak : delete \r at the end of lines.
* wince/mswince-ruby17.def : delete rb_obj_become
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3148 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-12-14 22:18:08 -05:00
|
|
|
#if defined(DJGPP) || defined(__CYGWIN32__) || defined(_WIN32)
|
1998-01-16 07:13:05 -05:00
|
|
|
/* Style 0 */
|
1998-01-16 07:19:22 -05:00
|
|
|
slen = RSTRING(str)->len;
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_str_cat(str, suffix, extlen);
|
1998-01-16 07:13:05 -05:00
|
|
|
#if defined(DJGPP)
|
|
|
|
if (_USE_LFN) return;
|
|
|
|
#else
|
1998-01-16 07:19:22 -05:00
|
|
|
if (valid_filename(RSTRING(str)->ptr)) return;
|
1998-01-16 07:13:05 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Fooey, style 0 failed. Fix str before continuing. */
|
1998-01-16 07:19:22 -05:00
|
|
|
RSTRING(str)->ptr[RSTRING(str)->len = slen] = '\0';
|
1998-01-16 07:13:05 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
slen = extlen;
|
1998-01-16 07:19:22 -05:00
|
|
|
t = buf; baselen = 0; s = RSTRING(str)->ptr;
|
1999-08-13 01:45:20 -04:00
|
|
|
while ((*t = *s) && *s != '.') {
|
1998-01-16 07:13:05 -05:00
|
|
|
baselen++;
|
|
|
|
if (*s == '\\' || *s == '/') baselen = 0;
|
|
|
|
s++; t++;
|
|
|
|
}
|
|
|
|
p = t;
|
|
|
|
|
|
|
|
t = ext; extlen = 0;
|
|
|
|
while (*t++ = *s++) extlen++;
|
|
|
|
if (extlen == 0) { ext[0] = '.'; ext[1] = 0; extlen++; }
|
|
|
|
|
|
|
|
if (*suffix == '.') { /* Style 1 */
|
|
|
|
if (strEQ(ext, suffix)) goto fallback;
|
|
|
|
strcpy(p, suffix);
|
2001-05-02 00:22:21 -04:00
|
|
|
}
|
|
|
|
else if (suffix[1] == '\0') { /* Style 2 */
|
1998-01-16 07:13:05 -05:00
|
|
|
if (extlen < 4) {
|
|
|
|
ext[extlen] = *suffix;
|
|
|
|
ext[++extlen] = '\0';
|
2001-05-02 00:22:21 -04:00
|
|
|
}
|
|
|
|
else if (baselen < 8) {
|
1998-01-16 07:13:05 -05:00
|
|
|
*p++ = *suffix;
|
2001-05-02 00:22:21 -04:00
|
|
|
}
|
|
|
|
else if (ext[3] != *suffix) {
|
1998-01-16 07:13:05 -05:00
|
|
|
ext[3] = *suffix;
|
2001-05-02 00:22:21 -04:00
|
|
|
}
|
|
|
|
else if (buf[7] != *suffix) {
|
1998-01-16 07:13:05 -05:00
|
|
|
buf[7] = *suffix;
|
2001-05-02 00:22:21 -04:00
|
|
|
}
|
|
|
|
else goto fallback;
|
1998-01-16 07:13:05 -05:00
|
|
|
strcpy(p, ext);
|
2001-05-02 00:22:21 -04:00
|
|
|
}
|
|
|
|
else { /* Style 3: Panic */
|
1998-01-16 07:13:05 -05:00
|
|
|
fallback:
|
|
|
|
(void)memcpy(p, strEQ(ext, suffix1) ? suffix2 : suffix1, 5);
|
|
|
|
}
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_str_resize(str, strlen(buf));
|
1998-01-16 07:19:22 -05:00
|
|
|
memcpy(RSTRING(str)->ptr, buf, RSTRING(str)->len);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
* configure.in, defines.h, dir.c, dir.h, dln.c, error.c,
eval.c, file.c, hash.c, io.c, main.c, missing.c,
process.c, ruby.c, rubysig.h, signal.c, st.c, util.c, util.h,
bcc/Makefile.sub, win32/Makefile.sub, win32/win32.h,
ext/Win32API/Win32API.c, ext/socket/getaddrinfo.c,
ext/socket/getnameinfo.c, ext/socket/socket.c,
ext/tcltklib/stubs.c
: replace "NT" with "_WIN32", add DOSISH_DRIVE_LETTER
* wince/exe.mak : delete \r at the end of lines.
* wince/mswince-ruby17.def : delete rb_obj_become
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3148 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-12-14 22:18:08 -05:00
|
|
|
#if defined(__CYGWIN32__) || defined(_WIN32)
|
1998-01-16 07:13:05 -05:00
|
|
|
static int
|
|
|
|
valid_filename(char *s)
|
|
|
|
{
|
|
|
|
int fd;
|
|
|
|
|
|
|
|
/*
|
|
|
|
// if the file exists, then it's a valid filename!
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (_access(s, 0) == 0) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
// It doesn't exist, so see if we can open it.
|
|
|
|
*/
|
2003-04-17 12:49:23 -04:00
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
if ((fd = _open(s, O_CREAT, 0666)) >= 0) {
|
|
|
|
_close(fd);
|
2003-04-17 12:49:23 -04:00
|
|
|
_unlink(s); /* don't leave it laying around */
|
1998-01-16 07:13:05 -05:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2000-12-18 09:22:37 -05:00
|
|
|
#if defined __DJGPP__
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2000-12-18 09:22:37 -05:00
|
|
|
#include <dpmi.h>
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2000-12-18 09:22:37 -05:00
|
|
|
static char dbcs_table[256];
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2000-12-18 09:22:37 -05:00
|
|
|
int
|
|
|
|
make_dbcs_table()
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
|
|
|
__dpmi_regs r;
|
2000-12-18 09:22:37 -05:00
|
|
|
struct {
|
|
|
|
unsigned char start;
|
|
|
|
unsigned char end;
|
|
|
|
} vec;
|
|
|
|
int offset;
|
|
|
|
|
|
|
|
memset(&r, 0, sizeof(r));
|
|
|
|
r.x.ax = 0x6300;
|
1998-01-16 07:13:05 -05:00
|
|
|
__dpmi_int(0x21, &r);
|
2000-12-18 09:22:37 -05:00
|
|
|
offset = r.x.ds * 16 + r.x.si;
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
int i;
|
|
|
|
dosmemget(offset, sizeof vec, &vec);
|
|
|
|
if (!vec.start && !vec.end)
|
|
|
|
break;
|
|
|
|
for (i = vec.start; i <= vec.end; i++)
|
|
|
|
dbcs_table[i] = 1;
|
|
|
|
offset += 2;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
2000-12-18 09:22:37 -05:00
|
|
|
}
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2000-12-18 09:22:37 -05:00
|
|
|
int
|
|
|
|
mblen(const char *s, size_t n)
|
|
|
|
{
|
|
|
|
static int need_init = 1;
|
|
|
|
if (need_init) {
|
|
|
|
make_dbcs_table();
|
|
|
|
need_init = 0;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
2000-12-18 09:22:37 -05:00
|
|
|
if (s) {
|
|
|
|
if (n == 0 || *s == 0)
|
|
|
|
return 0;
|
2004-01-29 09:56:26 -05:00
|
|
|
else if (!s[1])
|
|
|
|
return 1;
|
2000-12-18 09:22:37 -05:00
|
|
|
return dbcs_table[(unsigned char)*s] + 1;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
2000-12-18 09:22:37 -05:00
|
|
|
else
|
|
|
|
return 1;
|
|
|
|
}
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2000-12-18 09:22:37 -05:00
|
|
|
struct PathList {
|
|
|
|
struct PathList *next;
|
|
|
|
char *path;
|
|
|
|
};
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2000-12-18 09:22:37 -05:00
|
|
|
struct PathInfo {
|
|
|
|
struct PathList *head;
|
|
|
|
int count;
|
|
|
|
};
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2000-12-18 09:22:37 -05:00
|
|
|
static void
|
2002-03-23 11:07:55 -05:00
|
|
|
push_element(const char *path, VALUE vinfo)
|
2000-12-18 09:22:37 -05:00
|
|
|
{
|
|
|
|
struct PathList *p;
|
2002-03-23 11:07:55 -05:00
|
|
|
struct PathInfo *info = (struct PathInfo *)vinfo;
|
2000-12-18 09:22:37 -05:00
|
|
|
|
|
|
|
p = ALLOC(struct PathList);
|
|
|
|
MEMZERO(p, struct PathList, 1);
|
|
|
|
p->path = ruby_strdup(path);
|
|
|
|
p->next = info->head;
|
|
|
|
info->head = p;
|
|
|
|
info->count++;
|
|
|
|
}
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2000-12-18 09:22:37 -05:00
|
|
|
#include <dirent.h>
|
|
|
|
int __opendir_flags = __OPENDIR_PRESERVE_CASE;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2000-12-18 09:22:37 -05:00
|
|
|
char **
|
|
|
|
__crt0_glob_function(char *path)
|
|
|
|
{
|
|
|
|
int len = strlen(path);
|
|
|
|
int i;
|
|
|
|
char **rv;
|
|
|
|
char path_buffer[PATH_MAX];
|
|
|
|
char *buf = path_buffer;
|
|
|
|
char *p;
|
|
|
|
struct PathInfo info;
|
|
|
|
struct PathList *plist;
|
|
|
|
|
|
|
|
if (PATH_MAX <= len)
|
|
|
|
buf = ruby_xmalloc(len + 1);
|
|
|
|
|
|
|
|
strncpy(buf, path, len);
|
|
|
|
buf[len] = '\0';
|
|
|
|
|
2004-01-21 10:26:11 -05:00
|
|
|
for (p = buf; *p; p += mblen(p, RUBY_MBCHAR_MAXSIZE))
|
2000-12-18 09:22:37 -05:00
|
|
|
if (*p == '\\')
|
|
|
|
*p = '/';
|
|
|
|
|
|
|
|
info.count = 0;
|
|
|
|
info.head = 0;
|
|
|
|
|
2004-01-29 03:05:29 -05:00
|
|
|
rb_glob(buf, push_element, (VALUE)&info);
|
2000-12-18 09:22:37 -05:00
|
|
|
|
|
|
|
if (buf != path_buffer)
|
|
|
|
ruby_xfree(buf);
|
|
|
|
|
|
|
|
if (info.count == 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
rv = ruby_xmalloc((info.count + 1) * sizeof (char *));
|
|
|
|
|
|
|
|
plist = info.head;
|
|
|
|
i = 0;
|
|
|
|
while (plist) {
|
|
|
|
struct PathList *cur;
|
|
|
|
rv[i] = plist->path;
|
|
|
|
cur = plist;
|
|
|
|
plist = plist->next;
|
|
|
|
ruby_xfree(cur);
|
|
|
|
i++;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
2000-12-18 09:22:37 -05:00
|
|
|
rv[i] = 0;
|
|
|
|
return rv;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
2000-12-18 09:22:37 -05:00
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
#endif
|
1999-01-19 23:59:39 -05:00
|
|
|
|
|
|
|
/* mm.c */
|
|
|
|
|
|
|
|
#define A ((int*)a)
|
|
|
|
#define B ((int*)b)
|
|
|
|
#define C ((int*)c)
|
|
|
|
#define D ((int*)d)
|
|
|
|
|
2001-12-10 02:18:16 -05:00
|
|
|
#define mmprepare(base, size) do {\
|
|
|
|
if (((long)base & (0x3)) == 0)\
|
|
|
|
if (size >= 16) mmkind = 1;\
|
|
|
|
else mmkind = 0;\
|
|
|
|
else mmkind = -1;\
|
|
|
|
high = (size & (~0xf));\
|
|
|
|
low = (size & 0x0c);\
|
|
|
|
} while (0)\
|
1999-01-19 23:59:39 -05:00
|
|
|
|
2001-12-10 02:18:16 -05:00
|
|
|
#define mmarg mmkind, size, high, low
|
1999-01-19 23:59:39 -05:00
|
|
|
|
2001-12-10 02:18:16 -05:00
|
|
|
static void mmswap_(a, b, mmarg)
|
|
|
|
register char *a, *b;
|
|
|
|
int mmarg;
|
1999-01-19 23:59:39 -05:00
|
|
|
{
|
|
|
|
register int s;
|
|
|
|
if (a == b) return;
|
|
|
|
if (mmkind >= 0) {
|
|
|
|
if (mmkind > 0) {
|
|
|
|
register char *t = a + high;
|
|
|
|
do {
|
|
|
|
s = A[0]; A[0] = B[0]; B[0] = s;
|
|
|
|
s = A[1]; A[1] = B[1]; B[1] = s;
|
|
|
|
s = A[2]; A[2] = B[2]; B[2] = s;
|
|
|
|
s = A[3]; A[3] = B[3]; B[3] = s; a += 16; b += 16;
|
1999-08-13 01:45:20 -04:00
|
|
|
} while (a < t);
|
1999-01-19 23:59:39 -05:00
|
|
|
}
|
|
|
|
if (low != 0) { s = A[0]; A[0] = B[0]; B[0] = s;
|
|
|
|
if (low >= 8) { s = A[1]; A[1] = B[1]; B[1] = s;
|
|
|
|
if (low == 12) {s = A[2]; A[2] = B[2]; B[2] = s;}}}
|
2001-05-02 00:22:21 -04:00
|
|
|
}
|
|
|
|
else {
|
2001-12-10 02:18:16 -05:00
|
|
|
register char *t = a + size;
|
1999-01-19 23:59:39 -05:00
|
|
|
do {s = *a; *a++ = *b; *b++ = s;} while (a < t);
|
|
|
|
}
|
|
|
|
}
|
2001-12-10 02:18:16 -05:00
|
|
|
#define mmswap(a,b) mmswap_((a),(b),mmarg)
|
1999-01-19 23:59:39 -05:00
|
|
|
|
2001-12-10 02:18:16 -05:00
|
|
|
static void mmrot3_(a, b, c, mmarg)
|
|
|
|
register char *a, *b, *c;
|
|
|
|
int mmarg;
|
1999-01-19 23:59:39 -05:00
|
|
|
{
|
|
|
|
register int s;
|
|
|
|
if (mmkind >= 0) {
|
|
|
|
if (mmkind > 0) {
|
|
|
|
register char *t = a + high;
|
|
|
|
do {
|
|
|
|
s = A[0]; A[0] = B[0]; B[0] = C[0]; C[0] = s;
|
|
|
|
s = A[1]; A[1] = B[1]; B[1] = C[1]; C[1] = s;
|
|
|
|
s = A[2]; A[2] = B[2]; B[2] = C[2]; C[2] = s;
|
|
|
|
s = A[3]; A[3] = B[3]; B[3] = C[3]; C[3] = s; a += 16; b += 16; c += 16;
|
2001-05-02 00:22:21 -04:00
|
|
|
} while (a < t);
|
1999-01-19 23:59:39 -05:00
|
|
|
}
|
|
|
|
if (low != 0) { s = A[0]; A[0] = B[0]; B[0] = C[0]; C[0] = s;
|
|
|
|
if (low >= 8) { s = A[1]; A[1] = B[1]; B[1] = C[1]; C[1] = s;
|
|
|
|
if (low == 12) {s = A[2]; A[2] = B[2]; B[2] = C[2]; C[2] = s;}}}
|
2001-05-02 00:22:21 -04:00
|
|
|
}
|
|
|
|
else {
|
2001-12-10 02:18:16 -05:00
|
|
|
register char *t = a + size;
|
1999-01-19 23:59:39 -05:00
|
|
|
do {s = *a; *a++ = *b; *b++ = *c; *c++ = s;} while (a < t);
|
|
|
|
}
|
|
|
|
}
|
2001-12-10 02:18:16 -05:00
|
|
|
#define mmrot3(a,b,c) mmrot3_((a),(b),(c),mmarg)
|
1999-01-19 23:59:39 -05:00
|
|
|
|
|
|
|
/* qs6.c */
|
|
|
|
/*****************************************************/
|
|
|
|
/* */
|
|
|
|
/* qs6 (Quick sort function) */
|
|
|
|
/* */
|
|
|
|
/* by Tomoyuki Kawamura 1995.4.21 */
|
|
|
|
/* kawamura@tokuyama.ac.jp */
|
|
|
|
/*****************************************************/
|
|
|
|
|
|
|
|
typedef struct { char *LL, *RR; } stack_node; /* Stack structure for L,l,R,r */
|
2002-04-18 04:46:18 -04:00
|
|
|
#define PUSH(ll,rr) do { top->LL = (ll); top->RR = (rr); ++top; } while (0) /* Push L,l,R,r */
|
|
|
|
#define POP(ll,rr) do { --top; ll = top->LL; rr = top->RR; } while (0) /* Pop L,l,R,r */
|
1999-01-19 23:59:39 -05:00
|
|
|
|
2004-09-20 23:08:33 -04:00
|
|
|
#define med3(a,b,c) ((*cmp)(a,b,d)<0 ? \
|
|
|
|
((*cmp)(b,c,d)<0 ? b : ((*cmp)(a,c,d)<0 ? c : a)) : \
|
|
|
|
((*cmp)(b,c,d)>0 ? b : ((*cmp)(a,c,d)<0 ? a : c)))
|
1999-01-19 23:59:39 -05:00
|
|
|
|
2005-10-11 08:30:48 -04:00
|
|
|
void
|
|
|
|
ruby_qsort(void* base, const int nel, const int size,
|
|
|
|
int (*cmp)(const void*, const void*, void*), void *d)
|
1999-01-19 23:59:39 -05:00
|
|
|
{
|
2001-05-02 00:22:21 -04:00
|
|
|
register char *l, *r, *m; /* l,r:left,right group m:median point */
|
|
|
|
register int t, eq_l, eq_r; /* eq_l: all items in left group are equal to S */
|
|
|
|
char *L = base; /* left end of curren region */
|
2001-12-10 02:18:16 -05:00
|
|
|
char *R = (char*)base + size*(nel-1); /* right end of current region */
|
|
|
|
int chklim = 63; /* threshold of ordering element check */
|
|
|
|
stack_node stack[32], *top = stack; /* 32 is enough for 32bit CPU */
|
|
|
|
int mmkind, high, low;
|
2001-05-02 00:22:21 -04:00
|
|
|
|
|
|
|
if (nel <= 1) return; /* need not to sort */
|
|
|
|
mmprepare(base, size);
|
|
|
|
goto start;
|
|
|
|
|
|
|
|
nxt:
|
|
|
|
if (stack == top) return; /* return if stack is empty */
|
|
|
|
POP(L,R);
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
start:
|
2001-12-10 02:18:16 -05:00
|
|
|
if (L + size == R) { /* 2 elements */
|
2004-09-20 23:08:33 -04:00
|
|
|
if ((*cmp)(L,R,d) > 0) mmswap(L,R); goto nxt;
|
2001-12-10 02:18:16 -05:00
|
|
|
}
|
2001-05-02 00:22:21 -04:00
|
|
|
|
|
|
|
l = L; r = R;
|
|
|
|
t = (r - l + size) / size; /* number of elements */
|
|
|
|
m = l + size * (t >> 1); /* calculate median value */
|
|
|
|
|
|
|
|
if (t >= 60) {
|
|
|
|
register char *m1;
|
|
|
|
register char *m3;
|
|
|
|
if (t >= 200) {
|
|
|
|
t = size*(t>>3); /* number of bytes in splitting 8 */
|
|
|
|
{
|
|
|
|
register char *p1 = l + t;
|
|
|
|
register char *p2 = p1 + t;
|
|
|
|
register char *p3 = p2 + t;
|
|
|
|
m1 = med3(p1, p2, p3);
|
|
|
|
p1 = m + t;
|
|
|
|
p2 = p1 + t;
|
|
|
|
p3 = p2 + t;
|
|
|
|
m3 = med3(p1, p2, p3);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
t = size*(t>>2); /* number of bytes in splitting 4 */
|
|
|
|
m1 = l + t;
|
|
|
|
m3 = m + t;
|
|
|
|
}
|
|
|
|
m = med3(m1, m, m3);
|
|
|
|
}
|
|
|
|
|
2004-09-20 23:08:33 -04:00
|
|
|
if ((t = (*cmp)(l,m,d)) < 0) { /*3-5-?*/
|
|
|
|
if ((t = (*cmp)(m,r,d)) < 0) { /*3-5-7*/
|
2001-05-02 00:22:21 -04:00
|
|
|
if (chklim && nel >= chklim) { /* check if already ascending order */
|
|
|
|
char *p;
|
|
|
|
chklim = 0;
|
2004-09-20 23:08:33 -04:00
|
|
|
for (p=l; p<r; p+=size) if ((*cmp)(p,p+size,d) > 0) goto fail;
|
2001-05-02 00:22:21 -04:00
|
|
|
goto nxt;
|
|
|
|
}
|
|
|
|
fail: goto loopA; /*3-5-7*/
|
|
|
|
}
|
|
|
|
if (t > 0) {
|
2004-09-20 23:08:33 -04:00
|
|
|
if ((*cmp)(l,r,d) <= 0) {mmswap(m,r); goto loopA;} /*3-5-4*/
|
2001-05-02 00:22:21 -04:00
|
|
|
mmrot3(r,m,l); goto loopA; /*3-5-2*/
|
|
|
|
}
|
|
|
|
goto loopB; /*3-5-5*/
|
|
|
|
}
|
|
|
|
|
|
|
|
if (t > 0) { /*7-5-?*/
|
2004-09-20 23:08:33 -04:00
|
|
|
if ((t = (*cmp)(m,r,d)) > 0) { /*7-5-3*/
|
2001-05-02 00:22:21 -04:00
|
|
|
if (chklim && nel >= chklim) { /* check if already ascending order */
|
|
|
|
char *p;
|
|
|
|
chklim = 0;
|
2004-09-20 23:08:33 -04:00
|
|
|
for (p=l; p<r; p+=size) if ((*cmp)(p,p+size,d) < 0) goto fail2;
|
2001-05-02 00:22:21 -04:00
|
|
|
while (l<r) {mmswap(l,r); l+=size; r-=size;} /* reverse region */
|
|
|
|
goto nxt;
|
|
|
|
}
|
|
|
|
fail2: mmswap(l,r); goto loopA; /*7-5-3*/
|
|
|
|
}
|
|
|
|
if (t < 0) {
|
2004-09-20 23:08:33 -04:00
|
|
|
if ((*cmp)(l,r,d) <= 0) {mmswap(l,m); goto loopB;} /*7-5-8*/
|
2001-05-02 00:22:21 -04:00
|
|
|
mmrot3(l,m,r); goto loopA; /*7-5-6*/
|
|
|
|
}
|
|
|
|
mmswap(l,r); goto loopA; /*7-5-5*/
|
|
|
|
}
|
|
|
|
|
2004-09-20 23:08:33 -04:00
|
|
|
if ((t = (*cmp)(m,r,d)) < 0) {goto loopA;} /*5-5-7*/
|
2001-05-02 00:22:21 -04:00
|
|
|
if (t > 0) {mmswap(l,r); goto loopB;} /*5-5-3*/
|
|
|
|
|
2001-12-10 02:18:16 -05:00
|
|
|
/* determining splitting type in case 5-5-5 */ /*5-5-5*/
|
2001-05-02 00:22:21 -04:00
|
|
|
for (;;) {
|
|
|
|
if ((l += size) == r) goto nxt; /*5-5-5*/
|
|
|
|
if (l == m) continue;
|
2004-09-20 23:08:33 -04:00
|
|
|
if ((t = (*cmp)(l,m,d)) > 0) {mmswap(l,r); l = L; goto loopA;}/*575-5*/
|
2001-05-02 00:22:21 -04:00
|
|
|
if (t < 0) {mmswap(L,l); l = L; goto loopB;} /*535-5*/
|
|
|
|
}
|
|
|
|
|
|
|
|
loopA: eq_l = 1; eq_r = 1; /* splitting type A */ /* left <= median < right */
|
|
|
|
for (;;) {
|
|
|
|
for (;;) {
|
|
|
|
if ((l += size) == r)
|
|
|
|
{l -= size; if (l != m) mmswap(m,l); l -= size; goto fin;}
|
|
|
|
if (l == m) continue;
|
2004-09-20 23:08:33 -04:00
|
|
|
if ((t = (*cmp)(l,m,d)) > 0) {eq_r = 0; break;}
|
2001-05-02 00:22:21 -04:00
|
|
|
if (t < 0) eq_l = 0;
|
|
|
|
}
|
|
|
|
for (;;) {
|
|
|
|
if (l == (r -= size))
|
|
|
|
{l -= size; if (l != m) mmswap(m,l); l -= size; goto fin;}
|
|
|
|
if (r == m) {m = l; break;}
|
2004-09-20 23:08:33 -04:00
|
|
|
if ((t = (*cmp)(r,m,d)) < 0) {eq_l = 0; break;}
|
2001-05-02 00:22:21 -04:00
|
|
|
if (t == 0) break;
|
|
|
|
}
|
|
|
|
mmswap(l,r); /* swap left and right */
|
|
|
|
}
|
|
|
|
|
|
|
|
loopB: eq_l = 1; eq_r = 1; /* splitting type B */ /* left < median <= right */
|
|
|
|
for (;;) {
|
|
|
|
for (;;) {
|
|
|
|
if (l == (r -= size))
|
|
|
|
{r += size; if (r != m) mmswap(r,m); r += size; goto fin;}
|
|
|
|
if (r == m) continue;
|
2004-09-20 23:08:33 -04:00
|
|
|
if ((t = (*cmp)(r,m,d)) < 0) {eq_l = 0; break;}
|
2001-05-02 00:22:21 -04:00
|
|
|
if (t > 0) eq_r = 0;
|
|
|
|
}
|
|
|
|
for (;;) {
|
|
|
|
if ((l += size) == r)
|
|
|
|
{r += size; if (r != m) mmswap(r,m); r += size; goto fin;}
|
|
|
|
if (l == m) {m = r; break;}
|
2004-09-20 23:08:33 -04:00
|
|
|
if ((t = (*cmp)(l,m,d)) > 0) {eq_r = 0; break;}
|
2001-05-02 00:22:21 -04:00
|
|
|
if (t == 0) break;
|
|
|
|
}
|
|
|
|
mmswap(l,r); /* swap left and right */
|
|
|
|
}
|
|
|
|
|
|
|
|
fin:
|
|
|
|
if (eq_l == 0) /* need to sort left side */
|
|
|
|
if (eq_r == 0) /* need to sort right side */
|
|
|
|
if (l-L < R-r) {PUSH(r,R); R = l;} /* sort left side first */
|
|
|
|
else {PUSH(L,l); L = r;} /* sort right side first */
|
|
|
|
else R = l; /* need to sort left side only */
|
|
|
|
else if (eq_r == 0) L = r; /* need to sort right side only */
|
|
|
|
else goto nxt; /* need not to sort both sides */
|
|
|
|
}
|
1999-01-19 23:59:39 -05:00
|
|
|
}
|
1999-08-13 01:45:20 -04:00
|
|
|
|
2000-07-27 05:49:34 -04:00
|
|
|
char *
|
|
|
|
ruby_strdup(str)
|
|
|
|
const char *str;
|
|
|
|
{
|
|
|
|
char *tmp;
|
|
|
|
int len = strlen(str) + 1;
|
|
|
|
|
|
|
|
tmp = xmalloc(len);
|
|
|
|
memcpy(tmp, str, len);
|
|
|
|
|
|
|
|
return tmp;
|
|
|
|
}
|
2001-11-08 01:43:14 -05:00
|
|
|
|
|
|
|
char *
|
|
|
|
ruby_getcwd()
|
|
|
|
{
|
* gc.c (Init_stack): stack region is far smaller than usual if
pthread is used.
* marshal.c (w_extended): singleton methods should not be checked
when dumping via marshal_dump() or _dump(). [ruby-talk:85909]
* file.c (getcwdofdrv): avoid using getcwd() directly, use
my_getcwd() instead.
* merged NeXT, OpenStep, Rhapsody ports patch from Eric Sunshine
<sunshine@sunshineco.com>. [ruby-core:01596]
* marshal.c (w_object): LINK check earlier than anything else,
i.e. do not dump TYPE_IVAR for already dumped objects.
(ruby-bugs PR#1220)
* eval.c (rb_eval): call "inherited" only when a new class is
generated; not on reopening.
* eval.c (eval): prepend error position in evaluating string to
* configure.in: revived NextStep, OpenStep, and Rhapsody ports which
had become unbuildable; enhanced --enable-fat-binary option so that
it accepts a list of desired architectures (rather than assuming a
fixed list), or defaults to a platform-appropriate list if user does
not provide an explicit list; made the default list of architectures
for MAB (fat binary) more comprehensive; now uses -fno-common even
when building the interpreter (in addition to using it for
extensions), thus allowing the interpreter to be embedded into a
plugin module of an external project (in addition to allowing
embedding directly into an application); added checks for
<netinet/in_systm.h> (needed by `socket' extension) and getcwd(); now
ensures that -I/usr/local/include is employed when extensions'
extconf.rb scripts invoke have_header() since extension checks on
NextStep and OpenStep will fail without it if the desired resource
resides in the /usr/local tree; fixed formatting of --help message.
* Makefile.in: $(LIBRUBY_A) rule now deletes the archive before
invoking $(AR) since `ar' on Apple/NeXT can not "update" MAB archives
(see configure's --enable-fat-binary option); added rule for new
missing/getcwd.c.
* defines.h: fixed endian handling during MAB build (see configure's
--enable-fat-binary option) to ensure that all portions of the
project see the correct WORDS_BIGENDIAN value (some extension modules
were getting the wrong endian setting); added missing constants
GETPGRP_VOID, WNOHANG, WUNTRACED, X_OK, and type pid_t for NextStep
and OpenStep; removed unnecessary and problematic HAVE_SYS_WAIT_H
define in NeXT section.
* dir.c: do not allow NAMLEN() macro to trust dirent::d_namlen on
NextStep since, on some installations, this value always resolves
uselessly to zero.
* dln.c: added error reporting to NextStep extension loader since the
previous behavior of failing silently was not useful; now ensures
that NSLINKMODULE_OPTION_BINDNOW compatibility constant is defined
for OpenStep and Rhapsody; no longer includes <mach-o/dyld.h> twice
on Rhapsody since this header lacks multiple-include protection,
which resulted in "redefinition" compilation errors.
* main.c: also create hard reference to objc_msgSend() on NeXT
platforms (in addition to Apple platforms).
* lib/mkmf.rb: now exports XCFLAGS from configure script to extension
makefiles so that extensions can be built MAB (see configure's
--enable-fat-binary option); also utilize XCFLAGS in cc_command()
(but not cpp_command() because MAB flags are incompatible with
direct invocation of `cpp').
* ext/curses/extconf.rb: now additionally checks for presence of these
curses functions which are not present on NextStep or Openstep:
bkgd(), bkgdset(), color(), curs(), getbkgd(), init(), scrl(), set(),
setscrreg(), wattroff(), wattron(), wattrset(), wbkgd(), wbkgdset(),
wscrl(), wsetscrreg()
* ext/curses/curses.c: added appropriate #ifdef's for additional set of
curses functions now checked by extconf.rb; fixed curses_bkgd() and
window_bkgd() to correctly return boolean result rather than numeric
result; fixed window_getbkgd() to correctly signal an error by
returning nil rather than -1.
* ext/etc/etc.c: setup_passwd() and setup_group() now check for null
pointers before invoking rb_tainted_str_new2() upon fields extracted
from `struct passwd' and `struct group' since null pointers in some
fields are common on NextStep/OpenStep (especially so for the
`pw_comment' field) and rb_tainted_str_new2() throws an exception
when it receives a null pointer.
* ext/pty/pty.c: include "util.h" for strdup()/ruby_strdup() for
platforms such as NextStep and OpenStep which lack strdup().
* ext/socket/getaddrinfo.c: cast first argument of getservbyname(),
gethostbyaddr(), and gethostbyname() from (const char*) to non-const
(char*) for older platforms such as NextStep and OpenStep.
* ext/socket/socket.c: include "util.h" for strdup()/ruby_strdup() for
platforms such as NextStep and OpenStep which lack strdup(); include
<netinet/in_systm.h> if present for NextStep and OpenStep; cast first
argument of gethostbyaddr() and getservbyname() from (const char*) to
non-const (char*) for older platforms.
* ext/syslog/syslog.c: include "util.h" for strdup()/ruby_strdup() for
platforms such as NextStep and OpenStep which lack strdup().
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5002 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2003-11-21 23:00:03 -05:00
|
|
|
#ifdef HAVE_GETCWD
|
2001-11-08 01:43:14 -05:00
|
|
|
int size = 200;
|
|
|
|
char *buf = xmalloc(size);
|
|
|
|
|
|
|
|
while (!getcwd(buf, size)) {
|
2004-09-12 10:55:22 -04:00
|
|
|
if (errno != ERANGE) {
|
|
|
|
free(buf);
|
|
|
|
rb_sys_fail("getcwd");
|
|
|
|
}
|
2001-11-08 01:43:14 -05:00
|
|
|
size *= 2;
|
|
|
|
buf = xrealloc(buf, size);
|
|
|
|
}
|
* gc.c (Init_stack): stack region is far smaller than usual if
pthread is used.
* marshal.c (w_extended): singleton methods should not be checked
when dumping via marshal_dump() or _dump(). [ruby-talk:85909]
* file.c (getcwdofdrv): avoid using getcwd() directly, use
my_getcwd() instead.
* merged NeXT, OpenStep, Rhapsody ports patch from Eric Sunshine
<sunshine@sunshineco.com>. [ruby-core:01596]
* marshal.c (w_object): LINK check earlier than anything else,
i.e. do not dump TYPE_IVAR for already dumped objects.
(ruby-bugs PR#1220)
* eval.c (rb_eval): call "inherited" only when a new class is
generated; not on reopening.
* eval.c (eval): prepend error position in evaluating string to
* configure.in: revived NextStep, OpenStep, and Rhapsody ports which
had become unbuildable; enhanced --enable-fat-binary option so that
it accepts a list of desired architectures (rather than assuming a
fixed list), or defaults to a platform-appropriate list if user does
not provide an explicit list; made the default list of architectures
for MAB (fat binary) more comprehensive; now uses -fno-common even
when building the interpreter (in addition to using it for
extensions), thus allowing the interpreter to be embedded into a
plugin module of an external project (in addition to allowing
embedding directly into an application); added checks for
<netinet/in_systm.h> (needed by `socket' extension) and getcwd(); now
ensures that -I/usr/local/include is employed when extensions'
extconf.rb scripts invoke have_header() since extension checks on
NextStep and OpenStep will fail without it if the desired resource
resides in the /usr/local tree; fixed formatting of --help message.
* Makefile.in: $(LIBRUBY_A) rule now deletes the archive before
invoking $(AR) since `ar' on Apple/NeXT can not "update" MAB archives
(see configure's --enable-fat-binary option); added rule for new
missing/getcwd.c.
* defines.h: fixed endian handling during MAB build (see configure's
--enable-fat-binary option) to ensure that all portions of the
project see the correct WORDS_BIGENDIAN value (some extension modules
were getting the wrong endian setting); added missing constants
GETPGRP_VOID, WNOHANG, WUNTRACED, X_OK, and type pid_t for NextStep
and OpenStep; removed unnecessary and problematic HAVE_SYS_WAIT_H
define in NeXT section.
* dir.c: do not allow NAMLEN() macro to trust dirent::d_namlen on
NextStep since, on some installations, this value always resolves
uselessly to zero.
* dln.c: added error reporting to NextStep extension loader since the
previous behavior of failing silently was not useful; now ensures
that NSLINKMODULE_OPTION_BINDNOW compatibility constant is defined
for OpenStep and Rhapsody; no longer includes <mach-o/dyld.h> twice
on Rhapsody since this header lacks multiple-include protection,
which resulted in "redefinition" compilation errors.
* main.c: also create hard reference to objc_msgSend() on NeXT
platforms (in addition to Apple platforms).
* lib/mkmf.rb: now exports XCFLAGS from configure script to extension
makefiles so that extensions can be built MAB (see configure's
--enable-fat-binary option); also utilize XCFLAGS in cc_command()
(but not cpp_command() because MAB flags are incompatible with
direct invocation of `cpp').
* ext/curses/extconf.rb: now additionally checks for presence of these
curses functions which are not present on NextStep or Openstep:
bkgd(), bkgdset(), color(), curs(), getbkgd(), init(), scrl(), set(),
setscrreg(), wattroff(), wattron(), wattrset(), wbkgd(), wbkgdset(),
wscrl(), wsetscrreg()
* ext/curses/curses.c: added appropriate #ifdef's for additional set of
curses functions now checked by extconf.rb; fixed curses_bkgd() and
window_bkgd() to correctly return boolean result rather than numeric
result; fixed window_getbkgd() to correctly signal an error by
returning nil rather than -1.
* ext/etc/etc.c: setup_passwd() and setup_group() now check for null
pointers before invoking rb_tainted_str_new2() upon fields extracted
from `struct passwd' and `struct group' since null pointers in some
fields are common on NextStep/OpenStep (especially so for the
`pw_comment' field) and rb_tainted_str_new2() throws an exception
when it receives a null pointer.
* ext/pty/pty.c: include "util.h" for strdup()/ruby_strdup() for
platforms such as NextStep and OpenStep which lack strdup().
* ext/socket/getaddrinfo.c: cast first argument of getservbyname(),
gethostbyaddr(), and gethostbyname() from (const char*) to non-const
(char*) for older platforms such as NextStep and OpenStep.
* ext/socket/socket.c: include "util.h" for strdup()/ruby_strdup() for
platforms such as NextStep and OpenStep which lack strdup(); include
<netinet/in_systm.h> if present for NextStep and OpenStep; cast first
argument of gethostbyaddr() and getservbyname() from (const char*) to
non-const (char*) for older platforms.
* ext/syslog/syslog.c: include "util.h" for strdup()/ruby_strdup() for
platforms such as NextStep and OpenStep which lack strdup().
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5002 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2003-11-21 23:00:03 -05:00
|
|
|
#else
|
|
|
|
# ifndef PATH_MAX
|
|
|
|
# define PATH_MAX 8192
|
|
|
|
# endif
|
|
|
|
char *buf = xmalloc(PATH_MAX+1);
|
|
|
|
|
|
|
|
if (!getwd(buf)) {
|
2004-09-12 10:55:22 -04:00
|
|
|
free(buf);
|
* gc.c (Init_stack): stack region is far smaller than usual if
pthread is used.
* marshal.c (w_extended): singleton methods should not be checked
when dumping via marshal_dump() or _dump(). [ruby-talk:85909]
* file.c (getcwdofdrv): avoid using getcwd() directly, use
my_getcwd() instead.
* merged NeXT, OpenStep, Rhapsody ports patch from Eric Sunshine
<sunshine@sunshineco.com>. [ruby-core:01596]
* marshal.c (w_object): LINK check earlier than anything else,
i.e. do not dump TYPE_IVAR for already dumped objects.
(ruby-bugs PR#1220)
* eval.c (rb_eval): call "inherited" only when a new class is
generated; not on reopening.
* eval.c (eval): prepend error position in evaluating string to
* configure.in: revived NextStep, OpenStep, and Rhapsody ports which
had become unbuildable; enhanced --enable-fat-binary option so that
it accepts a list of desired architectures (rather than assuming a
fixed list), or defaults to a platform-appropriate list if user does
not provide an explicit list; made the default list of architectures
for MAB (fat binary) more comprehensive; now uses -fno-common even
when building the interpreter (in addition to using it for
extensions), thus allowing the interpreter to be embedded into a
plugin module of an external project (in addition to allowing
embedding directly into an application); added checks for
<netinet/in_systm.h> (needed by `socket' extension) and getcwd(); now
ensures that -I/usr/local/include is employed when extensions'
extconf.rb scripts invoke have_header() since extension checks on
NextStep and OpenStep will fail without it if the desired resource
resides in the /usr/local tree; fixed formatting of --help message.
* Makefile.in: $(LIBRUBY_A) rule now deletes the archive before
invoking $(AR) since `ar' on Apple/NeXT can not "update" MAB archives
(see configure's --enable-fat-binary option); added rule for new
missing/getcwd.c.
* defines.h: fixed endian handling during MAB build (see configure's
--enable-fat-binary option) to ensure that all portions of the
project see the correct WORDS_BIGENDIAN value (some extension modules
were getting the wrong endian setting); added missing constants
GETPGRP_VOID, WNOHANG, WUNTRACED, X_OK, and type pid_t for NextStep
and OpenStep; removed unnecessary and problematic HAVE_SYS_WAIT_H
define in NeXT section.
* dir.c: do not allow NAMLEN() macro to trust dirent::d_namlen on
NextStep since, on some installations, this value always resolves
uselessly to zero.
* dln.c: added error reporting to NextStep extension loader since the
previous behavior of failing silently was not useful; now ensures
that NSLINKMODULE_OPTION_BINDNOW compatibility constant is defined
for OpenStep and Rhapsody; no longer includes <mach-o/dyld.h> twice
on Rhapsody since this header lacks multiple-include protection,
which resulted in "redefinition" compilation errors.
* main.c: also create hard reference to objc_msgSend() on NeXT
platforms (in addition to Apple platforms).
* lib/mkmf.rb: now exports XCFLAGS from configure script to extension
makefiles so that extensions can be built MAB (see configure's
--enable-fat-binary option); also utilize XCFLAGS in cc_command()
(but not cpp_command() because MAB flags are incompatible with
direct invocation of `cpp').
* ext/curses/extconf.rb: now additionally checks for presence of these
curses functions which are not present on NextStep or Openstep:
bkgd(), bkgdset(), color(), curs(), getbkgd(), init(), scrl(), set(),
setscrreg(), wattroff(), wattron(), wattrset(), wbkgd(), wbkgdset(),
wscrl(), wsetscrreg()
* ext/curses/curses.c: added appropriate #ifdef's for additional set of
curses functions now checked by extconf.rb; fixed curses_bkgd() and
window_bkgd() to correctly return boolean result rather than numeric
result; fixed window_getbkgd() to correctly signal an error by
returning nil rather than -1.
* ext/etc/etc.c: setup_passwd() and setup_group() now check for null
pointers before invoking rb_tainted_str_new2() upon fields extracted
from `struct passwd' and `struct group' since null pointers in some
fields are common on NextStep/OpenStep (especially so for the
`pw_comment' field) and rb_tainted_str_new2() throws an exception
when it receives a null pointer.
* ext/pty/pty.c: include "util.h" for strdup()/ruby_strdup() for
platforms such as NextStep and OpenStep which lack strdup().
* ext/socket/getaddrinfo.c: cast first argument of getservbyname(),
gethostbyaddr(), and gethostbyname() from (const char*) to non-const
(char*) for older platforms such as NextStep and OpenStep.
* ext/socket/socket.c: include "util.h" for strdup()/ruby_strdup() for
platforms such as NextStep and OpenStep which lack strdup(); include
<netinet/in_systm.h> if present for NextStep and OpenStep; cast first
argument of gethostbyaddr() and getservbyname() from (const char*) to
non-const (char*) for older platforms.
* ext/syslog/syslog.c: include "util.h" for strdup()/ruby_strdup() for
platforms such as NextStep and OpenStep which lack strdup().
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5002 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2003-11-21 23:00:03 -05:00
|
|
|
rb_sys_fail("getwd");
|
|
|
|
}
|
|
|
|
#endif
|
2001-11-08 01:43:14 -05:00
|
|
|
return buf;
|
|
|
|
}
|
2002-05-14 02:22:31 -04:00
|
|
|
|
|
|
|
/* copyright notice for strtod implementation --
|
|
|
|
*
|
|
|
|
* Copyright (c) 1988-1993 The Regents of the University of California.
|
|
|
|
* Copyright (c) 1994 Sun Microsystems, Inc.
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and distribute this
|
|
|
|
* software and its documentation for any purpose and without
|
|
|
|
* fee is hereby granted, provided that the above copyright
|
|
|
|
* notice appear in all copies. The University of California
|
|
|
|
* makes no representations about the suitability of this
|
|
|
|
* software for any purpose. It is provided "as is" without
|
|
|
|
* express or implied warranty.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define TRUE 1
|
|
|
|
#define FALSE 0
|
|
|
|
|
2003-07-09 18:28:42 -04:00
|
|
|
static int MDMINEXPT = -323;
|
|
|
|
static int MDMAXEXPT = 309;
|
2002-05-14 02:22:31 -04:00
|
|
|
static double powersOf10[] = { /* Table giving binary powers of 10. Entry */
|
|
|
|
10.0, /* is 10^2^i. Used to convert decimal */
|
|
|
|
100.0, /* exponents into floating-point numbers. */
|
|
|
|
1.0e4,
|
|
|
|
1.0e8,
|
|
|
|
1.0e16,
|
|
|
|
1.0e32,
|
|
|
|
1.0e64,
|
|
|
|
1.0e128,
|
|
|
|
1.0e256
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
*----------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* strtod --
|
|
|
|
*
|
|
|
|
* This procedure converts a floating-point number from an ASCII
|
|
|
|
* decimal representation to internal double-precision format.
|
|
|
|
*
|
|
|
|
* Results:
|
|
|
|
* The return value is the double-precision floating-point
|
|
|
|
* representation of the characters in string. If endPtr isn't
|
|
|
|
* NULL, then *endPtr is filled in with the address of the
|
|
|
|
* next character after the last one that was part of the
|
|
|
|
* floating-point number.
|
|
|
|
*
|
|
|
|
* Side effects:
|
|
|
|
* None.
|
|
|
|
*
|
|
|
|
*----------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
double
|
|
|
|
ruby_strtod(string, endPtr)
|
|
|
|
const char *string; /* A decimal ASCII floating-point number,
|
|
|
|
* optionally preceded by white space.
|
|
|
|
* Must have form "-I.FE-X", where I is the
|
|
|
|
* integer part of the mantissa, F is the
|
|
|
|
* fractional part of the mantissa, and X
|
|
|
|
* is the exponent. Either of the signs
|
|
|
|
* may be "+", "-", or omitted. Either I
|
2004-07-13 23:32:20 -04:00
|
|
|
* or F may be omitted, but both cannot be
|
|
|
|
* ommitted at once. The decimal
|
2002-05-14 02:22:31 -04:00
|
|
|
* point isn't necessary unless F is present.
|
|
|
|
* The "E" may actually be an "e". E and X
|
|
|
|
* may both be omitted (but not just one).
|
|
|
|
*/
|
|
|
|
char **endPtr; /* If non-NULL, store terminating character's
|
|
|
|
* address here. */
|
|
|
|
{
|
|
|
|
int sign, expSign = FALSE;
|
|
|
|
double fraction, dblExp, *d;
|
|
|
|
register const char *p;
|
|
|
|
register int c;
|
|
|
|
int exp = 0; /* Exponent read from "EX" field. */
|
|
|
|
int fracExp = 0; /* Exponent that derives from the fractional
|
|
|
|
* part. Under normal circumstatnces, it is
|
|
|
|
* the negative of the number of digits in F.
|
|
|
|
* However, if I is very long, the last digits
|
|
|
|
* of I get dropped (otherwise a long I with a
|
|
|
|
* large negative exponent could cause an
|
|
|
|
* unnecessary overflow on I alone). In this
|
|
|
|
* case, fracExp is incremented one for each
|
|
|
|
* dropped digit. */
|
2004-05-06 22:26:19 -04:00
|
|
|
int mantSize = 0; /* Number of digits in mantissa. */
|
2004-07-13 23:32:20 -04:00
|
|
|
int hasPoint = FALSE; /* Decimal point exists. */
|
|
|
|
int hasDigit = FALSE; /* I or F exists. */
|
2004-05-06 22:26:19 -04:00
|
|
|
const char *pMant; /* Temporarily holds location of mantissa
|
|
|
|
* in string. */
|
2002-05-14 02:22:31 -04:00
|
|
|
const char *pExp; /* Temporarily holds location of exponent
|
|
|
|
* in string. */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Strip off leading blanks and check for a sign.
|
|
|
|
*/
|
|
|
|
|
2002-05-29 01:20:39 -04:00
|
|
|
errno = 0;
|
2002-05-14 02:22:31 -04:00
|
|
|
p = string;
|
2002-05-29 01:20:39 -04:00
|
|
|
while (ISSPACE(*p)) {
|
2002-05-14 02:22:31 -04:00
|
|
|
p += 1;
|
|
|
|
}
|
|
|
|
if (*p == '-') {
|
|
|
|
sign = TRUE;
|
|
|
|
p += 1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (*p == '+') {
|
|
|
|
p += 1;
|
|
|
|
}
|
|
|
|
sign = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2004-05-13 23:17:50 -04:00
|
|
|
* Count the number of digits in the mantissa
|
|
|
|
* and also locate the decimal point.
|
2002-05-14 02:22:31 -04:00
|
|
|
*/
|
|
|
|
|
2004-05-06 22:26:19 -04:00
|
|
|
for ( ; c = *p; p += 1) {
|
2002-05-29 01:20:39 -04:00
|
|
|
if (!ISDIGIT(c)) {
|
2004-07-13 23:32:20 -04:00
|
|
|
if (c != '.' || hasPoint) {
|
2002-05-14 02:22:31 -04:00
|
|
|
break;
|
|
|
|
}
|
2004-07-13 23:32:20 -04:00
|
|
|
hasPoint = TRUE;
|
2004-05-06 22:26:19 -04:00
|
|
|
}
|
|
|
|
else {
|
2004-07-13 23:32:20 -04:00
|
|
|
if (hasPoint) { /* already in fractional part */
|
2004-05-06 22:26:19 -04:00
|
|
|
fracExp -= 1;
|
|
|
|
}
|
|
|
|
if (mantSize) { /* already in mantissa */
|
|
|
|
mantSize += 1;
|
|
|
|
}
|
|
|
|
else if (c != '0') { /* have entered mantissa */
|
|
|
|
mantSize += 1;
|
|
|
|
pMant = p;
|
|
|
|
}
|
2004-07-13 23:32:20 -04:00
|
|
|
hasDigit = TRUE;
|
2002-05-14 02:22:31 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Now suck up the digits in the mantissa. Use two integers to
|
|
|
|
* collect 9 digits each (this is faster than using floating-point).
|
|
|
|
* If the mantissa has more than 18 digits, ignore the extras, since
|
|
|
|
* they can't affect the value anyway.
|
|
|
|
*/
|
|
|
|
|
|
|
|
pExp = p;
|
2004-05-13 23:17:50 -04:00
|
|
|
if (mantSize) {
|
|
|
|
p = pMant;
|
|
|
|
}
|
2002-05-14 02:22:31 -04:00
|
|
|
if (mantSize > 18) {
|
2004-05-06 22:26:19 -04:00
|
|
|
fracExp += (mantSize - 18);
|
2002-05-14 02:22:31 -04:00
|
|
|
mantSize = 18;
|
|
|
|
}
|
2004-07-13 23:32:20 -04:00
|
|
|
if (!hasDigit) {
|
|
|
|
fraction = 0.0;
|
|
|
|
p = string;
|
|
|
|
}
|
|
|
|
else {
|
2002-05-14 02:22:31 -04:00
|
|
|
int frac1, frac2;
|
|
|
|
frac1 = 0;
|
|
|
|
for ( ; mantSize > 9; mantSize -= 1) {
|
|
|
|
c = *p;
|
|
|
|
p += 1;
|
|
|
|
if (c == '.') {
|
|
|
|
c = *p;
|
|
|
|
p += 1;
|
|
|
|
}
|
|
|
|
frac1 = 10*frac1 + (c - '0');
|
|
|
|
}
|
|
|
|
frac2 = 0;
|
|
|
|
for (; mantSize > 0; mantSize -= 1) {
|
|
|
|
c = *p;
|
|
|
|
p += 1;
|
|
|
|
if (c == '.') {
|
|
|
|
c = *p;
|
|
|
|
p += 1;
|
|
|
|
}
|
|
|
|
frac2 = 10*frac2 + (c - '0');
|
|
|
|
}
|
|
|
|
|
2003-04-17 12:49:23 -04:00
|
|
|
/*
|
|
|
|
* Skim off the exponent.
|
|
|
|
*/
|
2002-05-14 02:22:31 -04:00
|
|
|
|
2003-04-17 12:49:23 -04:00
|
|
|
p = pExp;
|
|
|
|
if ((*p == 'E') || (*p == 'e')) {
|
2002-05-14 02:22:31 -04:00
|
|
|
p += 1;
|
2003-04-17 12:49:23 -04:00
|
|
|
if (*p == '-') {
|
|
|
|
expSign = TRUE;
|
|
|
|
p += 1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (*p == '+') {
|
|
|
|
p += 1;
|
|
|
|
}
|
|
|
|
expSign = FALSE;
|
|
|
|
}
|
|
|
|
while (ISDIGIT(*p)) {
|
|
|
|
exp = exp * 10 + (*p - '0');
|
2002-05-14 02:22:31 -04:00
|
|
|
p += 1;
|
|
|
|
}
|
|
|
|
}
|
2003-04-17 12:49:23 -04:00
|
|
|
if (expSign) {
|
|
|
|
exp = fracExp - exp;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
exp = fracExp + exp;
|
2002-05-14 02:22:31 -04:00
|
|
|
}
|
|
|
|
|
2003-04-17 12:49:23 -04:00
|
|
|
/*
|
|
|
|
* Generate a floating-point number that represents the exponent.
|
|
|
|
* Do this by processing the exponent one bit at a time to combine
|
|
|
|
* many powers of 2 of 10. Then combine the exponent with the
|
|
|
|
* fraction.
|
|
|
|
*/
|
2002-05-14 02:22:31 -04:00
|
|
|
|
2003-07-11 03:10:14 -04:00
|
|
|
if (exp >= MDMAXEXPT - 18) {
|
2003-07-09 18:28:42 -04:00
|
|
|
exp = MDMAXEXPT;
|
2003-04-17 12:49:23 -04:00
|
|
|
errno = ERANGE;
|
|
|
|
}
|
2003-07-09 18:28:42 -04:00
|
|
|
else if (exp < MDMINEXPT + 18) {
|
|
|
|
exp = MDMINEXPT;
|
2003-04-17 12:49:23 -04:00
|
|
|
errno = ERANGE;
|
|
|
|
}
|
|
|
|
fracExp = exp;
|
|
|
|
exp += 9;
|
|
|
|
if (exp < 0) {
|
|
|
|
expSign = TRUE;
|
|
|
|
exp = -exp;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
expSign = FALSE;
|
|
|
|
}
|
|
|
|
dblExp = 1.0;
|
|
|
|
for (d = powersOf10; exp != 0; exp >>= 1, d += 1) {
|
|
|
|
if (exp & 01) {
|
|
|
|
dblExp *= *d;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (expSign) {
|
|
|
|
fraction = frac1 / dblExp;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
fraction = frac1 * dblExp;
|
|
|
|
}
|
|
|
|
exp = fracExp;
|
|
|
|
if (exp < 0) {
|
|
|
|
expSign = TRUE;
|
|
|
|
exp = -exp;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
expSign = FALSE;
|
|
|
|
}
|
|
|
|
dblExp = 1.0;
|
|
|
|
for (d = powersOf10; exp != 0; exp >>= 1, d += 1) {
|
|
|
|
if (exp & 01) {
|
|
|
|
dblExp *= *d;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (expSign) {
|
|
|
|
fraction += frac2 / dblExp;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
fraction += frac2 * dblExp;
|
2002-05-14 02:22:31 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (endPtr != NULL) {
|
|
|
|
*endPtr = (char *) p;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sign) {
|
|
|
|
return -fraction;
|
|
|
|
}
|
|
|
|
return fraction;
|
|
|
|
}
|