From 7ea2ceddb832b9973694fecac9fe3c30400735ba Mon Sep 17 00:00:00 2001 From: matz Date: Fri, 16 Jan 1998 12:19:22 +0000 Subject: This commit was generated by cvs2svn to compensate for changes in r11, which included commits to RCS files with non-trunk default branches. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- util.c | 54 ++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 42 insertions(+), 12 deletions(-) (limited to 'util.c') diff --git a/util.c b/util.c index 8e822631ed..21e0a55639 100644 --- a/util.c +++ b/util.c @@ -10,11 +10,42 @@ ************************************************/ +#define RUBY_NO_INLINE #include "ruby.h" + +int +rb_type(obj) + VALUE obj; +{ + if (FIXNUM_P(obj)) return T_FIXNUM; + if (obj == Qnil) return T_NIL; + if (obj == FALSE) return T_FALSE; + if (obj == TRUE) return T_TRUE; + + return BUILTIN_TYPE(obj); +} + +int +rb_special_const_p(obj) + VALUE obj; +{ + if (FIXNUM_P(obj)) return TRUE; + if (obj == Qnil) return TRUE; + if (obj == FALSE) return TRUE; + if (obj == TRUE) return TRUE; + + return FALSE; +} + +int +rb_test_false_or_nil(v) + VALUE v; +{ + return (v != Qnil) && (v != FALSE); +} + #include "util.h" -#ifdef HAVE_STRING_H -# include -#else +#ifndef HAVE_STRING_H char *strchr(); #endif @@ -136,7 +167,7 @@ static char suffix2[] = ".~~~"; #define strEQ(s1,s2) (strcmp(s1,s2) == 0) void -add_suffix(struct RString *str, char *suffix) +add_suffix(VALUE str, char *suffix) { int baselen; int extlen = strlen(suffix); @@ -144,25 +175,25 @@ add_suffix(struct RString *str, char *suffix) int slen; char buf[1024]; - if (str->len > 1000) - Fatal("Cannot do inplace edit on long filename (%d characters)", str->len); + if (RSTRING(str)->len > 1000) + Fatal("Cannot do inplace edit on long filename (%d characters)", RSTRING(str)->len); #if defined(DJGPP) || defined(__CYGWIN32__) || defined(NT) /* Style 0 */ - slen = str->len; + slen = RSTRING(str)->len; str_cat(str, suffix, extlen); #if defined(DJGPP) if (_USE_LFN) return; #else - if (valid_filename(str->ptr)) return; + if (valid_filename(RSTRING(str)->ptr)) return; #endif /* Fooey, style 0 failed. Fix str before continuing. */ - str->ptr[str->len = slen] = '\0'; + RSTRING(str)->ptr[RSTRING(str)->len = slen] = '\0'; #endif slen = extlen; - t = buf; baselen = 0; s = str->ptr; + t = buf; baselen = 0; s = RSTRING(str)->ptr; while ( (*t = *s) && *s != '.') { baselen++; if (*s == '\\' || *s == '/') baselen = 0; @@ -194,7 +225,7 @@ fallback: (void)memcpy(p, strEQ(ext, suffix1) ? suffix2 : suffix1, 5); } str_resize(str, strlen(buf)); - memcpy(str->ptr, buf, str->len); + memcpy(RSTRING(str)->ptr, buf, RSTRING(str)->len); } #if defined(__CYGWIN32__) || defined(NT) @@ -232,7 +263,6 @@ valid_filename(char *s) #include /* For FILENAME_MAX */ #include /* For errno */ #include /* For tolower */ -#include /* For strlen() */ #include /* For LFN stuff */ #include #include /* For dpmisim */ -- cgit v1.2.3