FDclone 2.08f patch [1/2]
しらいです。
file & directory 管理ツール FDclone 2.08f の patch その 1
です。
Submitted-by: shirai@chandra2
Archive-name: FD-2.08f.patch/part01
---- Cut Here and feed the following to sh ----
#!/bin/sh
# This is FD-2.08f.patch, a shell archive (produced by GNU sharutils 4.2)
# To extract the files from this archive, save it to some FILE, remove
# everything before the `!/bin/sh' line above, then type `sh FILE'.
#
# Made on 2006-08-08 00:00 JST by <shirai@chandra2>.
# Source directory was `/usr/home/shirai/src/fd2'.
#
# Existing files will *not* be overwritten unless `-c' is specified.
#
# This is part 1 of a multipart archive.
# Do not concatenate these parts, unpack them in order with `/bin/sh'.
#
# This shar contains:
# length mode name
# ------ ---------- ------------------------------------------
# 61441 -rw-r--r-- FD-2.08f.patch
#
echo=echo
touch -am 1231235999 $$.touch >/dev/null 2>&1
if test ! -f 1231235999 && test -f $$.touch; then
shar_touch=touch
else
shar_touch=:
echo
$echo 'WARNING: not restoring timestamps. Consider getting and'
$echo "installing GNU \`touch', distributed in GNU File Utilities..."
echo
fi
rm -f 1231235999 $$.touch
#
if mkdir _sh01590; then
$echo 'x -' 'creating lock directory'
else
$echo 'failed to create lock directory'
exit 1
fi
if test -r _sh01590/seq; then
$echo 'Must unpack archives in sequence!'
$echo 'Please unpack part' '`cat _sh01590/seq`' 'next!'
exit 1
fi
# ============= FD-2.08f.patch ==============
if test -f 'FD-2.08f.patch' && test "$first_param" != -c; then
$echo 'x -' SKIPPING 'FD-2.08f.patch' '(file already exists)'
rm -f _sh01590/new
else
> _sh01590/new
$echo 'x -' extracting 'FD-2.08f.patch' '(text)'
sed 's/^X//' << 'SHAR_EOF' > 'FD-2.08f.patch' &&
diff -urNP ../FD-2.08e/HISTORY ./HISTORY
--- ../FD-2.08e/HISTORY Fri Jul 28 00:00:00 2006
+++ ./HISTORY Tue Aug 8 00:00:00 2006
@@ -1,3 +1,9 @@
+Ver. 2.08f NFS 上の履歴セーブファイル保護用にファイルロックに対応。
+ (08/08/06) 非 ANSI 環境でコンパイルに失敗する点を修正。
+ Cygwin 1.5.21 対応。
+ IGNORECASE=1 時に日本語ファイル名ソートがおかしかった点を修正。
+ UNICODE テーブルが壊れていた点を修正。(MS-DOS 版)
+
X Ver. 2.08e カスタマイザの ANSIPALETTE 項目をメニュー化。
X (07/28/06) カスタマイザの PTYMENUKEY 項目をキー入力による設定に変更。
X カスタマイザで EDITOR, PAGER 等の内部変数を設定できるよう修正。
diff -urNP ../FD-2.08e/HISTORY.eng ./HISTORY.eng
--- ../FD-2.08e/HISTORY.eng Fri Jul 28 00:00:00 2006
+++ ./HISTORY.eng Tue Aug 8 00:00:00 2006
@@ -1,3 +1,9 @@
+Ver. 2.08f Support locking on NFS to protect the command history file.
+ (08/08/06) Failure to compile on the non-ANSI environment is fixed.
+ Support Cygwin 1.5.21.
+ Mis-sorting for Japanese filenames on IGNORECASE=1 is fixed.
+ Broken UNICODE table is fixed. (MS-DOS)
+
X Ver. 2.08e Support the menu method for 'ANSIPALETTE' on customizer.
X (07/28/06) Support the key-input method for 'PTYMENUKEY' on customizer.
X Support the setting of "EDITOR", "PAGER", etc. on customizer.
diff -urNP ../FD-2.08e/Makefile ./Makefile
--- ../FD-2.08e/Makefile Fri Jul 28 00:00:00 2006
+++ ./Makefile Tue Aug 8 00:00:00 2006
@@ -95,7 +95,7 @@
X
X sh bsh \
X fd.doc README.doc HISTORY.doc FAQ.doc LICENSES.doc \
-depend clean: Makefile.tmp
+depend: Makefile.tmp
X $(MAKE) -f Makefile.tmp $@
X
X config: rmconfig Makefile.tmp
@@ -117,6 +117,11 @@
X makefile.bpc makefile.b98
X $(MAKE) -f Makefile.tmp $@
X
+clean: Makefile.tmp
+ $(MAKE) -f Makefile.tmp $@
+ -rm -f Makefile.tmp mkmf.sed
+ -rm -f mkmfsed mkmfsed.exe
+
X realclean: Makefile.tmp
X $(MAKE) -f Makefile.tmp clean
X -rm -f Makefile.tmp mkmf.sed config.h
@@ -124,4 +129,4 @@
X -rm -f makefile.dpc makefile.d98
X -rm -f makefile.lpc makefile.l98
X -rm -f makefile.bpc makefile.b98
- -rm -f mkmfsed
+ -rm -f mkmfsed mkmfsed.exe
diff -urNP ../FD-2.08e/Makefile.in ./Makefile.in
--- ../FD-2.08e/Makefile.in Fri Jul 28 00:00:00 2006
+++ ./Makefile.in Tue Aug 8 00:00:00 2006
@@ -671,11 +671,10 @@
X builtin__OBJ__: wait.h
X builtin__OBJ__: termemu.h
X shell__OBJ__: fd.h
-shell__OBJ__: machine.h config.h
-shell__OBJ__: types.h
-shell__OBJ__: printf.h kctype.h
-shell__OBJ__: pathname.h term.h
-shell__OBJ__: func.h
+shell__OBJ__: machine.h config.h types.h
+shell__OBJ__: printf.h
+shell__OBJ__: kctype.h
+shell__OBJ__: pathname.h term.h func.h
X shell__OBJ__: dosdisk.h kanji.h system.h termio.h
X shell__OBJ__: wait.h
X shell__OBJ__: termemu.h
diff -urNP ../FD-2.08e/README ./README
--- ../FD-2.08e/README Fri Jul 28 00:00:00 2006
+++ ./README Tue Aug 8 00:00:00 2006
@@ -3,7 +3,7 @@
X # FDclone Ver. 2.08 に関して
X #
X # Takashi SHIRAI, <shirai@unixusers.net>
-# Jul 28, 2006
+# Aug 8, 2006
X #
X ############################################################
X
diff -urNP ../FD-2.08e/README.eng ./README.eng
--- ../FD-2.08e/README.eng Fri Jul 28 00:00:00 2006
+++ ./README.eng Tue Aug 8 00:00:00 2006
@@ -3,7 +3,7 @@
X # About FDclone Ver. 2.08
X #
X # Takashi SHIRAI, <shirai@unixusers.net>
-# Jul 28, 2006
+# Aug 8, 2006
X #
X ############################################################
X
diff -urNP ../FD-2.08e/archive.c ./archive.c
--- ../FD-2.08e/archive.c Fri Jul 28 00:00:00 2006
+++ ./archive.c Tue Aug 8 00:00:00 2006
@@ -211,7 +211,9 @@
X {"*.tar.Z", "zcat %C|tar tvf -", PM_TAR, 0},
X {"*.tar.gz", "gzip -cd %C|tar tvf -", PM_TAR, 0},
X {"*.tar.bz2", "bzip2 -cd %C|tar tvf -", PM_TAR, 0},
+# ifndef CYGWIN
X {"*.taZ", "zcat %C|tar tvf -", PM_TAR, 0},
+# endif
X {"*.taz", "gzip -cd %C|tar tvf -", PM_TAR, 0},
X {"*.tgz", "gzip -cd %C|tar tvf -", PM_TAR, 0},
X #endif /* !MSDOS */
@@ -240,8 +242,10 @@
X "gzip -cd %C|tar xf - %TA", 0},
X {"*.tar.bz2", "tar cf - %T|bzip2 -c > %C",
X "bzip2 -cd %C|tar xf - %TA", 0},
+# ifndef CYGWIN
X {"*.taZ", "tar cf - %T|compress -c > %C",
X "zcat %C|tar xf - %TA", 0},
+# endif
X {"*.taz", "tar cf - %T|gzip -c > %C",
X "gzip -cd %C|tar xf - %TA", 0},
X {"*.tgz", "tar cf - %T|gzip -c > %C",
diff -urNP ../FD-2.08e/custom.c ./custom.c
--- ../FD-2.08e/custom.c Fri Jul 28 00:00:00 2006
+++ ./custom.c Tue Aug 8 00:00:00 2006
@@ -161,12 +161,11 @@
X #define noselect(n, m, x, s, v) \
X (selectstr(n, m, x, s, v) != K_CR)
X #define MAXSAVEMENU 5
-#define MAXTNAMLEN 8
X #define DEFPALETTE "8962435188"
X #define MAXPALETTE 10
X #define MAXCOLOR 10
-#ifndef O_BINARY
-#define O_BINARY 0
+#ifndef O_TEXT
+#define O_TEXT 0
X #endif
X
X typedef struct _envtable {
@@ -191,7 +190,7 @@
X
X #define env_str(n) (&(envlist[n].env[FDESIZ]))
X #define fdenv_str(n) (envlist[n].env)
-#define env_type(n) (envlist[n].type)
+#define env_type(n) (envlist[n].type & T_TYPE)
X #ifdef FORCEDSTDC
X #define def_str(n) (envlist[n].def.str)
X #define def_num(n) (envlist[n].def.num)
@@ -202,6 +201,8 @@
X #define DEFVAL(d) (char *)(d)
X #endif
X
+#define T_TYPE 0037
+#define T_PRIMAL 0040
X #define T_BOOL 0
X #define T_SHORT 1
X #define T_INT 2
@@ -415,12 +416,12 @@
X {"FD_PRECEDEPATH", &precedepath, DEFVAL(PRECEDEPATH), PCPT_E, T_PATHS},
X #endif
X #if FD >= 2
- {"FD_PS1", &promptstr, DEFVAL(PROMPT), PRMP_E, T_CHARP},
+ {"FD_PS1", &promptstr, DEFVAL(PROMPT), PRMP_E, T_CHARP | T_PRIMAL},
X #else
X {"FD_PROMPT", &promptstr, DEFVAL(PROMPT), PRMP_E, T_CHARP},
X #endif
X #ifndef _NOORIGSHELL
- {"FD_PS2", &promptstr2, DEFVAL(PROMPT2), PRM2_E, T_CHARP},
+ {"FD_PS2", &promptstr2, DEFVAL(PROMPT2), PRM2_E, T_CHARP | T_PRIMAL},
X {"FD_DUMBSHELL", &dumbshell, DEFVAL(DUMBSHELL), DMSHL_E, T_BOOL},
X #endif
X #ifndef _NOPTY
@@ -551,13 +552,13 @@
X
X VOID initenv(VOID_A)
X {
-#if !MSDOS
+#if !MSDOS && defined (FORCEDSTDC)
X char *cp;
X int w;
X #endif
X int i;
X
-#if !MSDOS
+#if !MSDOS && defined (FORCEDSTDC)
X if ((w = sizeof(char *) - sizeof(int)) > 0) {
X i = 0x5a;
X cp = (char *)(&i);
@@ -566,7 +567,7 @@
X #endif
X
X for (i = 0; i < ENVLISTSIZ; i++) {
-#if !MSDOS
+#if !MSDOS && defined (FORCEDSTDC)
X if (w > 0) switch (env_type(i)) {
X case T_CHARP:
X case T_PATH:
@@ -577,11 +578,11 @@
X case T_NOVAR:
X break;
X default:
- cp = (char *)(&(envlist[i].def.num));
+ cp = (char *)&def_num(i);
X memmove(cp, &(cp[w]), sizeof(int));
X break;
X }
-#endif /* !MSDOS */
+#endif /* !MSDOS && FORCEDSTDC */
X _evalenv(i);
X }
X }
@@ -683,7 +684,7 @@
X break;
X #endif
X case T_COLUMN:
- if ((n = atoi2(cp)) < 0 || n > 5 || n == 4)
+ if ((n = atoi2(cp)) <= 0 || n > 5 || n == 4)
X n = def_num(no);
X *((int *)(envlist[no].var)) = n;
X break;
@@ -2016,12 +2017,7 @@
X if (f) ident += FDESIZ;
X f = (1 << f);
X
- if (flaglist && (flaglist[i] & f)) {
- trash = (char **)realloc2(trash,
- (nt + 1) * sizeof(char *));
- trash[nt++] = argv[n];
- }
- else {
+ if (!flaglist || !(flaglist[i] & f)) {
X if (flaglist) flaglist[i] |= f;
X if ((cp = getshellvar(ident, -1))
X && (env_type(i) != T_CHARP
@@ -2030,13 +2026,18 @@
X cp = killmeta(cp);
X fprintf2(fp, "%s=%s", ident, cp);
X free(cp);
+ continue;
X }
- else {
+ else if (!(envlist[i].type & T_PRIMAL)) {
X unset = (char **)realloc2(unset,
X (nu + 1) * sizeof(char *));
X unset[nu++] = ident;
+ continue;
X }
X }
+
+ trash = (char **)realloc2(trash, (nt + 1) * sizeof(char *));
+ trash[nt++] = argv[n];
X }
X if (ns) fputnl(fp);
X
@@ -2081,12 +2082,7 @@
X if (f) ident += FDESIZ;
X f = (1 << f);
X
- if (flaglist && (flaglist[i] & f)) {
- trash = (char **)realloc2(trash,
- (nt + 1) * sizeof(char *));
- trash[nt++] = ident;
- }
- else {
+ if (!flaglist || !(flaglist[i] & f)) {
X if (flaglist) flaglist[i] |= f;
X if ((cp = getshellvar(ident, -1))
X && (env_type(i) != T_CHARP
@@ -2095,13 +2091,18 @@
X cp = killmeta(cp);
X fprintf2(fp, "%s=%s", ident, cp);
X free(cp);
+ continue;
X }
- else {
+ else if (!(envlist[i].type & T_PRIMAL)) {
X unset = (char **)realloc2(unset,
X (nu + 1) * sizeof(char *));
X unset[nu++] = ident;
+ continue;
X }
X }
+
+ trash = (char **)realloc2(trash, (nt + 1) * sizeof(char *));
+ trash[nt++] = ident;
X }
X if (ns) fputnl(fp);
X
@@ -3408,7 +3409,7 @@
X
X printarchcomm(archivelist, i, 1, fp);
X }
- for (i = 0; i < origmaxlaunch; i++) {
+ for (i = 0; i < origmaxarchive; i++) {
X if (origflaglist[i]) continue;
X
X printarchcomm(origarchivelist, i, 0, fp);
@@ -3859,42 +3860,48 @@
X char *file;
X {
X syntaxtree *trp, *stree;
+ lockbuf_t *lck;
X FILE *fpin, *fpout;
X char *cp, *buf, **argv, **subst, path[MAXPATHLEN];
X char *flaglist[MAXCUSTOM - 1], *origflaglist[MAXCUSTOM - 1];
X int i, n, len, *slen, fd, argc, max[MAXCUSTOM], origmax[MAXCUSTOM - 1];
X
- if (!(fpin = Xfopen(file, "r")) && errno != ENOENT) {
+ if (!(lck = lockfopen(file, "r", O_TEXT | O_RDWR))) {
X warning(-1, file);
X return(-1);
X }
X
X strcpy(path, file);
- cp = getbasename(path);
- len = strsize(path) - (cp - path);
- if (len > MAXTNAMLEN) len = MAXTNAMLEN;
- genrandname(NULL, 0);
-
- for (;;) {
- genrandname(cp, len);
- fd = Xopen(path, O_BINARY | O_WRONLY | O_CREAT | O_EXCL, 0666);
- if (fd >= 0) break;
- if (errno != EEXIST) {
- warning(-1, path);
- if (fpin) Xfclose(fpin);
- return(-1);
+ if ((fpin = lck -> fp)) fd = opentmpfile(path, 0666);
+ else {
+ lockclose(lck);
+ lck = lockopen(path,
+ O_TEXT | O_WRONLY | O_CREAT | O_EXCL, 0666);
+ fd = (lck) ? lck -> fd : -1;
+ }
+ fpout = (fd >= 0) ? Xfdopen(fd, "w") : NULL;
+
+ if (fpout) {
+ if (!fpin) {
+ lck -> fp = fpout;
+ lck -> flags |= LCK_STREAM;
X }
X }
- if (fd < 0) {
- warning(EEXIST, path);
- if (fpin) Xfclose(fpin);
- return(-1);
- }
- if (!(fpout = Xfdopen(fd, "w"))) {
+ else {
X warning(-1, path);
- VOID_C Xclose(fd);
- Xunlink(path);
- if (fpin) Xfclose(fpin);
+# if MSDOS || defined (CYGWIN)
+ lockclose(lck);
+ if (fd >= 0) {
+ if (fpin) VOID_C Xclose(fd);
+ Xunlink(path);
+ }
+# else
+ if (fd >= 0) {
+ Xunlink(path);
+ if (fpin) VOID_C Xclose(fd);
+ }
+ lockclose(lck);
+# endif
X return(-1);
X }
X
@@ -4018,7 +4025,6 @@
X
X if (!fpin) fputs("# configurations by customizer\n", fpout);
X else {
- Xfclose(fpin);
X n = 0;
X if (val[0] && flaglist[0])
X n = dumpenv(flaglist[0], NULL);
@@ -4062,26 +4068,48 @@
X if (val[5] && flaglist[5])
X dumpdosdrive(flaglist[5], origflaglist[5], fpout);
X # endif
- Xfclose(fpout);
X for (i = 0; i < MAXCUSTOM - 1; i++) {
X if (flaglist[i]) free(flaglist[i]);
X if (origflaglist[i]) free(origflaglist[i]);
X }
X
- if (Xrename(path, file) < 0) {
+ if (!fpin) {
+ lockclose(lck);
+ n = 0;
+ }
+ else {
+# if !MSDOS && !defined (CYGWIN)
+ n = Xrename(path, file);
+ lockclose(lck);
+ Xfclose(fpout);
+# else /* MSDOS || CYGWIN */
+ lockclose(lck);
+ Xfclose(fpout);
+# if MSDOS
+ n = Xrename(path, file);
+# else
+ while ((n = Xrename(path, file)) < 0) {
+ if (errno != EACCES) break;
+ usleep(100000L);
+ }
+# endif
+# endif /* MSDOS || CYGWIN */
+ }
+
+ if (n < 0) {
X warning(-1, file);
X Xunlink(path);
X return(-1);
X }
X
- return(1);
+ return(0);
X }
X # endif /* !_NOORIGSHELL */
X
X static int NEAR editsave(no)
X int no;
X {
- FILE *fp;
+ lockbuf_t *lck;
X char *file, *str[MAXCUSTOM - 1];
X int i, n, done, val[MAXCUSTOM - 1];
X
@@ -4173,7 +4201,7 @@
X done = 1;
X file = evalpath(file, 0);
X # ifdef FAKEUNINIT
- fp = NULL; /* fake for -Wuninitialized */
+ lck = NULL; /* fake for -Wuninitialized */
X # endif
X if (!*file
X || (Xaccess(file, F_OK) >= 0 && yesno(FSVOK_K)))
@@ -4182,28 +4210,34 @@
X envcaption(SSAVE_K);
X if (noselect(NULL, MAXCUSTOM - 1, 0, str, val))
X done = 0;
- else if (!(fp = Xfopen(file, "w"))) {
- warning(-1, file);
- done = 0;
+ else {
+ lck = lockfopen(file, "w",
+ O_TEXT | O_WRONLY
+ | O_CREAT | O_TRUNC);
+ if (!lck || !(lck -> fp)) {
+ warning(-1, file);
+ lockclose(lck);
+ done = 0;
+ }
X }
X }
X free(file);
X
X if (!done) break;
- fputs("# configurations by customizer\n", fp);
- if (val[0]) dumpenv(NULL, fp);
- if (val[1]) dumpbind(NULL, NULL, fp);
+ fputs("# configurations by customizer\n", lck -> fp);
+ if (val[0]) dumpenv(NULL, lck -> fp);
+ if (val[1]) dumpbind(NULL, NULL, lck -> fp);
X # ifndef _NOKEYMAP
- if (val[2]) dumpkeymap(NULL, NULL, fp);
+ if (val[2]) dumpkeymap(NULL, NULL, lck -> fp);
X # endif
X # ifndef _NOARCHIVE
- if (val[3]) dumplaunch(NULL, NULL, fp);
- if (val[4]) dumparch(NULL, NULL, fp);
+ if (val[3]) dumplaunch(NULL, NULL, lck -> fp);
+ if (val[4]) dumparch(NULL, NULL, lck -> fp);
X # endif
X # ifdef _USEDOSEMU
- if (val[5]) dumpdosdrive(NULL, NULL, fp);
+ if (val[5]) dumpdosdrive(NULL, NULL, lck -> fp);
X # endif
- Xfclose(fp);
+ lockclose(lck);
X break;
X case 4:
X # ifndef _NOORIGSHELL
diff -urNP ../FD-2.08e/doscom.c ./doscom.c
--- ../FD-2.08e/doscom.c Fri Jul 28 00:00:00 2006
+++ ./doscom.c Tue Aug 8 00:00:00 2006
@@ -846,7 +846,9 @@
X else ret = (cp2) ? -1 : 0;
X break;
X case 'D':
- ret = sp1 -> mtim - sp2 -> mtim;
+ if (sp1 -> mtim == sp2 -> mtim) ret = 0;
+ else ret = (sp1 -> mtim > sp2 -> mtim)
+ ? 1 : -1;
X break;
X case 'G':
X ret = dir_isdir(sp2) - dir_isdir(sp1);
diff -urNP ../FD-2.08e/dosdisk.c ./dosdisk.c
--- ../FD-2.08e/dosdisk.c Fri Jul 28 00:00:00 2006
+++ ./dosdisk.c Tue Aug 8 00:00:00 2006
@@ -144,7 +144,7 @@
X #define KC_EUCJP 0010
X
X #define strsize(s) ((int)sizeof(s) - 1)
-#define arraysize(a) ((int)sizeof(a) / (int)sizeof(*(a)))
+#define arraysize(a) ((int)((u_int)sizeof(a) / (u_int)sizeof(*(a))))
X
X #define reterr(c) {errno = doserrno; return(c);}
X #define S_IEXEC_ALL (S_IEXEC | (S_IEXEC >> 3) | (S_IEXEC >> 6))
@@ -213,9 +213,12 @@
X static int NEAR openunitbl __P_((char *));
X static u_int NEAR unifysjis __P_((u_int, int));
X static u_int NEAR cnvunicode __P_((u_int, int));
+#define Xopen open
+#define Xclose(f) ((close(f)) ? -1 : 0)
+#define sureread read
X #define getword(s, n) (((u_short)((s)[(n) + 1]) << 8) | (s)[n])
-#define skread(f,o,s,n) (lseek(f, o, L_SET) >= (off_t)0 \
- && read(f, s, n) == n)
+#define skread(f,o,s,n) (Xlseek(f, o, L_SET) >= (off_t)0 \
+ && sureread(f, s, n) == n)
X #define SJ_UDEF 0x81ac /* GETA */
X #define U2_UDEF 0x3013 /* GETA */
X #define UNICODETBL "fd-unicd.tbl"
@@ -925,30 +928,27 @@
X static int NEAR openunitbl(file)
X char *file;
X {
- static int fd = -1;
+ static int fd = -2;
X u_char buf[2];
X char path[MAXPATHLEN];
X
X if (!file) {
- if (fd >= 0) close(fd);
- fd = -1;
+ if (fd >= 0) Xclose(fd);
+ fd = -2;
X return(0);
X }
X
- if (fd >= 0) return(fd);
+ if (fd >= -1) return(fd);
X
X if (!unitblpath || !*unitblpath) strcpy(path, file);
X else strcatdelim2(path, unitblpath, file);
X
- if ((fd = open(path, O_BINARY | O_RDONLY, 0600)) < 0) return(-1);
- if (!unitblent) {
- if (read(fd, buf, 2) != 2) {
- close(fd);
- fd = -1;
- return(-1);
- }
- unitblent = getword(buf, 0);
+ if ((fd = Xopen(path, O_BINARY | O_RDONLY, 0666)) < 0) fd = -1;
+ else if (!unitblent && sureread(fd, buf, 2) != 2) {
+ Xclose(fd);
+ fd = -1;
X }
+ else unitblent = getword(buf, 0);
X
X return(fd);
X }
@@ -1032,9 +1032,9 @@
X ofs = min = max = 0;
X if ((fd = openunitbl(UNICODETBL)) < 0) ofs = unitblent;
X else if (encode) {
- if (lseek(fd, (off_t)2, L_SET) < (off_t)0) ofs = unitblent;
+ if (Xlseek(fd, (off_t)2, L_SET) < (off_t)0) ofs = unitblent;
X else for (ofs = 0; ofs < unitblent; ofs++) {
- if (read(fd, cp, 4) != 4) {
+ if (sureread(fd, cp, 4) != 4) {
X ofs = unitblent;
X break;
X }
@@ -2185,7 +2185,7 @@
X }
X }
X # endif /* LINUX */
- if ((fd = open(devp -> ch_name, i, 0600)) < 0) {
+ if ((fd = open(devp -> ch_name, i, 0666)) < 0) {
X # ifdef EFORMAT
X if (errno == EFORMAT) {
X errno = duperrno;
@@ -2196,7 +2196,7 @@
X if ((errno != EROFS && errno != EACCES)
X || i == (O_BINARY | O_RDONLY)
X || (fd = open(devp -> ch_name,
- O_BINARY | O_RDONLY, 0600)) < 0) {
+ O_BINARY | O_RDONLY, 0666)) < 0) {
X doserrno = errno;
X errno = duperrno;
X return(-1);
@@ -2481,7 +2481,7 @@
X l_off_t *slice;
X int fd, head, sect, size;
X
- if ((fd = open(devfile, O_BINARY | O_RDONLY, 0600)) < 0) {
+ if ((fd = open(devfile, O_BINARY | O_RDONLY, 0666)) < 0) {
X if (errno == EIO) errno = ENODEV;
X return(NULL);
X }
@@ -4454,7 +4454,7 @@
X static long NEAR dosfilbuf(fd, wrt)
X int fd, wrt;
X {
- long n, size, new, prev;
+ long size, new, prev;
X
X size = dosflist[fd]._bufsize;
X if (!wrt && (off_t)size > dosflist[fd]._size - dosflist[fd]._loc)
@@ -4485,8 +4485,7 @@
X }
X dosflist[fd]._off = new;
X dosflist[fd]._next = ENDCLUST;
- for (n = 0; n < dosflist[fd]._bufsize; n++)
- dosflist[fd]._base[n] = 0;
+ memset(dosflist[fd]._base, 0, dosflist[fd]._bufsize);
X }
X dosflist[fd]._cnt = size;
X dosflist[fd]._ptr = dosflist[fd]._base;
@@ -4636,10 +4635,42 @@
X dosflist[fd]._ptr += size;
X dosflist[fd]._cnt -= size;
X dosflist[fd]._loc += size;
+ if (dosflist[fd]._size < dosflist[fd]._loc)
+ dosflist[fd]._size = dosflist[fd]._loc;
X offset -= size;
X }
X
X return(dosflist[fd]._loc);
+}
+
+int dosftruncate(fd, size)
+int fd;
+off_t size;
+{
+ off_t offset;
+ int n;
+
+ fd -= DOSFDOFFSET;
+ if (fd < 0 || fd >= maxdosf) {
+ errno = EBADF;
+ return(-1);
+ }
+ if ((dosflist[fd]._flag & O_ACCMODE) == O_RDONLY) {
+ errno = EINVAL;
+ return(-1);
+ }
+
+ n = 0;
+ offset = dosflist[fd]._loc;
+ if (doslseek(fd + DOSFDOFFSET, size, L_SET) < (off_t)0) n = -1;
+ else if (dosflist[fd]._next != ENDCLUST) {
+ clustfree(fd2devp(fd), dosflist[fd]._next);
+ dosflist[fd]._next = ENDCLUST;
+ }
+ dosflist[fd]._size = size;
+ doslseek(fd + DOSFDOFFSET, offset, L_SET);
+
+ return(n);
X }
X
X int dosmkdir(path, mode)
diff -urNP ../FD-2.08e/dosdisk.h ./dosdisk.h
--- ../FD-2.08e/dosdisk.h Fri Jul 28 00:00:00 2006
+++ ./dosdisk.h Tue Aug 8 00:00:00 2006
@@ -52,10 +52,6 @@
X #define d_fileno d_ino
X #endif
X
-#ifdef NODRECLEN
-#define d_reclen d_fd
-#endif
-
X #ifndef L_SET
X # ifdef SEEK_SET
X # define L_SET SEEK_SET
@@ -323,6 +319,12 @@
X typedef struct dirent st_dirent;
X #endif
X
+#ifdef NODRECLEN
+#define wrap_reclen(dp) (*(u_short *)(dp))
+#else
+#define wrap_reclen(dp) ((dp) -> d_reclen)
+#endif
+
X #ifdef CYGWIN
X /* Some versions of Cygwin have neither d_fileno nor d_ino */
X struct dosdirent {
@@ -387,6 +389,7 @@
X extern int dosread __P_((int, char *, int));
X extern int doswrite __P_((int, char *, int));
X extern off_t doslseek __P_((int, off_t, int));
+extern int dosftruncate __P_((int, off_t));
X extern int dosmkdir __P_((char *, int));
X extern int dosrmdir __P_((char *));
X extern int dosfileno __P_((FILE *));
diff -urNP ../FD-2.08e/dosemu.c ./dosemu.c
--- ../FD-2.08e/dosemu.c Fri Jul 28 00:00:00 2006
+++ ./dosemu.c Tue Aug 8 00:00:00 2006
@@ -9,6 +9,10 @@
X #include "termio.h"
X #include "func.h"
X
+#ifndef O_ACCMODE
+#define O_ACCMODE (O_RDONLY | O_WRONLY | O_RDWR)
+#endif
+
X #if !defined (_NODOSDRIVE) && defined (CODEEUC)
X extern int noconv;
X #endif
@@ -256,7 +260,7 @@
X /* Some versions of Cygwin have neither d_fileno nor d_ino */
X if (dos) {
X src = ((struct dosdirent *)dp) -> d_name;
- buf.d_reclen = ((struct dosdirent *)dp) -> d_reclen;
+ wrap_reclen(&buf) = ((struct dosdirent *)dp) -> d_reclen;
X }
X else
X #endif
@@ -723,6 +727,18 @@
X else ofs = lseek(fd, offset, whence);
X
X return(ofs);
+}
+
+int Xftruncate(fd, len)
+int fd;
+off_t len;
+{
+ int n;
+
+ if (fd >= DOSFDOFFSET) n = dosftruncate(fd, len);
+ else n = ftruncate(fd, len);
+
+ return(n);
X }
X
X int Xdup(oldd)
diff -urNP ../FD-2.08e/fd.cat ./fd.cat
--- ../FD-2.08e/fd.cat Fri Jul 28 00:00:00 2006
+++ ./fd.cat Tue Aug 8 00:00:00 2006
@@ -1917,7 +1917,7 @@
X ドライブ名として小文字を用いると、MS-Windows format floppy
X の Long File Name (LFN) が扱えるフロッピードライブとしてアク
X セスできます。この場合、UNIX 上の長いファイル名もそのままコ
- ピーすることができます。但し、UNICODE の変換テーブル
+ ピーすることができます。但し、UNICODE 変換テーブル
X f^Hfd^Hd-^H-u^Hun^Hni^Hic^Hcd^Hd.^H.t^Htb^Hbl^Hl が、起動された f^Hfd^Hd の存在するディレクトリにない
X 場合は、漢字のファイル名は LFN 形式では扱えません。逆に、大
X 文字のドライブ名を用いると、LFN を無視して 8+3 形式のファイ
@@ -3050,26 +3050,26 @@
X
X 関^H^H関連^H^H連フ^H^Hファ^H^Hァイ^H^Hイル^H^Hル
X /^H/e^Het^Htc^Hc/^H/f^Hfd^Hd2^H2r^Hrc^Hc
- システム共通の f^Hfd^Hd 初期設定ファイル。
- ~^H~/^H/.^H.f^Hfd^Hd2^H2r^Hrc^Hc 個人用の f^Hfd^Hd 初期設定ファイル。
- ~^H~/^H/.^H.f^Hfd^Hds^Hsh^Hhr^Hrc^Hc 個人用の f^Hfd^Hds^Hsh^Hh 初期設定ファイル。
+ システム共通の f^Hfd^Hd 初期設定ファイル
+ ~^H~/^H/.^H.f^Hfd^Hd2^H2r^Hrc^Hc 個人用の f^Hfd^Hd 初期設定ファイル
+ ~^H~/^H/.^H.f^Hfd^Hds^Hsh^Hhr^Hrc^Hc 個人用の f^Hfd^Hds^Hsh^Hh 初期設定ファイル
X ~^H~/^H/.^H.f^Hfd^Hd_h^Hhi^His^Hst^Hto^Hor^Hry^Hy
- コマンド履歴のセーブファイル既定値。
- /^H/b^Hbi^Hin^Hn/^H/s^Hsh^Hh 環境変数 S^HSH^HHE^HEL^HLL^HL が未定義だった場合のユーザシェル。
- /^H/b^Hbi^Hin^Hn/^H/r^Hrm^Hm 異常終了時に不要ファイルを消去するためのコマンド。
- /^H/t^Htm^Hmp^Hp/^H/f^Hfd^Hd*^H* アーカイブファイル伸長のための一時的ディレクトリ。
+ コマンド履歴のセーブファイル既定値
+ /^H/b^Hbi^Hin^Hn/^H/s^Hsh^Hh 環境変数 S^HSH^HHE^HEL^HLL^HL が未定義だった場合のユーザシェル
+ /^H/b^Hbi^Hin^Hn/^H/r^Hrm^Hm 異常終了時に不要ファイルを消去するためのコマンド
+ /^H/t^Htm^Hmp^Hp/^H/f^Hfd^Hd*^H* アーカイブファイル伸長のための一時的ディレクトリ
X f^Hfd^Hd-^H-u^Hun^Hni^Hic^Hcd^Hd.^H.t^Htb^Hbl^Hl
- フロッピードライブの UNICODE 変換テーブル。f^Hfd^Hd の起
- 動ディレクトリにインストールされる。
+ f^Hfd^Hd の起動ディレクトリにインストールされる UNICODE
+ 変換テーブル
X
- f^Hfd^Hd2^H2r^Hrc^Hc MS-DOS 版での共通 f^Hfd^Hd 初期設定ファイル。f^Hfd^Hd の起動デ
- ィレクトリに用意しておく。
+ f^Hfd^Hd2^H2r^Hrc^Hc f^Hfd^Hd の起動ディレクトリに用意しておく MS-DOS 版での
+ 共通 f^Hfd^Hd 初期設定ファイル
X $^H$H^HHO^HOM^HME^HE\^H\f^Hfd^Hd2^H2.^H.r^Hrc^Hc
- MS-DOS 版での個人用の f^Hfd^Hd 初期設定ファイル。
+ MS-DOS 版での個人用の f^Hfd^Hd 初期設定ファイル
X $^H$H^HHO^HOM^HME^HE\^H\f^Hfd^Hds^Hsh^Hh.^H.r^Hrc^Hc
- MS-DOS 版での個人用の f^Hfd^Hds^Hsh^Hh 初期設定ファイル。
+ MS-DOS 版での個人用の f^Hfd^Hds^Hsh^Hh 初期設定ファイル
X $^H$H^HHO^HOM^HME^HE\^H\f^Hfd^Hd.^H.h^Hhs^Hst^Ht
- MS-DOS 版でのコマンド履歴のセーブファイル既定値。
+ MS-DOS 版でのコマンド履歴のセーブファイル既定値
X
X 制^H^H制限^H^H限事^H^H事項^H^H項
X 登録できるキー割当ては 2^H25^H56^H6 個までです。このうち、ユーザ定義
diff -urNP ../FD-2.08e/fd.man ./fd.man
--- ../FD-2.08e/fd.man Fri Jul 28 00:00:00 2006
+++ ./fd.man Tue Aug 8 00:00:00 2006
@@ -2,9 +2,9 @@
X .\" Copyright (C) 1995-2006 Takashi SHIRAI
X .\" <shirai@unixusers.net>
X .\"
-.\" @(#)fd.1 2.08e 07/28/06
+.\" @(#)fd.1 2.08f 08/08/06
X .\" fd - File & Directory maintenance tool
-.TH FD 1 "July 28, 2006"
+.TH FD 1 "August 8, 2006"
X .de sh
X .br
X .PP
@@ -3202,7 +3202,7 @@
X MS-Windows format floppy の Long File Name (LFN) が扱える
X フロッピードライブとしてアクセスできます。
X この場合、UNIX 上の長いファイル名もそのままコピーすることができます。
-但し、UNICODE の変換テーブル
+但し、UNICODE 変換テーブル
X .B " fd\-unicd.tbl"
X が、起動された
X .B " fd"
@@ -4986,57 +4986,55 @@
X .B /etc/fd2rc
X システム共通の
X .B " fd"
-初期設定ファイル。
+初期設定ファイル
X .TP
X .B ~/.fd2rc
X 個人用の
X .B " fd"
-初期設定ファイル。
+初期設定ファイル
X .TP
X .B ~/.fdshrc
X 個人用の
X .B " fdsh"
-初期設定ファイル。
+初期設定ファイル
X .TP
X .B ~/.fd_history
-コマンド履歴のセーブファイル既定値。
+コマンド履歴のセーブファイル既定値
X .TP
X .B /bin/sh
X 環境変数
X .B " SHELL"
-が未定義だった場合のユーザシェル。
+が未定義だった場合のユーザシェル
X .TP
X .B /bin/rm
-異常終了時に不要ファイルを消去するためのコマンド。
+異常終了時に不要ファイルを消去するためのコマンド
X .TP
X .B /tmp/fd\(**
-アーカイブファイル伸長のための一時的ディレクトリ。
+アーカイブファイル伸長のための一時的ディレクトリ
X .TP
X .B fd\-unicd.tbl
-フロッピードライブの UNICODE 変換テーブル。
X .B fd
-の起動ディレクトリにインストールされる。
+の起動ディレクトリにインストールされる UNICODE 変換テーブル
X
X .TP
X .B fd2rc
-MS-DOS 版での共通
-.B " fd"
-初期設定ファイル。
X .B fd
-の起動ディレクトリに用意しておく。
+の起動ディレクトリに用意しておく MS-DOS 版での共通
+.B " fd"
+初期設定ファイル
X .TP
X .B $HOME\efd2.rc
X MS-DOS 版での個人用の
X .B " fd"
-初期設定ファイル。
+初期設定ファイル
X .TP
X .B $HOME\efdsh.rc
X MS-DOS 版での個人用の
X .B " fdsh"
-初期設定ファイル。
+初期設定ファイル
X .TP
X .B $HOME\efd.hst
-MS-DOS 版でのコマンド履歴のセーブファイル既定値。
+MS-DOS 版でのコマンド履歴のセーブファイル既定値
X .PD
X .SH 制限事項
X 登録できるキー割当ては
diff -urNP ../FD-2.08e/fd_e.cat ./fd_e.cat
--- ../FD-2.08e/fd_e.cat Fri Jul 28 00:00:00 2006
+++ ./fd_e.cat Tue Aug 8 00:00:00 2006
@@ -2102,13 +2102,13 @@
X access it as the floppy drive which can treat the Long File
X Name (LFN) for MS-Windows formatted floppy disk. In this
X case, you can copy a file with a long filename on UNIX as it
- is. But, when the UNICODE translation table f^Hfd^Hd-^H-u^Hun^Hni^Hic^Hcd^Hd.^H.t^Htb^Hbl^Hl is
- not exist in the same directory as the invoked f^Hfd^Hd exists,
- any Kanji filename cannot be treated as LFN representation.
- Reversely, when you use a uppercase letter as the drive
- name, LFN is ignored and 8+3 formed filename is treated.
- MS-DOS version inherits this specification by the case of a
- drive name.
+ is. But, when the UNICODE translation table f^Hfd^Hd-^H-u^Hun^Hni^Hic^Hcd^Hd.^H.t^Htb^Hbl^Hl
+ does not exist in the same directory as the invoked f^Hfd^Hd ex-
+ ists, any Kanji filename cannot be treated as LFN representa-
+ tion. Reversely, when you use a uppercase letter as the
+ drive name, LFN is ignored and 8+3 formed filename is treat-
+ ed. MS-DOS version inherits this specification by the case
+ of a drive name.
X
X S^HSt^Htr^Hri^Hin^Hng^Hg I^HIn^Hnp^Hpu^Hut^Ht
X When you input the string, such as the pathname, the follow-
@@ -3369,9 +3369,9 @@
X /^H/b^Hbi^Hin^Hn/^H/r^Hrm^Hm The command to remove temporary files when abort
X /^H/t^Htm^Hmp^Hp/^H/f^Hfd^Hd*^H* The temporary directory to unpack the archive file
X f^Hfd^Hd-^H-u^Hun^Hni^Hic^Hcd^Hd.^H.t^Htb^Hbl^Hl
- The UNICODE translation table for the floppy
- drive, which is installed in the same directory as
- the executable binary of f^Hfd^Hd
+ The UNICODE translation table, which is installed
+ in the same directory as the executable binary of
+ f^Hfd^Hd
X
X f^Hfd^Hd2^H2r^Hrc^Hc The systemwide initial configuration file for f^Hfd^Hd
X on MS-DOS version, which must be prepared in the
diff -urNP ../FD-2.08e/fd_e.man ./fd_e.man
--- ../FD-2.08e/fd_e.man Fri Jul 28 00:00:00 2006
+++ ./fd_e.man Tue Aug 8 00:00:00 2006
@@ -2,9 +2,9 @@
X .\" Copyright (C) 1995-2006 Takashi SHIRAI
X .\" <shirai@unixusers.net>
X .\"
-.\" @(#)fd.1 2.08e 07/28/06
+.\" @(#)fd.1 2.08f 08/08/06
X .\" fd - File & Directory maintenance tool
-.TH FD 1 "July 28, 2006"
+.TH FD 1 "August 8, 2006"
X .de sh
X .br
X .PP
@@ -3346,7 +3346,7 @@
X But,
X when the UNICODE translation table
X .B fd\-unicd.tbl
-is not exist in the same directory as the invoked
+does not exist in the same directory as the invoked
X .B fd
X exists,
X any Kanji filename cannot be treated as LFN representation.
@@ -5193,7 +5193,7 @@
X The temporary directory to unpack the archive file
X .TP
X .B fd\-unicd.tbl
-The UNICODE translation table for the floppy drive,
+The UNICODE translation table,
X which is installed in the same directory as the executable binary of
X .B fd
X
diff -urNP ../FD-2.08e/file.c ./file.c
--- ../FD-2.08e/file.c Fri Jul 28 00:00:00 2006
+++ ./file.c Tue Aug 8 00:00:00 2006
@@ -10,10 +10,6 @@
X #include "func.h"
X #include "kanji.h"
X
-#ifndef ENOSPC
-#define ENOSPC EACCES
-#endif
-
X #if MSDOS
X #include <process.h>
X extern int getcurdrv __P_((VOID_A));
@@ -42,9 +38,7 @@
X #endif
X
X #define MAXTMPNAMLEN 8
-#ifndef O_BINARY
-#define O_BINARY 0
-#endif
+#define LOCKEXT "LCK"
X #ifdef _NODOSDRIVE
X #define DOSDIRENT 32
X #define LFNENTSIZ 13
@@ -53,6 +47,15 @@
X #define DOSBODYLEN 8
X #define DOSEXTLEN 3
X
+#ifndef O_BINARY
+#define O_BINARY 0
+#endif
+#ifndef O_ACCMODE
+#define O_ACCMODE (O_RDONLY | O_WRONLY | O_RDWR)
+#endif
+#ifndef ENOSPC
+#define ENOSPC EACCES
+#endif
X #ifndef L_SET
X # ifdef SEEK_SET
X # define L_SET SEEK_SET
@@ -61,6 +64,10 @@
X # endif
X #endif /* !L_SET */
X
+#ifndef NOFLOCK
+static int NEAR fcntllock __P_((int, int));
+#endif
+static char *NEAR excllock __P_((char *, int));
X #ifdef _NODOSDRIVE
X #define nodoschdir Xchdir
X #define nodosgetwd Xgetwd
@@ -275,22 +282,22 @@
X CONST VOID_P vp1;
X CONST VOID_P vp2;
X {
+ treelist *tp1, *tp2;
X char *cp1, *cp2;
X int tmp;
X
- if (!(((treelist *)vp1) -> name)) return(1);
- if (!(((treelist *)vp2) -> name)) return(-1);
+ tp1 = (treelist *)vp1;
+ tp2 = (treelist *)vp2;
+ if (!(tp1 -> name)) return(1);
+ if (!(tp2 -> name)) return(-1);
X switch (sorton & 7) {
X case 1:
- tmp = strpathcmp2(((treelist *)vp1) -> name,
- ((treelist *)vp2) -> name);
+ tmp = strpathcmp2(tp1 -> name, tp2 -> name);
X break;
X case 2:
- if ((cp1 = strrchr(((treelist *)vp1) -> name, '.')))
- cp1++;
+ if ((cp1 = strrchr(tp1 -> name, '.'))) cp1++;
X else cp1 = nullstr;
- if ((cp2 = strrchr(((treelist *)vp2) -> name, '.')))
- cp2++;
+ if ((cp2 = strrchr(tp2 -> name, '.'))) cp2++;
X else cp2 = nullstr;
X tmp = strpathcmp2(cp1, cp2);
X break;
@@ -304,7 +311,7 @@
X
X return(tmp);
X }
-#endif
+#endif /* !_NOTREE */
X
X /*ARGSUSED*/
X struct dirent *searchdir(dirp, regexp, arcregstr)
@@ -420,7 +427,7 @@
X }
X
X #ifndef NOFLOCK
-int lockfile(fd, mode)
+static int NEAR fcntllock(fd, mode)
X int fd, mode;
X {
X static int lockmode[] = {
@@ -457,6 +464,173 @@
X }
X #endif /* !NOFLOCK */
X
+static char *NEAR excllock(file, mode)
+char *file;
+int mode;
+{
+#if MSDOS
+ char *ext;
+#endif
+ static char **locklist = NULL;
+ char *cp, path[MAXPATHLEN];
+ int i, fd;
+
+ if (!file) {
+ if (locklist) {
+ for (i = 0; locklist[i]; i++) {
+ Xunlink(locklist[i]);
+ free(locklist[i]);
+ }
+ free(locklist);
+ }
+ return(NULL);
+ }
+
+ if (mode == LCK_UNLOCK) {
+ VOID_C Xunlink(file);
+ if (locklist) {
+ for (i = 0; locklist[i]; i++)
+ if (file == locklist[i]) break;
+ if (locklist[i]) {
+ for (; locklist[i + 1]; i++)
+ locklist[i] = locklist[i + 1];
+ locklist[i] = NULL;
+ }
+ if (!i) {
+ free(locklist);
+ locklist = NULL;
+ }
+ }
+ free(file);
+ return(NULL);
+ }
+
+#if MSDOS
+ cp = getbasename(file);
+ for (i = 0; cp[i]; i++) if (cp[i] == '.') break;
+ ext = &(cp[i]);
+ if (i > DOSBODYLEN - strsize(LOCKEXT))
+ i = DOSBODYLEN - strsize(LOCKEXT);
+ i += cp - file;
+ snprintf2(path, sizeof(path), "%-.*s%s%s", i, file, LOCKEXT, ext);
+#else
+ snprintf2(path, sizeof(path), "%s.%s", file, LOCKEXT);
+#endif
+ for (;;) {
+ fd = Xopen(path, O_BINARY | O_WRONLY | O_CREAT | O_EXCL,
+ 0666 & ~tmpumask);
+ if (fd >= 0) break;
+ if (errno != EEXIST) return(NULL);
+#if !MSDOS || defined (DJGPP)
+ usleep(100000L);
+#endif
+ }
+
+ Xclose(fd);
+ cp = strdup2(path);
+ i = countvar(locklist);
+ locklist = (char **)realloc2(locklist, (i + 2) * sizeof(char *));
+ locklist[i] = cp;
+ locklist[++i] = NULL;
+
+ return(cp);
+}
+
+lockbuf_t *lockopen(path, flags, mode)
+char *path;
+int flags, mode;
+{
+ char *lckname;
+ lockbuf_t *lck;
+ int fd, lckflags, lckmode, duperrno;
+
+ lckname = NULL;
+ lckflags = 0;
+ lckmode = ((flags & O_ACCMODE) == O_RDONLY) ? LCK_READ : LCK_WRITE;
+
+ fd = -1;
+#ifndef NOFLOCK
+ if (isnfs(path) <= 0) {
+ lckflags |= LCK_FLOCK;
+ fd = newdup(Xopen(path, flags & ~O_TRUNC, mode));
+ if (fd < 0) {
+ if ((flags & O_ACCMODE) == O_WRONLY || errno != ENOENT)
+ return(NULL);
+ }
+ else if (fcntllock(fd, lckmode) < 0) lckflags &= ~LCK_FLOCK;
+ else if ((flags & O_TRUNC) && Xftruncate(fd, (off_t)0) < 0) {
+ duperrno = errno;
+ VOID_C fcntllock(fd, LCK_UNLOCK);
+ Xclose(fd);
+ errno = duperrno;
+ return(NULL);
+ }
+ }
+#endif /* !NOFLOCK */
+
+ if (!(lckflags & LCK_FLOCK)) {
+ if (fd >= 0) Xclose(fd);
+ if ((lckname = excllock(path, lckmode))) /*EMPTY*/;
+ else if ((flags & O_ACCMODE) != O_RDONLY) return(NULL);
+
+ if ((fd = newdup(Xopen(path, flags, mode))) >= 0) /*EMPTY*/;
+ else if ((flags & O_ACCMODE) == O_WRONLY || errno != ENOENT) {
+ duperrno = errno;
+ VOID_C excllock(lckname, LCK_UNLOCK);
+ errno = duperrno;
+ return(NULL);
+ }
+ }
+
+ if (fd < 0) lckflags |= LCK_INVALID;
+ lck = (lockbuf_t *)malloc2(sizeof(lockbuf_t));
+ lck -> fd = fd;
+ lck -> fp = NULL;
+ lck -> name = lckname;
+ lck -> flags = lckflags;
+
+ return(lck);
+}
+
+lockbuf_t *lockfopen(path, type, flags)
+char *path, *type;
+int flags;
+{
+ lockbuf_t *lck;
+ FILE *fp;
+
+ if (!(lck = lockopen(path, flags, 0666))) return(NULL);
+
+ if (!(lck -> flags & LCK_INVALID)) {
+ if (!(fp = Xfdopen(lck -> fd, type))) {
+ lockclose(lck);
+ return(NULL);
+ }
+ lck -> fp = fp;
+ }
+ lck -> flags |= LCK_STREAM;
+
+ return(lck);
+}
+
+VOID lockclose(lck)
+lockbuf_t *lck;
+{
+ if (lck) {
+ if (lck -> name) VOID_C excllock(lck -> name, LCK_UNLOCK);
+ if (!(lck -> flags & LCK_INVALID)) {
+#ifndef NOFLOCK
+ if (lck -> flags & LCK_FLOCK)
+ VOID_C fcntllock(lck -> fd, LCK_UNLOCK);
+#endif
+ if (lck -> flags & LCK_STREAM) Xfclose(lck -> fp);
+ else Xclose(lck -> fd);
+ }
+
+ free(lck);
+ }
+}
+
X int touchfile(path, stp)
X char *path;
X struct stat *stp;
@@ -755,7 +929,7 @@
X VOID_C Xclose(fd1);
X
X if (i < 0) {
- Xunlink(dest);
+ VOID_C Xunlink(dest);
X errno = duperrno;
X return(-1);
X }
@@ -977,28 +1151,40 @@
X return(0);
X }
X
-int mktmpfile(file)
-char *file;
+int opentmpfile(path, mode)
+char *path;
+int mode;
X {
- char *cp, path[MAXPATHLEN];
- int fd, len, duperrno;
+ char *cp;
+ int fd, len;
X
- path[0] = '\0';
- if (mktmpdir(path) < 0) return(-1);
- cp = strcatdelim(path);
- len = strsize(path) - (cp - path);
+ cp = getbasename(path);
+ len = MAXPATHLEN - (cp - path) - 1;
X if (len > MAXTMPNAMLEN) len = MAXTMPNAMLEN;
X genrandname(NULL, 0);
X
X for (;;) {
X genrandname(cp, len);
- fd = Xopen(path, O_BINARY | O_WRONLY | O_CREAT | O_EXCL,
- 0666 & ~tmpumask);
- if (fd >= 0) {
- strcpy(file, path);
- return(fd);
- }
- if (errno != EEXIST) break;
+ fd = Xopen(path, O_BINARY | O_WRONLY | O_CREAT | O_EXCL, mode);
+ if (fd >= 0) break;
+ if (errno != EEXIST) return(-1);
+ }
+
+ return(fd);
+}
+
+int mktmpfile(file)
+char *file;
+{
+ char path[MAXPATHLEN];
+ int fd, duperrno;
+
+ path[0] = '\0';
+ if (mktmpdir(path) < 0) return(-1);
+ VOID_C strcatdelim(path);
+ if ((fd = opentmpfile(path, 0666 & ~tmpumask)) >= 0) {
+ strcpy(file, path);
+ return(fd);
X }
X duperrno = errno;
X rmtmpdir(NULL);
@@ -1079,6 +1265,8 @@
X extern char **environ;
X char buf[MAXPATHLEN];
X
+ VOID_C excllock(NULL, LCK_UNLOCK);
+
X if (!dir || !*dir || !file || !*file) return(0);
X strcatdelim2(buf, dir, file);
X
@@ -1313,7 +1501,8 @@
X }
X else {
X fd = Xopen(fname,
- O_CREAT | O_EXCL, 0600);
+ O_WRONLY | O_CREAT | O_EXCL,
+ 0600);
X if (fd >= 0) {
X VOID_C Xclose(fd);
X return(fname);
@@ -1522,12 +1711,12 @@
X else if (!strpathcmp(dp -> d_name, tmpdir)) {
X #if MSDOS
X if (!(dp -> d_alias[0])) len = DOSBODYLEN;
-#else
+#else /* !MSDOS */
X # ifndef _NODOSDRIVE
- if (dos == 3 && dp -> d_reclen == DOSDIRENT)
+ if (dos == 3 && wrap_reclen(dp) == DOSDIRENT)
X len = DOSBODYLEN;
X # endif
-#endif
+#endif /* !MSDOS */
X ent = i;
X }
X else {
diff -urNP ../FD-2.08e/func.h ./func.h
--- ../FD-2.08e/func.h Fri Jul 28 00:00:00 2006
+++ ./func.h Tue Aug 8 00:00:00 2006
@@ -184,11 +184,13 @@
X #define Xread read
X #define Xwrite write
X #define Xlseek lseek
+#define Xftruncate ftruncate
X #else
X extern int Xclose __P_((int));
X extern int Xread __P_((int, char *, int));
X extern int Xwrite __P_((int, char *, int));
X extern off_t Xlseek __P_((int, off_t, int));
+extern int Xftruncate __P_((int, off_t));
X #endif
X #ifdef _NODOSDRIVE
X #define Xdup safe_dup
@@ -384,9 +386,9 @@
X extern struct dirent *searchdir __P_((DIR *, reg_t *, char *));
X extern int underhome __P_((char *));
X extern int preparedir __P_((char *));
-#ifndef NOFLOCK
-extern int lockfile __P_((int, int));
-#endif
+extern lockbuf_t *lockopen __P_((char *, int, int));
+extern lockbuf_t *lockfopen __P_((char *, char *, int));
+extern VOID lockclose __P_((lockbuf_t *));
X extern int touchfile __P_((char *, struct stat *));
X #ifdef _NODOSDRIVE
X #define nodoslstat Xlstat
@@ -405,6 +407,7 @@
X extern char *genrandname __P_((char *, int));
X extern int mktmpdir __P_((char *));
X extern int rmtmpdir __P_((char *));
+extern int opentmpfile __P_((char *, int));
X extern int mktmpfile __P_((char *));
X extern int rmtmpfile __P_((char *));
X extern VOID removetmp __P_((char *, char *));
diff -urNP ../FD-2.08e/kanji.c ./kanji.c
--- ../FD-2.08e/kanji.c Fri Jul 28 00:00:00 2006
+++ ./kanji.c Tue Aug 8 00:00:00 2006
@@ -42,6 +42,7 @@
X #endif
X
X #ifdef FD
+#include "termio.h"
X #include "func.h"
X extern int norealpath;
X # ifndef _NOROCKRIDGE
@@ -53,6 +54,9 @@
X #else /* !FD */
X # ifdef _USEUNICODE
X extern char *malloc2 __P_((ALLOC_T));
+# define Xopen open
+# define Xclose(f) ((close(f)) ? -1 : 0)
+# define sureread read
X # endif
X #endif /* !FD */
X
@@ -130,8 +134,8 @@
X static int NEAR openunitbl __P_((char *));
X static u_char *NEAR newunitbl __P_((ALLOC_T));
X #define getword(s, n) (((u_short)((s)[(n) + 1]) << 8) | (s)[n])
-#define skread(f,o,s,n) (lseek(f, o, L_SET) >= (off_t)0 \
- && read(f, s, n) == n)
+#define skread(f,o,s,n) (Xlseek(f, o, L_SET) >= (off_t)0 \
+ && sureread(f, s, n) == n)
X #endif
X #ifndef _NOKANJICONV
X # ifdef _USEUNICODE
@@ -710,30 +714,27 @@
X static int NEAR openunitbl(file)
X char *file;
X {
- static int fd = -1;
+ static int fd = -2;
X u_char buf[2];
X char path[MAXPATHLEN];
X
X if (!file) {
- if (fd >= 0) close(fd);
- fd = -1;
+ if (fd >= 0) Xclose(fd);
+ fd = -2;
X return(0);
X }
X
- if (fd >= 0) return(fd);
+ if (fd >= -1) return(fd);
X
X if (!unitblpath || !*unitblpath) strcpy(path, file);
X else strcatdelim2(path, unitblpath, file);
X
- if ((fd = open(path, O_BINARY | O_RDONLY, 0600)) < 0) return(-1);
- if (!unitblent) {
- if (read(fd, buf, 2) != 2) {
- close(fd);
- fd = -1;
- return(-1);
- }
- unitblent = getword(buf, 0);
+ if ((fd = Xopen(path, O_BINARY | O_RDONLY, 0666)) < 0) fd = -1;
+ else if (!unitblent && sureread(fd, buf, 2) != 2) {
+ Xclose(fd);
+ fd = -1;
X }
+ else unitblent = getword(buf, 0);
X
X return(fd);
X }
@@ -794,7 +795,7 @@
X tblent = (u_int *)malloc2(nftblnum * sizeof(u_int));
X
X for (i = 0; i < nftblnum; i++) {
- if (read(fd, buf, 2) != 2) {
+ if (sureread(fd, buf, 2) != 2) {
X while (i > 0) free(tblbuf[--i]);
X free(tblbuf);
X free(tblent);
@@ -810,7 +811,7 @@
X free(tblent);
X return;
X }
- if (read(fd, tblbuf[i], size) != size) {
+ if (sureread(fd, tblbuf[i], size) != size) {
X while (i >= 0) free(tblbuf[i--]);
X free(tblbuf);
X free(tblent);
@@ -955,9 +956,9 @@
X }
X else if ((fd = openunitbl(UNICODETBL)) < 0) ofs = unitblent;
X else if (encode) {
- if (lseek(fd, (off_t)2, L_SET) < (off_t)0) ofs = unitblent;
+ if (Xlseek(fd, (off_t)2, L_SET) < (off_t)0) ofs = unitblent;
X else for (ofs = 0; ofs < unitblent; ofs++) {
- if (read(fd, cp, 4) != 4) {
+ if (sureread(fd, cp, 4) != 4) {
X ofs = unitblent;
X break;
X }
@@ -1362,7 +1363,7 @@
X n = 2 + nflen * 2;
X cp = new = (u_char *)malloc2(n);
X for (ofs = 0; ofs < ent; ofs++) {
- if (read(fd, cp, n) != n) {
+ if (sureread(fd, cp, n) != n) {
X ofs = ent;
X break;
X }
@@ -1416,7 +1417,7 @@
X }
X }
X else if ((fd = opennftbl(UNICODETBL, nf, &ent)) < 0
- || (top = lseek(fd, (off_t)0, L_INCR)) < (off_t)0)
+ || (top = Xlseek(fd, (off_t)0, L_INCR)) < (off_t)0)
X /*EMPTY*/;
X else {
X n = 2 + nflen * 2;
diff -urNP ../FD-2.08e/libc.c ./libc.c
--- ../FD-2.08e/libc.c Fri Jul 28 00:00:00 2006
+++ ./libc.c Tue Aug 8 00:00:00 2006
@@ -266,7 +266,7 @@
X {
X int fd, duperrno;
X
- if ((fd = open(curpath, O_RDONLY, 0600)) < 0) {
+ if ((fd = open(curpath, O_RDONLY, 0666)) < 0) {
X # ifdef CYGWIN
X char upath[MAXPATHLEN], spath[MAXPATHLEN];
X char tmp[MAXPATHLEN];
diff -urNP ../FD-2.08e/log.c ./log.c
--- ../FD-2.08e/log.c Fri Jul 28 00:00:00 2006
+++ ./log.c Tue Aug 8 00:00:00 2006
@@ -30,7 +30,7 @@
X
X extern char *progname;
X
-static int NEAR openlogfile __P_((VOID_A));
+static lockbuf_t *NEAR openlogfile __P_((VOID_A));
X static VOID NEAR writelog __P_((int, int, char *, int));
X
X char *logfile = NULL;
@@ -49,19 +49,19 @@
X #endif
X
X
-static int NEAR openlogfile(VOID_A)
+static lockbuf_t *NEAR openlogfile(VOID_A)
X {
+ lockbuf_t *lck;
X struct stat st;
X char *cp, *top, path[MAXPATHLEN];
X ALLOC_T size;
- int fd;
X
X cp = logfname;
X if (logfname) {
- if (!*logfname) return(-1);
+ if (!*logfname) return(NULL);
X }
X else {
- if (!logfile || !*logfile) return(-1);
+ if (!logfile || !*logfile) return(NULL);
X
X logfname = nullstr;
X top = logfile;
@@ -70,9 +70,9 @@
X #endif
X if (*top == _SC_) cp = logfile;
X else {
- if (!(cp = gethomedir())) return(-1);
+ if (!(cp = gethomedir())) return(NULL);
X strcatdelim2(path, cp, top);
- if (!*path) return(-1);
+ if (!*path) return(NULL);
X cp = strdup2(path);
X }
X }
@@ -83,21 +83,14 @@
X if (rename(cp, path) < 0) unlink(cp);
X }
X
- fd = open(cp, O_TEXT | O_WRONLY | O_CREAT | O_APPEND, 0666);
- if (fd < 0) {
+ lck = lockopen(cp, O_TEXT | O_WRONLY | O_CREAT | O_APPEND, 0666);
+ if (!lck) {
X free(cp);
- return(-1);
+ return(NULL);
X }
X
-#ifndef NOFLOCK
- if (isnfs(cp) <= 0 && lockfile(fd, LCK_WRITE) < 0) {
- close(fd);
- return(-1);
- }
-#endif
-
X logfname = cp;
- return(fd);
+ return(lck);
X }
X
X VOID logclose(VOID_A)
@@ -116,11 +109,12 @@
X char *buf;
X int len;
X {
+ lockbuf_t *lck;
X struct tm *tm;
X char hbuf[MAXLOGLEN + 1];
X time_t t;
X u_char uc;
- int n, fd;
+ int n;
X
X #ifndef NOUID
X if (!getuid()) {
@@ -132,15 +126,7 @@
X n = loglevel;
X if (!n || n < lvl) return;
X
- if ((fd = openlogfile()) < 0) {
-#ifndef NOSYSLOG
- if (usesyslog) /*EMPTY*/;
- else
-#endif
- return;
- }
-
- if (fd >= 0) {
+ if ((lck = openlogfile())) {
X t = time(NULL);
X tm = localtime(&t);
X #ifdef NOUID
@@ -156,14 +142,11 @@
X tm -> tm_hour, tm -> tm_min, tm -> tm_sec,
X getuid(), progname, getpid());
X #endif
- VOID_C write(fd, hbuf, n);
- VOID_C write(fd, buf, len);
+ VOID_C write(lck -> fd, hbuf, n);
+ VOID_C write(lck -> fd, buf, len);
X uc = '\n';
- VOID_C write(fd, &uc, sizeof(uc));
-#ifndef NOFLOCK
- if (isnfs(logfname) <= 0) VOID_C lockfile(fd, LCK_UNLOCK);
-#endif
- VOID_C close(fd);
+ VOID_C write(lck -> fd, &uc, sizeof(uc));
+ lockclose(lck);
X }
X #ifndef NOSYSLOG
X if (usesyslog && syslogged >= 0) {
diff -urNP ../FD-2.08e/makefile.b98 ./makefile.b98
--- ../FD-2.08e/makefile.b98 Fri Jul 28 00:00:00 2006
+++ ./makefile.b98 Tue Aug 8 00:00:00 2006
@@ -4,7 +4,7 @@
X
X TITLE = FD-
X VERMAJ = 2
-VERSION = 2.08e
+VERSION = 2.08f
X PREFIX =
X CONFDIR =
X BUILD =
@@ -671,11 +671,10 @@
X builtin.obj: wait.h
X builtin.obj: termemu.h
X shell.obj: fd.h
-shell.obj: machine.h config.h
-shell.obj: types.h
-shell.obj: printf.h kctype.h
-shell.obj: pathname.h term.h
-shell.obj: func.h
+shell.obj: machine.h config.h types.h
+shell.obj: printf.h
+shell.obj: kctype.h
+shell.obj: pathname.h term.h func.h
X shell.obj: dosdisk.h kanji.h system.h termio.h
X shell.obj: wait.h
X shell.obj: termemu.h
diff -urNP ../FD-2.08e/makefile.bpc ./makefile.bpc
--- ../FD-2.08e/makefile.bpc Fri Jul 28 00:00:00 2006
+++ ./makefile.bpc Tue Aug 8 00:00:00 2006
@@ -4,7 +4,7 @@
X
X TITLE = FD-
X VERMAJ = 2
-VERSION = 2.08e
+VERSION = 2.08f
X PREFIX =
X CONFDIR =
X BUILD =
@@ -671,11 +671,10 @@
X builtin.obj: wait.h
X builtin.obj: termemu.h
X shell.obj: fd.h
-shell.obj: machine.h config.h
-shell.obj: types.h
-shell.obj: printf.h kctype.h
-shell.obj: pathname.h term.h
-shell.obj: func.h
+shell.obj: machine.h config.h types.h
+shell.obj: printf.h
+shell.obj: kctype.h
+shell.obj: pathname.h term.h func.h
X shell.obj: dosdisk.h kanji.h system.h termio.h
X shell.obj: wait.h
X shell.obj: termemu.h
diff -urNP ../FD-2.08e/makefile.d98 ./makefile.d98
--- ../FD-2.08e/makefile.d98 Fri Jul 28 00:00:00 2006
+++ ./makefile.d98 Tue Aug 8 00:00:00 2006
@@ -4,7 +4,7 @@
X
X TITLE = FD-
X VERMAJ = 2
-VERSION = 2.08e
+VERSION = 2.08f
X PREFIX =
X CONFDIR =
X BUILD =
@@ -671,11 +671,10 @@
X builtin.o: wait.h
X builtin.o: termemu.h
X shell.o: fd.h
-shell.o: machine.h config.h
-shell.o: types.h
-shell.o: printf.h kctype.h
-shell.o: pathname.h term.h
-shell.o: func.h
+shell.o: machine.h config.h types.h
+shell.o: printf.h
+shell.o: kctype.h
+shell.o: pathname.h term.h func.h
X shell.o: dosdisk.h kanji.h system.h termio.h
X shell.o: wait.h
X shell.o: termemu.h
diff -urNP ../FD-2.08e/makefile.dpc ./makefile.dpc
--- ../FD-2.08e/makefile.dpc Fri Jul 28 00:00:00 2006
+++ ./makefile.dpc Tue Aug 8 00:00:00 2006
@@ -4,7 +4,7 @@
X
X TITLE = FD-
X VERMAJ = 2
-VERSION = 2.08e
+VERSION = 2.08f
X PREFIX =
X CONFDIR =
X BUILD =
@@ -671,11 +671,10 @@
X builtin.o: wait.h
X builtin.o: termemu.h
X shell.o: fd.h
-shell.o: machine.h config.h
-shell.o: types.h
-shell.o: printf.h kctype.h
-shell.o: pathname.h term.h
-shell.o: func.h
+shell.o: machine.h config.h types.h
+shell.o: printf.h
+shell.o: kctype.h
+shell.o: pathname.h term.h func.h
X shell.o: dosdisk.h kanji.h system.h termio.h
X shell.o: wait.h
X shell.o: termemu.h
diff -urNP ../FD-2.08e/makefile.g98 ./makefile.g98
--- ../FD-2.08e/makefile.g98 Fri Jul 28 00:00:00 2006
+++ ./makefile.g98 Tue Aug 8 00:00:00 2006
@@ -4,7 +4,7 @@
X
X TITLE = FD-
X VERMAJ = 2
-VERSION = 2.08e
+VERSION = 2.08f
X PREFIX =
X CONFDIR =
X BUILD =
@@ -671,11 +671,10 @@
X builtin.o: wait.h
X builtin.o: termemu.h
X shell.o: fd.h
-shell.o: machine.h config.h
-shell.o: types.h
-shell.o: printf.h kctype.h
-shell.o: pathname.h term.h
-shell.o: func.h
+shell.o: machine.h config.h types.h
+shell.o: printf.h
+shell.o: kctype.h
+shell.o: pathname.h term.h func.h
X shell.o: dosdisk.h kanji.h system.h termio.h
X shell.o: wait.h
X shell.o: termemu.h
diff -urNP ../FD-2.08e/makefile.gpc ./makefile.gpc
--- ../FD-2.08e/makefile.gpc Fri Jul 28 00:00:00 2006
+++ ./makefile.gpc Tue Aug 8 00:00:00 2006
@@ -4,7 +4,7 @@
X
X TITLE = FD-
X VERMAJ = 2
-VERSION = 2.08e
+VERSION = 2.08f
X PREFIX =
X CONFDIR =
X BUILD =
@@ -671,11 +671,10 @@
X builtin.o: wait.h
X builtin.o: termemu.h
X shell.o: fd.h
-shell.o: machine.h config.h
-shell.o: types.h
-shell.o: printf.h kctype.h
-shell.o: pathname.h term.h
-shell.o: func.h
+shell.o: machine.h config.h types.h
+shell.o: printf.h
+shell.o: kctype.h
+shell.o: pathname.h term.h func.h
X shell.o: dosdisk.h kanji.h system.h termio.h
X shell.o: wait.h
X shell.o: termemu.h
diff -urNP ../FD-2.08e/makefile.l98 ./makefile.l98
--- ../FD-2.08e/makefile.l98 Fri Jul 28 00:00:00 2006
+++ ./makefile.l98 Tue Aug 8 00:00:00 2006
@@ -4,7 +4,7 @@
X
X TITLE = FD-
X VERMAJ = 2
-VERSION = 2.08e
+VERSION = 2.08f
X PREFIX =
X CONFDIR =
X BUILD =
@@ -671,11 +671,10 @@
X builtin.obj: wait.h
X builtin.obj: termemu.h
SHAR_EOF
: || $echo 'restore of' 'FD-2.08f.patch' 'failed'
fi
$echo 'End of' 'FD-2.08f.patch' 'part' '1'
$echo 'File' 'FD-2.08f.patch' 'is continued in part' '2'
echo 2 > _sh01590/seq
exit 0
--
しらい たかし
Fnews-brouse 1.9(20180406) -- by Mizuno, MWE <mwe@ccsf.jp>
GnuPG Key ID = ECC8A735
GnuPG Key fingerprint = 9BE6 B9E9 55A5 A499 CD51 946E 9BDC 7870 ECC8 A735