Skip to content

Commit 8051709

Browse files
authored
Update fileio.c
1 parent 84359ec commit 8051709

File tree

1 file changed

+30
-12
lines changed

1 file changed

+30
-12
lines changed

libcob/fileio.c

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (C) 2002-2012, 2014-2024 Free Software Foundation, Inc.
2+
Copyright (C) 2002-2012, 2014-2025 Free Software Foundation, Inc.
33
Written by Keisuke Nishida, Roger While, Simon Sobisch, Ron Norman
44
55
This file is part of GnuCOBOL.
@@ -4393,19 +4393,37 @@ indexed_open (cob_file *f, char *filename,
43934393
}
43944394
isfd = isbuild ((void *)filename, (int)f->record_max, &fh->key[0],
43954395
vmode | ISINOUT | ISEXCLLOCK);
4396-
#if 0 /* activate on later merge of locking enhancements */
4397-
f->flag_file_lock = 1;
4398-
#endif
4399-
if (ISERRNO == EEXIST
4396+
4397+
if (isfd < 0) {
4398+
if (ISERRNO == EFLOCKED) {
4399+
return COB_STATUS_61_FILE_SHARING;
4400+
}
4401+
if ((ISERRNO == EEXIST || ISERRNO == EBADARG)
44004402
#if 1 /* CHECKME: guard added by Simon, needed ? */
4401-
&& omode == ISOUTPUT
4403+
&& omode == ISOUTPUT
44024404
#endif
4403-
&& isfd < 0) {
4404-
/* Erase file and redo the 'isbuild' */
4405-
iserase ((void *)filename);
4406-
isfd = isbuild ((void *)filename, (int)f->record_max, &fh->key[0],
4407-
vmode | ISINOUT | ISEXCLLOCK);
4408-
#if 0 /* activate on later merge of locking enhancements */
4405+
) {
4406+
/* Erase file and redo the 'isbuild' */
4407+
#if 0 /* TODO: activate on later merge of delete enhancements */
4408+
isam_file_delete (a, f, filename);
4409+
#else
4410+
iserase ((void *)filename);
4411+
#endif
4412+
#ifdef ISVARLEN
4413+
if (f->record_min != f->record_max) {
4414+
ISRECLEN = f->record_min;
4415+
}
4416+
#endif
4417+
ISERRNO = 0;
4418+
isfd = isbuild ((void *)filename, (int)f->record_max, &fh->key[0], vmode);
4419+
#if 0 /* TODO: activate on later merge of locking enhancements */
4420+
f->flag_file_lock = 1;
4421+
#endif
4422+
}
4423+
/* TODO: more checks in case isfd < 0,
4424+
allowing better io status than 30 */
4425+
#if 0 /* TODO: activate on later merge of locking enhancements */
4426+
} else {
44094427
f->flag_file_lock = 1;
44104428
#endif
44114429
}

0 commit comments

Comments
 (0)