vms file access

Fix the problem From a bug report.  His system has a logical name "DATA" pointing at some disk, and
when the dlb utility tried to open "data" for inclusion in the library
being built at install time, it attempted to access the wrong thing and
failed.  He then attempted to fix it in a manner which let dlb finish, by
modifying dlb_main.c to append "." to file names that lack a dot, but
then nethack couldn't access "dungeon" in the library because string
comparison didn't match the altered dlb directory entry of "dungeon.".

     NetHack was working around this unintended interaction with the
environment issue in fopen_datafile(), and dlb was doing so for fopen()
but not open().  This moves nethack's fixup out of src/files.c and into
sys/vms/vmsfiles.c, adds another routine there so that both open() and
fopen() are covered, and updates the vms Makefiles so that the various
utility programs all link with vmsfiles.  (The build script vmsbuild.com
puts object files into a library and gets that last bit for free.)
This commit is contained in:
nethack.rankin
2007-10-28 09:37:56 +00:00
parent cac2dd4d33
commit a675cc6ed7
7 changed files with 64 additions and 57 deletions
+2
View File
@@ -377,6 +377,8 @@ tty+GOLDOBJ: dropping or looting by menu wouldn't honor a count for gold
unix: remove use of parentheses in nethack man page usage that confused a unix: remove use of parentheses in nethack man page usage that confused a
man page conversion tool man page conversion tool
unix,vms: allow digits after first character in name at "Who are you?" prompt unix,vms: allow digits after first character in name at "Who are you?" prompt
vms: the DLB configuration could fail to build if a file without a dot
in its name happened to match a logical name
winCE: disable processing of double-click messages if the first click winCE: disable processing of double-click messages if the first click
causes map to scroll causes map to scroll
Windows, probably MSDOS and OS/2: attempting to use very first false rumor Windows, probably MSDOS and OS/2: attempting to use very first false rumor
+4 -1
View File
@@ -1,4 +1,4 @@
/* SCCS Id: @(#)vmsconf.h 3.5 2006/09/22 */ /* SCCS Id: @(#)vmsconf.h 3.5 2007/10/27 */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/* NetHack may be freely redistributed. See license for details. */ /* NetHack may be freely redistributed. See license for details. */
@@ -247,6 +247,7 @@ typedef __mode_t mode_t;
#define getuid() vms_getuid() /* vmsunix.c */ #define getuid() vms_getuid() /* vmsunix.c */
#define link(f1,f2) vms_link(f1,f2) /* vmsfiles.c */ #define link(f1,f2) vms_link(f1,f2) /* vmsfiles.c */
#define open(f,k,m) vms_open(f,k,m) /* vmsfiles.c */ #define open(f,k,m) vms_open(f,k,m) /* vmsfiles.c */
#define fopen(f,m) vms_fopen(f,m) /* vmsfiles.c */
/* #define unlink(f0) vms_unlink(f0) /* vmsfiles.c */ /* #define unlink(f0) vms_unlink(f0) /* vmsfiles.c */
#ifdef VERYOLD_VMS #ifdef VERYOLD_VMS
#define unlink(f0) delete(f0) /* vaxcrtl */ #define unlink(f0) delete(f0) /* vaxcrtl */
@@ -266,6 +267,8 @@ typedef __mode_t mode_t;
/* used in several files which don't #include "extern.h" */ /* used in several files which don't #include "extern.h" */
extern void FDECL(vms_exit, (int)); extern void FDECL(vms_exit, (int));
extern int FDECL(vms_open, (const char *,int,unsigned)); extern int FDECL(vms_open, (const char *,int,unsigned));
extern FILE *FDECL(vms_fopen, (const char *,const char *));
char *FDECL(vms_basename, (const char *)); /* vmsfiles.c */
#endif /* VMSCONF_H */ #endif /* VMSCONF_H */
#endif /* VMS */ #endif /* VMS */
+1 -11
View File
@@ -1,4 +1,4 @@
/* SCCS Id: @(#)files.c 3.5 2007/01/08 */ /* SCCS Id: @(#)files.c 3.5 2007/10/27 */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/* NetHack may be freely redistributed. See license for details. */ /* NetHack may be freely redistributed. See license for details. */
@@ -391,17 +391,7 @@ int prefix;
FILE *fp; FILE *fp;
filename = fqname(filename, prefix, prefix == TROUBLEPREFIX ? 3 : 0); filename = fqname(filename, prefix, prefix == TROUBLEPREFIX ? 3 : 0);
#ifdef VMS /* essential to have punctuation, to avoid logical names */
{
char tmp[BUFSIZ];
if (!index(filename, '.') && !index(filename, ';'))
filename = strcat(strcpy(tmp, filename), ";0");
fp = fopen(filename, mode, "mbc=16");
}
#else
fp = fopen(filename, mode); fp = fopen(filename, mode);
#endif
return fp; return fp;
} }
+3 -3
View File
@@ -1,5 +1,5 @@
# NetHack Makefile (VMS) - for building nethack itself. # NetHack Makefile (VMS) - for building nethack itself.
# SCCS Id: @(#)Makefile.src 3.5 2006/01/07 # SCCS Id: @(#)Makefile.src 3.5 2007/10/27
# Copy this file to [.src]Makefile. and then edit it as needed. # Copy this file to [.src]Makefile. and then edit it as needed.
# The default configuration is for building with DEC C (aka Compaq C). # The default configuration is for building with DEC C (aka Compaq C).
@@ -49,7 +49,7 @@ MORELIBS =
# Specific VMS object files # Specific VMS object files
SYSSRC = $(VMS)vmsmain.c,$(VMS)vmstty.c,$(VMS)vmsunix.c,\ SYSSRC = $(VMS)vmsmain.c,$(VMS)vmstty.c,$(VMS)vmsunix.c,\
$(VMS)vmsmisc.c,$(VMS)vmsfiles.c,$(VMS)vmsmail.c $(VMS)vmsmisc.c,$(VMS)vmsfiles.c,$(VMS)vmsmail.c
SYSOBJ = vmsmain.obj,vmstty.obj,vmsunix.obj,vmsfiles.obj,vmsmail.obj #,vmsmisc.obj SYSOBJ = vmsmain.obj,vmstty.obj,vmsunix.obj,vmsmail.obj #,vmsmisc.obj,vmsfiles.obj
LIBOPT = $(SRC)crtl.opt; LIBOPT = $(SRC)crtl.opt;
# termcap library # termcap library
@@ -139,7 +139,7 @@ HACKINCL = align.h amiconf.h artifact.h artilist.h attrib.h beconf.h color.h \
# lev_comp.h dgn_comp.h dgn_file.h # lev_comp.h dgn_comp.h dgn_file.h
# the following .obj's should be made before any others (for makedefs) # the following .obj's should be made before any others (for makedefs)
FIRSTOBJ = vmsmisc.obj,monst.obj,objects.obj FIRSTOBJ = vmsmisc.obj,vmsfiles.obj,monst.obj,objects.obj
# split up long list so that we can write pieces of it into nethack.opt # split up long list so that we can write pieces of it into nethack.opt
HOBJ1 = allmain.obj,alloc.obj,apply.obj,artifact.obj,attrib.obj, \ HOBJ1 = allmain.obj,alloc.obj,apply.obj,artifact.obj,attrib.obj, \
+13 -16
View File
@@ -1,5 +1,5 @@
# NetHack Makefile (VMS) - for utility programs. # NetHack Makefile (VMS) - for utility programs.
# SCCS Id: @(#)Makefile.utl 3.5 2006/03/15 # SCCS Id: @(#)Makefile.utl 3.5 2007/10/27
# Copy this file to [.util]Makefile. and then edit it as needed. # Copy this file to [.util]Makefile. and then edit it as needed.
# The default configuration is for building with DEC C (aka Compaq C). # The default configuration is for building with DEC C (aka Compaq C).
@@ -91,6 +91,8 @@ RECOVSRC = recover.c
DLBSRC = dlb_main.c DLBSRC = dlb_main.c
UTILSRCS = $(MAKESRC) $(SPLEVSRC) $(DGNCOMPSRC) $(RECOVSRC) $(DLBSRC) panic.c UTILSRCS = $(MAKESRC) $(SPLEVSRC) $(DGNCOMPSRC) $(RECOVSRC) $(DLBSRC) panic.c
VMSOBJS = $(SRC)vmsmisc.obj,$(SRC)vmsfiles.obj
# object files that provide access to NetHack's names # object files that provide access to NetHack's names
NAMEOBJ1 = $(SRC)monst.obj,$(SRC)objects.obj NAMEOBJ1 = $(SRC)monst.obj,$(SRC)objects.obj
NAMEOBJ2 = $(SRC)drawing.obj,$(SRC)decl.obj NAMEOBJ2 = $(SRC)drawing.obj,$(SRC)decl.obj
@@ -98,24 +100,19 @@ NAMEOBJS = $(NAMEOBJ1),$(NAMEOBJ2)
# object files for makedefs # object files for makedefs
MAKEOBJS = makedefs.obj,$(NAMEOBJ1) MAKEOBJS = makedefs.obj,$(NAMEOBJ1)
VMSMAKEOBJS = $(SRC)vmsmisc.obj
# object files for special levels compiler # object files for special levels compiler
SPLEVOBJS = lev_main.obj,lev_yacc.obj,lev_lex.obj,panic.obj,\ SPLEVOBJS = lev_main.obj,lev_yacc.obj,lev_lex.obj,panic.obj,\
$(SRC)alloc.obj,$(NAMEOBJS) $(SRC)alloc.obj,$(NAMEOBJS)
VMSSPLEVOBJS = $(SRC)vmsmisc.obj,$(SRC)vmsfiles.obj
# object files for dungeon compiler # object files for dungeon compiler
DGNCOMPOBJS = dgn_main.obj,dgn_yacc.obj,dgn_lex.obj,panic.obj,$(SRC)alloc.obj DGNCOMPOBJS = dgn_main.obj,dgn_yacc.obj,dgn_lex.obj,panic.obj,$(SRC)alloc.obj
VMSDGNCOBJS = $(SRC)vmsmisc.obj
# object files for recovery utility # object files for recovery utility
RECOVOBJS = recover.obj RECOVOBJS = recover.obj
VMSRECOBJS = $(SRC)vmsmisc.obj,$(SRC)vmsfiles.obj
# object files for dlb utility # object files for dlb utility
DLBOBJS = dlb_main.obj,panic.obj,$(SRC)alloc.obj,$(SRC)dlb.obj DLBOBJS = dlb_main.obj,panic.obj,$(SRC)alloc.obj,$(SRC)dlb.obj
VMSDLBOBJS = $(SRC)vmsmisc.obj,$(SRC)vmsfiles.obj
# fake target # fake target
@@ -154,8 +151,8 @@ $(LIBOPT) : $(SRC)Makefile.; # linker options file
# dependencies for makedefs # dependencies for makedefs
# #
$(MAKEDEFS) : $(MAKEOBJS) $(VMSMAKEOBJS) $(LIBOPT) $(MAKEDEFS) : $(MAKEOBJS) $(VMSOBJS) $(LIBOPT)
$(LINK) $(LFLAGS) $(MAKEOBJS),$(VMSMAKEOBJS),$(LIBS) $(LINK) $(LFLAGS) $(MAKEOBJS),$(VMSOBJS),$(LIBS)
@ $(TOUCH) $(MARKER) @ $(TOUCH) $(MARKER)
makedefs.obj : makedefs.c \ makedefs.obj : makedefs.c \
@@ -184,8 +181,8 @@ $(INC)date.h : $(MAKEDEFS)
# dependencies for lev_comp # dependencies for lev_comp
# #
$(LEVCOMP) : $(SPLEVOBJS) $(VMSSPLEVOBJS) # $(LIBOPT) $(LEVCOMP) : $(SPLEVOBJS) $(VMSOBJS) # $(LIBOPT)
$(LINK)/Exe=$(LEVCOMP) $(LFLAGS) $(SPLEVOBJS),$(VMSSPLEVOBJS),$(LIBS) $(LINK)/Exe=$(LEVCOMP) $(LFLAGS) $(SPLEVOBJS),$(VMSOBJS),$(LIBS)
lev_yacc.obj : $(HACK_H) $(INC)sp_lev.h lev_yacc.c lev_yacc.obj : $(HACK_H) $(INC)sp_lev.h lev_yacc.c
$(CC) $(CFLAGS) lev_yacc.c $(CC) $(CFLAGS) lev_yacc.c
@@ -217,8 +214,8 @@ lev_lex.c : lev_comp.l
# dependencies for dgn_comp # dependencies for dgn_comp
# #
$(DGNCOMP) : $(DGNCOMPOBJS) $(VMSDGNCOBJS) # $(LIBOPT) $(DGNCOMP) : $(DGNCOMPOBJS) $(VMSOBJS) # $(LIBOPT)
$(LINK)/Exe=$(DGNCOMP) $(LFLAGS) $(DGNCOMPOBJS),$(VMSDGNCOBJS),$(LIBS) $(LINK)/Exe=$(DGNCOMP) $(LFLAGS) $(DGNCOMPOBJS),$(VMSOBJS),$(LIBS)
dgn_yacc.obj : $(CONFIG_H) $(INC)dgn_file.h $(INC)date.h dgn_yacc.c dgn_yacc.obj : $(CONFIG_H) $(INC)dgn_file.h $(INC)date.h dgn_yacc.c
$(CC) $(CFLAGS) dgn_yacc.c $(CC) $(CFLAGS) dgn_yacc.c
@@ -248,15 +245,15 @@ dgn_lex.c : dgn_comp.l
# dependencies for recover # dependencies for recover
# #
$(RECOVER) : $(RECOVOBJS) $(VMSRECOBJS) # $(LIBOPT) $(RECOVER) : $(RECOVOBJS) $(VMSOBJS) # $(LIBOPT)
$(LINK) $(LFLAGS) $(RECOVOBJS),$(VMSRECOBJS),$(LIBS) $(LINK) $(LFLAGS) $(RECOVOBJS),$(VMSOBJS),$(LIBS)
recover.obj : $(CONFIG_H) recover.c recover.obj : $(CONFIG_H) recover.c
# dependencies for dlb # dependencies for dlb
# #
$(DLB) : $(DLBOBJS) $(VMSDLBOBJS) # $(LIBOPT) $(DLB) : $(DLBOBJS) $(VMSOBJS) # $(LIBOPT)
$(LINK)/Exe=$(DLB) $(LFLAGS) $(DLBOBJS),$(VMSDLBOBJS),$(LIBS) $(LINK)/Exe=$(DLB) $(LFLAGS) $(DLBOBJS),$(VMSOBJS),$(LIBS)
dlb_main.obj : $(CONFIG_H) $(INC)dlb.h dlb_main.c dlb_main.obj : $(CONFIG_H) $(INC)dlb.h dlb_main.c
+40 -6
View File
@@ -1,4 +1,4 @@
/* SCCS Id: @(#)vmsfiles.c 3.5 1999/08/29 */ /* SCCS Id: @(#)vmsfiles.c 3.5 2007/10/27 */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/* NetHack may be freely redistributed. See license for details. */ /* NetHack may be freely redistributed. See license for details. */
@@ -13,10 +13,8 @@
int FDECL(vms_link, (const char *,const char *)); int FDECL(vms_link, (const char *,const char *));
int FDECL(vms_unlink, (const char *)); int FDECL(vms_unlink, (const char *));
int FDECL(vms_creat, (const char *,unsigned int)); int FDECL(vms_creat, (const char *,unsigned int));
int FDECL(vms_open, (const char *,int,unsigned int));
boolean FDECL(same_dir, (const char *,const char *)); boolean FDECL(same_dir, (const char *,const char *));
int FDECL(c__translate, (int)); int FDECL(c__translate, (int));
char *FDECL(vms_basename, (const char *));
#include <rms.h> #include <rms.h>
#if 0 #if 0
@@ -113,16 +111,22 @@ const char *file;
and use 32 block buffer for faster throughput; ~30% speedup measured.) and use 32 block buffer for faster throughput; ~30% speedup measured.)
*/ */
#undef creat #undef creat
int vms_creat(file, mode) int
vms_creat(file, mode)
const char *file; const char *file;
unsigned int mode; unsigned int mode;
{ {
char filnambuf[BUFSIZ]; /*(not BUFSZ)*/
if (index(file, ';')) { if (index(file, ';')) {
/* assumes remove or delete, not vms_unlink */ /* assumes remove or delete, not vms_unlink */
if (!unlink(file)) { if (!unlink(file)) {
(void)sleep(1); (void)sleep(1);
(void)unlink(file); (void)unlink(file);
} }
} else if (!index(file, '.')) {
/* force some punctuation to be present */
file = strcat(strcpy(filnambuf, file), ".");
} }
return creat(file, mode, "shr=nil", "mbc=32", "mbf=2", "rop=wbh"); return creat(file, mode, "shr=nil", "mbc=32", "mbf=2", "rop=wbh");
} }
@@ -133,13 +137,21 @@ unsigned int mode;
at least one NFS implementation). at least one NFS implementation).
*/ */
#undef open #undef open
int vms_open(file, flags, mode) int
vms_open(file, flags, mode)
const char *file; const char *file;
int flags; int flags;
unsigned int mode; unsigned int mode;
{ {
int fd = open(file, flags, mode, "mbc=32", "mbf=2", "rop=rah"); char filnambuf[BUFSIZ]; /*(not BUFSZ)*/
int fd;
if (!index(file, '.') && !index(file, ';')) {
/* force some punctuation to be present to make sure that
the file name can't accidentally match a logical name */
file = strcat(strcpy(filnambuf, file), ";0");
}
fd = open(file, flags, mode, "mbc=32", "mbf=2", "rop=rah");
if (fd < 0 && errno == EVMSERR && lib$match_cond(vaxc$errno, RMS$_FLK)) { if (fd < 0 && errno == EVMSERR && lib$match_cond(vaxc$errno, RMS$_FLK)) {
(void)sleep(1); (void)sleep(1);
fd = open(file, flags, mode, "mbc=32", "mbf=2", "rop=rah"); fd = open(file, flags, mode, "mbc=32", "mbf=2", "rop=rah");
@@ -147,6 +159,28 @@ unsigned int mode;
return fd; return fd;
} }
/* do likewise for fopen() */
#undef fopen
FILE *
vms_fopen(file, mode)
const char *file, *mode;
{
char filnambuf[BUFSIZ]; /*(not BUFSZ)*/
FILE *fp;
if (!index(file, '.') && !index(file, ';')) {
/* force some punctuation to be present to make sure that
the file name can't accidentally match a logical name */
file = strcat(strcpy(filnambuf, file), ";0");
}
fp = fopen(file, mode, "mbc=32", "mbf=2", "rop=rah");
if (!fp && errno == EVMSERR && lib$match_cond(vaxc$errno, RMS$_FLK)) {
(void)sleep(1);
fp = fopen(file, mode, "mbc=32", "mbf=2", "rop=rah");
}
return fp;
}
/* /*
Determine whether two strings contain the same directory name. Determine whether two strings contain the same directory name.
Used for deciding whether installed privileges should be disabled Used for deciding whether installed privileges should be disabled
+1 -20
View File
@@ -1,4 +1,4 @@
/* SCCS Id: @(#)dlb_main.c 3.5 1998/08/16 */ /* SCCS Id: @(#)dlb_main.c 3.5 2007/10/27 */
/* Copyright (c) Kenneth Lorber, Bethesda, Maryland, 1993. */ /* Copyright (c) Kenneth Lorber, Bethesda, Maryland, 1993. */
/* NetHack may be freely redistributed. See license for details. */ /* NetHack may be freely redistributed. See license for details. */
@@ -28,11 +28,6 @@ extern void FDECL(close_library,(library *));
char *FDECL(eos, (char *)); /* also used by dlb.c */ char *FDECL(eos, (char *)); /* also used by dlb.c */
FILE *FDECL(fopen_datafile, (const char *,const char *)); FILE *FDECL(fopen_datafile, (const char *,const char *));
#ifdef VMS
extern char *FDECL(vms_basename, (const char *));
extern int FDECL(vms_open, (const char *,int,unsigned int));
#endif
static void FDECL(Write, (int,char *,long)); static void FDECL(Write, (int,char *,long));
static void NDECL(usage); static void NDECL(usage);
static void NDECL(verbose_help); static void NDECL(verbose_help);
@@ -150,20 +145,6 @@ eos(s)
} }
#ifdef VMS /* essential to have punctuation, to avoid logical names */
static FILE *
vms_fopen(filename, mode)
const char *filename, *mode;
{
char tmp[BUFSIZ];
if (!index(filename, '.') && !index(filename, ';'))
filename = strcat(strcpy(tmp, filename), ";0");
return fopen(filename, mode, "mbc=16");
}
#define fopen vms_fopen
#endif /* VMS */
/* open_library(dlb.c) needs this (which normally comes from src/files.c) */ /* open_library(dlb.c) needs this (which normally comes from src/files.c) */
FILE * FILE *
fopen_datafile(filename, mode) fopen_datafile(filename, mode)