Skip to content

Commit f99490d

Browse files
committed
refactor: do not close file when delete
1 parent f27ae25 commit f99490d

File tree

4 files changed

+7
-67
lines changed

4 files changed

+7
-67
lines changed

src/doscall.c

Lines changed: 6 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,10 +1129,6 @@ static Long Dskfre(short drv, Long buf) {
11291129

11301130
#ifndef _WIN32
11311131
static char *to_slash(size_t size, char *buf, const char *path) {
1132-
// 成功時にFILEINFO::nameにコピーするのでここでチェック
1133-
FILEINFO fi;
1134-
if (size > sizeof(fi.name)) return NULL;
1135-
11361132
if (strlen(path) >= size) return NULL;
11371133

11381134
char *p = strncpy(buf, path, size);
@@ -1221,7 +1217,6 @@ Long CreateNewFile(ULong file, UWord atr, bool newfile) {
12211217
finfo[ret].is_opened = true;
12221218
finfo[ret].mode = 2;
12231219
finfo[ret].nest = nest_cnt;
1224-
strcpy(finfo[ret].name, p);
12251220
return (ret);
12261221
}
12271222

@@ -1308,7 +1303,6 @@ static Long Open(char *p, short mode) {
13081303
finfo[ret].is_opened = true;
13091304
finfo[ret].mode = mode;
13101305
finfo[ret].nest = nest_cnt;
1311-
strcpy(finfo[ret].name, p);
13121306
return (ret);
13131307
}
13141308

@@ -1318,29 +1312,11 @@ static Long Open(char *p, short mode) {
13181312
*/
13191313
static Long Close(short hdl) {
13201314
if (hdl <= HUMAN68K_SYSTEM_FILENO_MAX) return DOSE_SUCCESS;
1321-
if (!finfo[hdl].is_opened) return -6; // オープンされていない
1322-
if (!CloseFile(&finfo[hdl])) return -14; // 無効なパラメータでコールした
1315+
if (!finfo[hdl].is_opened) return DOSE_BADF; // オープンされていない
1316+
if (!CloseFile(&finfo[hdl]))
1317+
return DOSE_ILGPARM; // 無効なパラメータでコールした
13231318

1324-
/* タイムスタンプ変更 */
1325-
#ifdef _WIN32
1326-
if (finfo[hdl].date != 0 || finfo[hdl].time != 0) {
1327-
FILETIME ft0, ft1, ft2;
1328-
int64_t datetime;
1329-
1330-
HANDLE handle = CreateFileA(finfo[hdl].name, GENERIC_WRITE, 0, NULL,
1331-
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
1332-
GetFileTime(handle, &ft0, &ft1, &ft2);
1333-
// 秒→100nsecに変換する。
1334-
datetime = ((int64_t)finfo[hdl].date * 86400L + finfo[hdl].time) * 10000000;
1335-
ft2.dwLowDateTime = (ULong)(datetime & 0xffffffff);
1336-
ft2.dwHighDateTime = (ULong)(datetime >> 32);
1337-
SetFileTime(handle, &ft0, &ft1, &ft2);
1338-
CloseHandle(handle);
1339-
finfo[hdl].date = 0;
1340-
finfo[hdl].time = 0;
1341-
}
1342-
#endif
1343-
return (0);
1319+
return 0;
13441320
}
13451321

13461322
/*
@@ -1493,43 +1469,8 @@ static Long Write_conv(short hdl, void *buf, size_t size) {
14931469
戻り値:ファイルハンドル(負ならエラーコード)
14941470
*/
14951471
static Long Delete(char *p) {
1496-
int err_save;
1497-
unsigned int len;
1498-
int hdl;
1499-
int i;
1500-
1501-
errno = 0;
1502-
if (remove(p) != 0) {
1503-
/* オープン中のファイルを調べる */
1504-
err_save = errno;
1505-
len = strlen(p);
1506-
hdl = 0;
1507-
for (i = 5; i < FILE_MAX; i++) {
1508-
if (!finfo[i].is_opened || nest_cnt != finfo[i].nest) continue;
1509-
if (len == strlen(finfo[i].name)) {
1510-
if (memcmp(p, finfo[i].name, len) == 0) {
1511-
hdl = i;
1512-
break;
1513-
}
1514-
}
1515-
}
1516-
if (len > 0 && hdl >= HUMAN68K_USER_FILENO_MIN) {
1517-
CloseFile(&finfo[hdl]);
1518-
errno = 0;
1519-
if (remove(p) != 0) {
1520-
if (errno == ENOENT)
1521-
return (-2); /* ファイルがない */
1522-
else
1523-
return (-13); /* ファイル名指定誤り */
1524-
}
1525-
} else {
1526-
if (err_save == ENOENT)
1527-
return (-2);
1528-
else
1529-
return (-13);
1530-
}
1531-
}
1532-
return (0);
1472+
if (remove(p) != 0) return (errno == ENOENT) ? DOSE_NOENT : DOSE_ILGFNAME;
1473+
return DOSE_SUCCESS;
15331474
}
15341475

15351476
/*

src/human68k.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ typedef struct {
4848
// DOSコールエラー番号
4949
#define DOSE_SUCCESS 0
5050
#define DOSE_ILGFNC -1
51+
#define DOSE_NOENT -2
5152
#define DOSE_NODIR -3
5253
#define DOSE_MFILE -4
5354
#define DOSE_BADF -6

src/run68.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,6 @@ static void init_fileinfo(int fileno, bool is_opened, short mode) {
270270
finfop->time = 0;
271271
finfop->mode = mode;
272272
finfop->nest = 0;
273-
finfop->name[0] = '\0';
274273
}
275274

276275
// ファイル管理テーブルの初期化

src/run68.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,6 @@ typedef struct {
163163
unsigned time;
164164
short mode;
165165
unsigned int nest;
166-
char name[89];
167166
} FILEINFO;
168167

169168
typedef struct {

0 commit comments

Comments
 (0)