aboutsummaryrefslogtreecommitdiffstats
path: root/vms/vms_misc.c
diff options
context:
space:
mode:
Diffstat (limited to 'vms/vms_misc.c')
-rw-r--r--vms/vms_misc.c58
1 files changed, 48 insertions, 10 deletions
diff --git a/vms/vms_misc.c b/vms/vms_misc.c
index c7044348..58231ff4 100644
--- a/vms/vms_misc.c
+++ b/vms/vms_misc.c
@@ -23,7 +23,13 @@
* the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
-#include "awk.h" /* really "../awk.h" */
+#define creat creat_dummy /* one of gcc-vms's headers has bad prototype */
+#include "awk.h"
+#undef creat
+#include <fab.h>
+#ifndef O_RDONLY
+#include <fcntl.h>
+#endif
#include <ssdef.h>
#include <stsdef.h>
@@ -36,9 +42,9 @@
# undef exit
#endif
void
-vms_exit( int errno ) /* note: local override of global 'errno' */
+vms_exit( int final_status )
{
- exit(errno == 0 ? SS$_NORMAL : (SS$_ABORT | STS$M_INHIB_MSG));
+ exit(final_status == 0 ? SS$_NORMAL : (SS$_ABORT | STS$M_INHIB_MSG));
}
#define exit(v) vms_exit(v)
@@ -55,7 +61,7 @@ vms_exit( int errno ) /* note: local override of global 'errno' */
char *
vms_strerror( int errnum )
{
- extern char *strerror( /* int, ... */ );
+ extern char *strerror P((int,...));
return ( errnum != EVMSERR ? strerror(errnum)
: strerror(EVMSERR, vaxc$errno) );
}
@@ -93,21 +99,53 @@ unlink( const char *file_spec ) {
}
/*
+ * Work-around an open(O_CREAT+O_TRUNC) bug (screwed up modification
+ * and creation dates when new version is created), and also use some
+ * VMS-specific file options. Note: optional 'prot' arg is completely
+ * ignored; gawk doesn't need it.
+ */
+#ifdef open
+# undef open
+#endif
+/* vms_open() - open a file, possibly creating it */
+int
+vms_open( const char *name, int mode, ... )
+{
+ extern int creat P((const char *,int,...));
+ extern int open P((const char *,int,unsigned,...));
+
+ if (mode == (O_WRONLY|O_CREAT|O_TRUNC))
+ return creat(name, 0, "shr=nil", "mbc=24");
+ else {
+ struct stat stb;
+ const char *mbc, *shr = "shr=get";
+
+ if (stat(name, &stb) < 0) { /* assume DECnet */
+ mbc = "mbc=8";
+ } else { /* ordinary file; allow full sharing iff record format */
+ mbc = "mbc=12";
+ if (stb.st_fab_rfm < FAB$C_STM) shr = "shr=get,put,upd";
+ }
+ return open(name, mode, 0, shr, mbc, "mbf=2");
+ }
+}
+
+ /*
* Check for attempt to (re-)open known file.
*/
/* vms_devopen() - check for "SYS$INPUT" or "SYS$OUTPUT" or "SYS$ERROR" */
int
-vms_devopen( const char *name )
+vms_devopen( const char *name, int mode )
{
FILE *file = NULL;
if (strncasecmp(name, "SYS$", 4) == 0) {
name += 4; /* skip "SYS$" */
- if (strncasecmp(name, "INPUT", 5) == 0)
+ if (strncasecmp(name, "INPUT", 5) == 0 && (mode & O_WRONLY) == 0)
file = stdin, name += 5;
- else if (strncasecmp(name, "OUTPUT", 6) == 0)
+ else if (strncasecmp(name, "OUTPUT", 6) == 0 && (mode & O_WRONLY) != 0)
file = stdout, name += 6;
- else if (strncasecmp(name, "ERROR", 5) == 0)
+ else if (strncasecmp(name, "ERROR", 5) == 0 && (mode & O_WRONLY) != 0)
file = stderr, name += 5;
if (*name == ':') name++; /* treat trailing colon as optional */
}
@@ -132,9 +170,9 @@ void tzset()
# ifdef bcopy
# undef bcopy
# endif
-void bcopy( char *src, char *dst, int len )
+void bcopy( const char *src, char *dst, int len )
{
- (void) OTS$MOVE3(len, src, dst);
+ (void) memcpy(dst, src, len);
}
#endif /*!__GNUC__*/