* error.c (rb_raise): snprintf() termination moved to

win32/win32.c.

* win32/win32.c (valid_filename, str_grow): unused.

* win32/win32.c (NTLoginName, ChildRecord): make static.

* win32/win32.c (CreateChild): argument check.

* win32/win32.c (kill): should not call CloseHandle() when
  OpenProcess() failed.

* win32/win32.c (rb_w32_vsnprintf, rb_w32_snprintf): ensure buffer
  terminated.  [ruby-talk:69672]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4227 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2003-07-30 06:10:09 +00:00
Родитель b873f41c1e
Коммит 3404b920d6
4 изменённых файлов: 63 добавлений и 66 удалений

Просмотреть файл

@ -1,3 +1,20 @@
Wed Jul 30 15:10:02 2003 Nobuyoshi Nakada <nobu.nokada@softhome.net>
* error.c (rb_raise): snprintf() termination moved to
win32/win32.c.
* win32/win32.c (valid_filename, str_grow): unused.
* win32/win32.c (NTLoginName, ChildRecord): make static.
* win32/win32.c (CreateChild): argument check.
* win32/win32.c (kill): should not call CloseHandle() when
OpenProcess() failed.
* win32/win32.c (rb_w32_vsnprintf, rb_w32_snprintf): ensure buffer
terminated. [ruby-talk:69672]
Wed Jul 30 10:54:10 2003 Shugo Maeda <shugo@ruby-lang.org>
* lib/net/ftp.rb (get): fix wrong argument name. Thanks to William

Просмотреть файл

@ -690,7 +690,6 @@ rb_raise(exc, fmt, va_alist)
va_init_list(args,fmt);
vsnprintf(buf, BUFSIZ, fmt, args);
buf[BUFSIZ - 1] = '\0';
va_end(args);
rb_exc_raise(rb_exc_new2(exc, buf));
}

Просмотреть файл

@ -91,9 +91,7 @@ bool NtSyncProcess = TRUE;
static struct ChildRecord *CreateChild(char *, char *, SECURITY_ATTRIBUTES *, HANDLE, HANDLE, HANDLE);
static int make_cmdvector(const char *, char ***);
static bool has_redirection(const char *);
static int valid_filename(char *s);
static void StartSockets ();
static char *str_grow(struct RString *str, size_t new_size);
static DWORD wait_events(HANDLE event, DWORD timeout);
#if !defined(__BORLANDC__) && !defined(_WIN32_WCE)
static int rb_w32_open_osfhandle(long osfhandle, int flags);
@ -203,7 +201,7 @@ static int map_errno(void)
return EINVAL;
}
char *NTLoginName;
static char *NTLoginName;
#ifdef WIN95
DWORD Win32System = (DWORD)-1;
@ -406,7 +404,7 @@ char *getlogin()
#define MAXCHILDNUM 256 /* max num of child processes */
struct ChildRecord {
static struct ChildRecord {
HANDLE hProcess; /* process handle */
pid_t pid; /* process id */
} ChildRecord[MAXCHILDNUM];
@ -830,6 +828,11 @@ CreateChild(char *cmd, char *prog, SECURITY_ATTRIBUTES *psa, HANDLE hInput, HAND
char *shell;
struct ChildRecord *child;
if (!cmd && !prog) {
errno = EFAULT;
return NULL;
}
child = FindFreeChildSlot();
if (!child) {
errno = EAGAIN;
@ -1294,13 +1297,7 @@ rb_w32_opendir(const char *filename)
if (rb_w32_stat(filename, &sbuf) < 0)
return NULL;
if (((
#ifdef __BORLANDC__
(unsigned short)(sbuf.st_mode)
#else
sbuf.st_mode
#endif
& _S_IFDIR) == 0) &&
if (!(sbuf.st_mode & S_IFDIR) &&
(!ISALPHA(filename[0]) || filename[1] != ':' || filename[2] != '\0' ||
((1 << (filename[0] & 0x5f) - 'A') & GetLogicalDrives()) == 0)) {
errno = ENOTDIR;
@ -1458,31 +1455,6 @@ rb_w32_closedir(DIR *dirp)
free(dirp);
}
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.
//
if ((fd = _open(s, _O_CREAT, 0666)) >= 0) {
close(fd);
_unlink (s); // don't leave it laying around
return 1;
}
return 0;
}
EXTERN_C void __cdecl _lock_fhandle(int);
EXTERN_C void __cdecl _unlock_fhandle(int);
EXTERN_C void __cdecl _unlock(int);
@ -2457,21 +2429,6 @@ rb_w32_getcwd(buffer, size)
return buffer;
}
static char *
str_grow(struct RString *str, size_t new_size)
{
char *p;
p = realloc(str->ptr, new_size);
if (p == NULL)
rb_fatal("cannot grow string\n");
str->len = new_size;
str->ptr = p;
return p;
}
int
chown(const char *path, int owner, int group)
{
@ -2543,11 +2500,13 @@ kill(int pid, int sig)
}
ret = -1;
}
else if (!TerminateProcess(hProc, 0)) {
else {
if (!TerminateProcess(hProc, 0)) {
errno = EPERM;
ret = -1;
}
CloseHandle(hProc);
}
});
break;
@ -2985,8 +2944,7 @@ int rb_w32_getc(FILE* stream)
{
c = _filbuf(stream);
#if defined __BORLANDC__ || defined _WIN32_WCE
if( ( c == EOF )&&( errno == EPIPE ) )
{
if ((c == EOF) && (errno == EPIPE)) {
clearerr(stream);
}
#endif
@ -3230,7 +3188,7 @@ rb_w32_utime(const char *path, struct utimbuf *times)
if (rb_w32_stat(path, &stat)) {
return -1;
}
if ((stat.st_mode & S_IFDIR) == 0 || IsWin95()) {
if (!(stat.st_mode & S_IFDIR) || IsWin95()) {
return utime(path, times);
}
@ -3255,3 +3213,23 @@ rb_w32_utime(const char *path, struct utimbuf *times)
return ret;
}
int
rb_w32_vsnprintf(char *buf, size_t size, const char *format, va_list va)
{
int ret = _vsnprintf(buf, size, format, va);
if (size > 0) buf[size - 1] = 0;
return ret;
}
int
rb_w32_snprintf(char *buf, size_t size, const char *format, ...)
{
int ret;
va_list va;
va_start(va, format);
ret = vsnprintf(buf, size, format, va);
va_end(va);
return ret;
}

Просмотреть файл

@ -114,8 +114,6 @@ extern "C++" {
#define _open _sopen
#define sopen _sopen
#endif
#define vsnprintf _vsnprintf
#define snprintf _snprintf
#define fsync(h) _commit(h)
#undef stat
#define stat(path,st) rb_w32_stat(path,st)
@ -164,6 +162,11 @@ extern int rb_w32_rename(const char *, const char *);
extern char **rb_w32_get_environ(void);
extern void rb_w32_free_environ(char **);
#define vsnprintf(s,n,f,l) rb_w32_vsnprintf(s,n,f,l)
#define snprintf rb_w32_snprintf
extern int rb_w32_vsnprintf(char *, size_t, const char *, va_list);
extern int rb_w32_snprintf(char *, size_t, const char *, ...);
extern int chown(const char *, int, int);
extern int link(char *, char *);
extern int gettimeofday(struct timeval *, struct timezone *);