summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog17
-rw-r--r--error.c1
-rw-r--r--win32/win32.c104
-rw-r--r--win32/win32.h7
4 files changed, 63 insertions, 66 deletions
diff --git a/ChangeLog b/ChangeLog
index 0ed5f30d40..642ee4ac00 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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
diff --git a/error.c b/error.c
index fb900b26a4..f8fbdf7ade 100644
--- a/error.c
+++ b/error.c
@@ -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));
}
diff --git a/win32/win32.c b/win32/win32.c
index f334e2f746..881f1597fa 100644
--- a/win32/win32.c
+++ b/win32/win32.c
@@ -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;
@@ -380,8 +378,8 @@ NtInitialize(int *argc, char ***argv)
StartSockets();
#ifdef _WIN32_WCE
- // free commandline buffer
- wce_FreeCommandLine();
+ // free commandline buffer
+ wce_FreeCommandLine();
#endif
}
@@ -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)) {
- errno = EPERM;
- ret = -1;
+ else {
+ if (!TerminateProcess(hProc, 0)) {
+ errno = EPERM;
+ ret = -1;
+ }
+ CloseHandle(hProc);
}
- CloseHandle(hProc);
});
break;
@@ -2982,12 +2941,11 @@ int rb_w32_getc(FILE* stream)
}
else
#endif
- {
+ {
c = _filbuf(stream);
#if defined __BORLANDC__ || defined _WIN32_WCE
- if( ( c == EOF )&&( errno == EPIPE ) )
- {
- clearerr(stream);
+ if ((c == EOF) && (errno == EPIPE)) {
+ clearerr(stream);
}
#endif
rb_trap_immediate = trap_immediate;
@@ -3007,7 +2965,7 @@ int rb_w32_putc(int c, FILE* stream)
}
else
#endif
- {
+ {
c = _flsbuf(c, stream);
rb_trap_immediate = trap_immediate;
catch_interrupt();
@@ -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;
+}
diff --git a/win32/win32.h b/win32/win32.h
index d04ea376e6..eb13e2b3a1 100644
--- a/win32/win32.h
+++ b/win32/win32.h
@@ -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 *);