summaryrefslogtreecommitdiff
path: root/missing
diff options
context:
space:
mode:
authorYukihiro Matsumoto <matz@ruby-lang.org>1997-10-15 18:08:37 +0900
committerTakashi Kokubun <takashikkbn@gmail.com>2019-08-17 22:09:33 +0900
commit2a4ba10e2d68c09ddb2e3f5751f5161c00a13bf5 (patch)
tree13190036ce10900901e1ff5b559ececbdc05a167 /missing
parent7ad198827b6029d5338c6a2dfe68248da25e9db5 (diff)
version 1.0-971015v1_0_971015
https://cache.ruby-lang.org/pub/ruby/1.0/ruby-1.0-971015.tar.gz Wed Oct 15 18:08:37 1997 Yukihiro Matsumoto <matz@netlab.co.jp> * version 1.0-971015
Diffstat (limited to 'missing')
-rw-r--r--missing/mkdir.c3
-rw-r--r--missing/nt.c105
-rw-r--r--missing/nt.h9
-rw-r--r--missing/x68.c12
4 files changed, 127 insertions, 2 deletions
diff --git a/missing/mkdir.c b/missing/mkdir.c
index b581a5e..ed1476d 100644
--- a/missing/mkdir.c
+++ b/missing/mkdir.c
@@ -1,4 +1,4 @@
-*
+/*
* Written by Robert Rother, Mariah Corporation, August 1985.
*
* If you want it, it's yours. All I ask in return is that if you
@@ -14,6 +14,7 @@
*/
#include <sys/stat.h>
+#include <errno.h>
/*
* Make a directory.
*/
diff --git a/missing/nt.c b/missing/nt.c
index 6674f09..58736ae 100644
--- a/missing/nt.c
+++ b/missing/nt.c
@@ -46,6 +46,109 @@ static char *str_grow(struct RString *str, size_t new_size);
char *NTLoginName;
+DWORD Win32System = (DWORD)-1;
+
+static DWORD
+IdOS(void)
+{
+ static OSVERSIONINFO osver;
+
+ if (osver.dwPlatformId != Win32System) {
+ memset(&osver, 0, sizeof(OSVERSIONINFO));
+ osver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
+ GetVersionEx(&osver);
+ Win32System = osver.dwPlatformId;
+ }
+ return (Win32System);
+}
+
+static int
+IsWin95(void) {
+ return (IdOS() == VER_PLATFORM_WIN32_WINDOWS);
+}
+
+static int
+IsWinNT(void) {
+ return (IdOS() == VER_PLATFORM_WIN32_NT);
+}
+
+
+/* simulate flock by locking a range on the file */
+
+
+#define LK_ERR(f,i) ((f) ? (i = 0) : (errno = GetLastError()))
+#define LK_LEN 0xffff0000
+
+int
+flock(int fd, int oper)
+{
+ OVERLAPPED o;
+ int i = -1;
+ HANDLE fh;
+
+ fh = (HANDLE)_get_osfhandle(fd);
+ memset(&o, 0, sizeof(o));
+
+ if(IsWinNT()) {
+ switch(oper) {
+ case LOCK_SH: /* shared lock */
+ LK_ERR(LockFileEx(fh, 0, 0, LK_LEN, 0, &o),i);
+ break;
+ case LOCK_EX: /* exclusive lock */
+ LK_ERR(LockFileEx(fh, LOCKFILE_EXCLUSIVE_LOCK, 0, LK_LEN, 0, &o),i);
+ break;
+ case LOCK_SH|LOCK_NB: /* non-blocking shared lock */
+ LK_ERR(LockFileEx(fh, LOCKFILE_FAIL_IMMEDIATELY, 0, LK_LEN, 0, &o),i);
+ break;
+ case LOCK_EX|LOCK_NB: /* non-blocking exclusive lock */
+ LK_ERR(LockFileEx(fh,
+ LOCKFILE_EXCLUSIVE_LOCK|LOCKFILE_FAIL_IMMEDIATELY,
+ 0, LK_LEN, 0, &o),i);
+ if(errno == EDOM) errno = EWOULDBLOCK;
+ break;
+ case LOCK_UN: /* unlock lock */
+ if (UnlockFileEx(fh, 0, LK_LEN, 0, &o)) {
+ i = 0;
+ }
+ else {
+ /* GetLastError() must returns `ERROR_NOT_LOCKED' */
+ errno = EWOULDBLOCK;
+ }
+ if(errno == EDOM) errno = EWOULDBLOCK;
+ break;
+ default: /* unknown */
+ errno = EINVAL;
+ break;
+ }
+ }
+ else if(IsWin95()) {
+ switch(oper) {
+ case LOCK_EX:
+ while(i == -1) {
+ LK_ERR(LockFile(fh, 0, 0, LK_LEN, 0), i);
+ if(errno != EDOM && i == -1) break;
+ }
+ break;
+ case LOCK_EX | LOCK_NB:
+ LK_ERR(LockFile(fh, 0, 0, LK_LEN, 0), i);
+ if(errno == EDOM) errno = EWOULDBLOCK;
+ break;
+ case LOCK_UN:
+ LK_ERR(UnlockFile(fh, 0, 0, LK_LEN, 0), i);
+ if(errno == EDOM) errno = EWOULDBLOCK;
+ break;
+ default:
+ errno = EINVAL;
+ break;
+ }
+ }
+ return i;
+}
+
+#undef LK_ERR
+#undef LK_LEN
+
+
#undef const
FILE *fdopen(int, const char *);
@@ -467,7 +570,7 @@ mypopen (char *cmd, char *mode)
fd = _open_osfhandle((long)hOutFile, (_O_WRONLY | pipemode));
CloseHandle(hInFile);
DuplicateHandle(GetCurrentProcess(), hStdin,
- GetCurrentProcess(), &hDummy,
+ GetCurrentProcess(), &hDummy,
0, TRUE, (DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE)
);
}
diff --git a/missing/nt.h b/missing/nt.h
index cf9f4cb..70132b4 100644
--- a/missing/nt.h
+++ b/missing/nt.h
@@ -147,6 +147,7 @@ extern int NtMakeCmdVector(char *, char ***, int);
extern char *NtGetLib(void);
extern char *NtGetBin(void);
extern FILE *mypopen(char *, char *);
+extern int flock(int fd, int oper);
//
// define this so we can do inplace editing
@@ -190,6 +191,14 @@ extern char *mystrerror(int);
#define HAVE_WAITPID 1
#define HAVE_GETCWD 1
+#define LOCK_SH 1
+#define LOCK_EX 2
+#define LOCK_NB 4
+#define LOCK_UN 8
+#ifndef EWOULDBLOCK
+#define EWOULDBLOCK 10035 /* EBASEERR + 35 (winsock.h) */
+#endif
+
#ifdef popen
#undef popen
#define popen mypopen
diff --git a/missing/x68.c b/missing/x68.c
new file mode 100644
index 0000000..8fd9c3e
--- /dev/null
+++ b/missing/x68.c
@@ -0,0 +1,12 @@
+#include "config.h"
+
+#if !HAVE_SELECT
+#include "x68/select.c"
+#endif
+#if MISSING__DTOS18
+#include "x68/_dtos18.c"
+#endif
+#if MISSING_FCONVERT
+#include "x68/_round.c"
+#include "x68/fconvert.c"
+#endif