24 #define _LFS64_LARGEFILE 1
25 #define _LFS64_STDIO 1
26 #define _FILE_OFFSET_BITS 64
27 #define _LARGEFILE64_SOURCE 1
29 #define _LARGE_FILES 1
31 #if defined(__hpux__) && !defined(__LP64__)
32 #define _APP32_64BIT_OFF_T 1
43 #include <sys/types.h>
56 #define WIN32_LEAN_AND_MEAN
61 #define fdcobsync _commit
63 #define fdcobsync fsync
65 #if !defined(__BORLANDC__) && !defined(__WATCOMC__)
66 #define getcwd _getcwd
72 #define unlink _unlink
73 #define fdopen _fdopen
74 #define lseek _lseeki64
76 #define off_t cob_s64_t
79 #define _O_TEMPORARY 0
83 #if defined(HAVE_FDATASYNC)
84 #define fdcobsync fdatasync
86 #define fdcobsync fsync
96 #define COB_LIB_EXPIMP
105 #elif defined(WITH_CISAM) || defined(WITH_DISAM) || defined(WITH_VBISAM)
107 #define WITH_ANY_ISAM
110 #define COB_WITH_STATUS_02
114 #define isfullclose(x) isclose (x)
119 #define isfullclose(x) isclose (x)
125 #undef COB_WITH_STATUS_02
149 struct keydesc key[1];
160 #ifdef WORDS_BIGENDIAN
161 #define COB_MAYSWAP_16(x) ((unsigned short)(x))
162 #define COB_MAYSWAP_32(x) ((unsigned int)(x))
164 #define COB_MAYSWAP_16(x) (COB_BSWAP_16((unsigned short)(x)))
165 #define COB_MAYSWAP_32(x) (COB_BSWAP_32((unsigned int)(x)))
171 #define COBSORTABORT 2
172 #define COBSORTFILEERR 3
173 #define COBSORTNOTOPEN 4
262 static const char *
const prefix[] = {
"DD_",
"dd_",
"" };
263 #define NUM_PREFIX sizeof(prefix) / sizeof(char *)
347 #if defined(WITH_INDEX_EXTFH) || defined(WITH_SEQRA_EXTFH)
352 extern void extfh_cob_exit_fileio (
void);
355 #ifdef WITH_INDEX_EXTFH
356 extern void extfh_indexed_unlock (
cob_file *);
357 extern int extfh_indexed_locate (
cob_file *,
char *);
358 extern int extfh_indexed_open (
cob_file *,
char *,
const int,
const int);
359 extern int extfh_indexed_close (
cob_file *,
const int);
362 extern int extfh_indexed_read_next (
cob_file *,
const int);
363 extern int extfh_indexed_write (
cob_file *,
const int);
364 extern int extfh_indexed_delete (
cob_file *);
365 extern int extfh_indexed_rewrite (
cob_file *,
const int);
368 #ifdef WITH_SEQRA_EXTFH
369 extern void extfh_seqra_unlock (
cob_file *);
370 extern int extfh_seqra_locate (
cob_file *,
char *);
371 extern int extfh_cob_file_open (
cob_file *,
char *,
const int,
const int);
372 extern int extfh_cob_file_close (
cob_file *,
const int);
373 extern int extfh_sequential_read (
cob_file *,
const int);
374 extern int extfh_sequential_write (
cob_file *,
const int);
375 extern int extfh_sequential_rewrite (
cob_file *,
const int);
378 extern int extfh_relative_read_next (
cob_file *,
const int);
379 extern int extfh_relative_write (
cob_file *,
const int);
380 extern int extfh_relative_rewrite (
cob_file *,
const int);
381 extern int extfh_relative_delete (
cob_file *);
386 static DB_ENV *bdb_env;
387 static char *bdb_buff;
388 static const char **bdb_data_dir;
389 static void *record_lock_object;
390 static size_t rlo_size;
391 static unsigned int bdb_lock_id;
393 #define DB_PUT(db,flags) db->put (db, NULL, &p->key, &p->data, flags)
394 #define DB_GET(db,flags) db->get (db, NULL, &p->key, &p->data, flags)
395 #define DB_SEQ(db,flags) db->c_get (db, &p->key, &p->data, flags)
396 #define DB_DEL(db,key,flags) db->del (db, NULL, key, flags)
397 #define DB_CLOSE(db) db->close (db, 0)
398 #define DB_SYNC(db) db->sync (db, 0)
399 #define cob_dbtsize_t u_int32_t
401 #define DBT_SET(key,fld) \
402 key.data = fld->data; \
403 key.size = (cob_dbtsize_t) fld->size
405 struct indexed_file {
409 unsigned char *last_key;
410 unsigned char *temp_key;
411 unsigned char **last_readkey;
412 unsigned int *last_dupno;
413 int *rewrite_sec_key;
416 DB_LOCK bdb_file_lock;
417 DB_LOCK bdb_record_lock;
419 unsigned int bdb_lock_id;
420 int write_cursor_open;
478 for (i = 0; i < strlen (s); ++i) {
479 if (!isalnum ((
int)s[i])) {
520 if (*p ==
'/' || *p ==
'\\') {
529 if (
likely(dollar == 0)) {
543 (
size_t)COB_FILE_MAX);
571 if (*src ==
'/' || *src ==
'\\') {
575 p = strtok (orig,
"/\\");
580 }
else if (!dollar) {
588 p = strtok (orig,
"/\\");
615 struct indexed_file *p;
617 #elif defined(WITH_ANY_ISAM)
618 struct indexfile *fh;
625 for (i = 0; i < f->
nkeys; ++i) {
631 #elif defined(WITH_ANY_ISAM)
642 fflush ((FILE *)f->
file);
656 for (l = file_cache; l; l = l->
next) {
671 if (
likely(status == 0)) {
674 memset (fnstatus->
data,
'0', (
size_t)2);
747 fp = (FILE *)f->
file;
758 for (i = 0; i < lingptr->
lin_bot; ++i) {
764 for (i = 0; i < lingptr->
lin_top; ++i) {
789 for (i = 0; i < lingptr->
lin_bot; ++i) {
796 for (i = 0; i < lingptr->
lin_top; ++i) {
800 for (i = (opt & COB_WRITE_MASK) - 1; i > 0; --i) {
817 if (write (f->
fd,
"\r", (
size_t)1) != 1) {
821 for (i = opt & COB_WRITE_MASK; i > 0; --i) {
822 if (write (f->
fd,
"\n", (
size_t)1) != 1) {
828 if (write (f->
fd,
"\f", (
size_t)1) != 1) {
847 putc (0x0d, (FILE *)f->
file);
850 putc (
'\n', (FILE *)f->
file);
854 putc (
'\f', (FILE *)f->
file);
865 unsigned int nonexistent;
880 if (access (filename,
F_OK) && errno == ENOENT) {
896 fdmode |= O_CREAT | O_TRUNC;
903 fperms = _S_IREAD | _S_IWRITE ;
910 fdmode |= O_CREAT | O_RDWR;
912 fperms = _S_IREAD | _S_IWRITE ;
921 fdmode |= O_CREAT | O_RDWR | O_APPEND;
923 fperms = _S_IREAD | _S_IWRITE ;
931 fd = open (filename, fdmode, fperms);
936 lseek (fd, (off_t) 0, SEEK_END);
965 if (memcmp (filename,
"/dev/", (
size_t)5)) {
966 memset ((
void *)&lock, 0,
sizeof (
struct flock));
968 lock.l_type = F_WRLCK;
970 lock.l_type = F_RDLCK;
972 lock.l_whence = SEEK_SET;
976 if (fcntl (fd, F_SETLK, &lock) < 0) {
1003 #ifdef WITH_SEQRA_EXTFH
1006 ret = extfh_seqra_locate (f, filename);
1010 if (access (filename,
F_OK) && errno == ENOENT) {
1021 ret = extfh_cob_file_open (f, filename, mode, sharing);
1047 unsigned int nonexistent;
1057 if (access (filename,
F_OK) && errno == ENOENT) {
1103 fp = fopen (filename, fmode);
1147 f->
fd = fileno (fp);
1151 if (memcmp (filename,
"/dev/", (
size_t)5)) {
1152 memset ((
void *)&lock, 0,
sizeof (
struct flock));
1154 lock.l_type = F_WRLCK;
1156 lock.l_type = F_RDLCK;
1158 lock.l_whence = SEEK_SET;
1161 if (fcntl (fileno (fp), F_SETLK, &lock) < 0) {
1186 #ifdef WITH_SEQRA_EXTFH
1187 return extfh_cob_file_close (f, opt);
1202 putc (
'\n', (FILE *)f->
file);
1207 if (write (f->
fd,
"\n", (
size_t)1) != 1) {
1213 memset ((
void *)&lock, 0,
sizeof (
struct flock));
1214 lock.l_type = F_UNLCK;
1215 lock.l_whence = SEEK_SET;
1219 fcntl (f->
fd, F_SETLK, &lock);
1225 fclose ((FILE *)f->
file);
1253 unsigned char sbuff[4];
1254 unsigned short sshort[2];
1258 #ifdef WITH_SEQRA_EXTFH
1261 extfh_ret = extfh_sequential_read (f, read_opts);
1271 lseek (f->
fd, (off_t)0, SEEK_CUR);
1279 if (bytesread == 0) {
1301 if (bytesread == 0) {
1303 }
else if (bytesread < 0) {
1316 unsigned char sbuff[4];
1317 unsigned short sshort[2];
1321 #ifdef WITH_SEQRA_EXTFH
1324 extfh_ret = extfh_sequential_write (f, opt);
1332 lseek (f->
fd, (off_t)0, SEEK_CUR);
1385 #ifdef WITH_SEQRA_EXTFH
1388 extfh_ret = extfh_sequential_rewrite (f, opt);
1396 if (lseek (f->
fd, -(off_t) f->
record->
size, SEEK_CUR) == (off_t)-1) {
1410 unsigned char *dataptr;
1414 #ifdef WITH_SEQRA_EXTFH
1417 extfh_ret = extfh_sequential_read (f, read_opts);
1427 n = getc ((FILE *)f->
file);
1436 n = getc ((FILE *)f->
file);
1448 if (
likely(i < f->record_max)) {
1449 *dataptr++ = (
unsigned char)n;
1453 if (i < f->record_max) {
1455 memset ((
unsigned char *)f->
record->
data + i,
' ',
1471 #ifdef WITH_SEQRA_EXTFH
1474 extfh_ret = extfh_sequential_write (f, opt);
1484 for (i = (
int)f->
record->
size - 1; i >= 0; --i) {
1496 for (i = 0; i < lingptr->
lin_top; ++i) {
1497 putc (
'\n', (FILE *)f->
file);
1514 for (i = 0; i < (int)size; ++i, ++p) {
1516 putc (0, (FILE *)f->
file);
1518 putc ((
int)(*p), (FILE *)f->
file);
1522 (FILE *)f->
file) != 1)) {
1529 putc (
'\n', (FILE *)f->
file);
1532 putc (
'\r', (FILE *)f->
file);
1534 putc (
'\r', (FILE *)f->
file);
1562 #ifdef WITH_SEQRA_EXTFH
1565 extfh_ret = extfh_relative_start (f, cond, k);
1571 if (fstat (f->
fd, &st) != 0 || st.st_size == 0) {
1585 kindex = st.st_size / relsize;
1593 ksindex = st.st_size / relsize;
1595 if (kindex > ksindex) {
1629 }
else if (kcond ==
COB_GT) {
1640 off = kindex * relsize;
1641 if (off >= st.st_size) {
1644 if (lseek (f->
fd, off, SEEK_SET) == (off_t)-1) {
1654 lseek (f->
fd, off, SEEK_SET);
1680 #ifdef WITH_SEQRA_EXTFH
1683 extfh_ret = extfh_relative_read (f, k, read_opts);
1693 lseek (f->
fd, (off_t)0, SEEK_CUR);
1701 off = relnum * relsize;
1702 if (lseek (f->
fd, off, SEEK_SET) == (off_t)-1 ||
1709 lseek (f->
fd, off, SEEK_SET);
1729 #ifdef WITH_SEQRA_EXTFH
1732 extfh_ret = extfh_relative_read_next (f, read_opts);
1740 lseek (f->
fd, (off_t)0, SEEK_CUR);
1744 if (fstat (f->
fd, &st) != 0 || st.st_size == 0) {
1747 if (st.st_size < relsize) {
1751 curroff = lseek (f->
fd, (off_t)0, SEEK_CUR);
1756 curroff = lseek (f->
fd, (off_t)0, SEEK_SET);
1759 curroff = st.st_size - relsize;
1760 curroff = lseek (f->
fd, curroff, SEEK_SET);
1766 }
else if (curroff > relsize) {
1767 curroff -= (relsize * 2);
1768 curroff = lseek (f->
fd, curroff, SEEK_SET);
1782 if (bytesread != 0) {
1794 relnum = (int)((curroff / relsize) + 1);
1798 lseek (f->
fd, curroff, SEEK_SET);
1804 curroff = lseek (f->
fd, curroff, SEEK_SET);
1809 if (curroff > relsize) {
1810 curroff -= (relsize * 2);
1811 curroff = lseek (f->
fd, curroff, SEEK_SET);
1816 curroff = lseek (f->
fd, (off_t) f->
record_max, SEEK_CUR);
1830 #ifdef WITH_SEQRA_EXTFH
1833 extfh_ret = extfh_relative_write (f, opt);
1843 lseek (f->
fd, (off_t)0, SEEK_CUR);
1852 off = (off_t) (relsize * kindex);
1853 if (lseek (f->
fd, off, SEEK_SET) == (off_t)-1) {
1856 if (read (f->
fd, &size, sizeof (size)) > 0) {
1862 off = lseek (f->
fd, (off_t)0, SEEK_CUR);
1864 lseek (f->
fd, off, SEEK_SET);
1877 i = (int)(off / relsize);
1891 #ifdef WITH_SEQRA_EXTFH
1894 extfh_ret = extfh_relative_rewrite (f, opt);
1911 off = relnum * relsize;
1912 if (lseek (f->
fd, off, SEEK_SET) == (off_t)-1 ||
1917 lseek (f->
fd, (off_t)0, SEEK_CUR);
1932 #ifdef WITH_SEQRA_EXTFH
1935 extfh_ret = extfh_relative_delete (f);
1947 off = relnum * relsize;
1948 if (lseek (f->
fd, off, SEEK_SET) == (off_t)-1 ||
1953 lseek (f->
fd, off, SEEK_SET);
1965 #ifdef WITH_ANY_ISAM
1968 fisretsts (
const int dfltsts)
2010 freefh (
struct indexfile *fh)
2031 struct indexfile *fh;
2035 memset ((
void *)&k0, 0,
sizeof(k0));
2036 if (fh->saverecnum >= 0) {
2040 isstart (fh->isfd, &k0, 0, (
void *)fh->recwrk, ISEQUAL);
2042 isread (fh->isfd, (
void *)fh->recwrk, ISEQUAL);
2043 isstart (fh->isfd, &fh->key[fh->curkey], 0,
2044 (
void *)fh->recwrk, ISEQUAL);
2045 isread (fh->isfd, (
void *)fh->recwrk, ISEQUAL);
2046 while (
isrecnum != fh->saverecnum) {
2048 if (
isread (fh->isfd, (
void *)fh->recwrk, fh->readdir)) {
2053 if (fh->readdir == ISNEXT) {
2055 isread (fh->isfd, (
void *)fh->recwrk, ISPREV);
2057 isread (fh->isfd, (
void *)fh->recwrk, ISNEXT);
2060 }
else if (fh->readdone && fh->curkey == 0) {
2061 memcpy (fh->recwrk + fh->key[0].k_start,
2062 fh->savekey, (
size_t)fh->key[0].k_leng);
2063 isstart (fh->isfd, &fh->key[fh->curkey], 0,
2064 (
void *)fh->recwrk, ISGTEQ);
2073 struct indexfile *fh;
2076 if (fh->curkey >= 0 && fh->readdir != -1) {
2078 if (fh->wrkhasrec != fh->readdir) {
2082 if (
isread (fh->isfd, (
void *)fh->recwrk, fh->readdir)) {
2083 fh->saverecnum = -1;
2085 if (fh->saveerrno == EENDFILE ||
2086 fh->saveerrno == ENOREC) {
2087 fh->eofpending = fh->readdir;
2097 fh->saverecnum = -1;
2106 bdb_msgcall_set (DB_ENV *dbe,
const char *err)
2115 bdb_errcall_set (DB_ENV *dbe,
const char *
prefix,
const char *err)
2125 join_environment (
void)
2133 ret = db_env_create (&bdb_env, 0);
2136 "env_create", ret, db_strerror (ret));
2140 bdb_env->set_errcall (bdb_env, bdb_errcall_set);
2141 #if (DB_VERSION_MAJOR > 4) || ((DB_VERSION_MAJOR == 4) && (DB_VERSION_MINOR > 2))
2142 bdb_env->set_msgcall (bdb_env, bdb_msgcall_set);
2145 bdb_env->set_errfile (bdb_env, stderr);
2146 #if (DB_VERSION_MAJOR > 4) || ((DB_VERSION_MAJOR == 4) && (DB_VERSION_MINOR > 2))
2147 bdb_env->set_msgfile (bdb_env, stderr);
2150 bdb_env->set_cachesize (bdb_env, 0, 2*1024*1024, 0);
2152 flags = DB_CREATE | DB_INIT_MPOOL | DB_INIT_CDB;
2153 ret = bdb_env->open (bdb_env, cobsetptr->
bdb_home, flags, 0);
2156 "env->open", ret, db_strerror (ret));
2157 bdb_env->close (bdb_env, 0);
2161 #if (DB_VERSION_MAJOR > 4) || ((DB_VERSION_MAJOR == 4) && (DB_VERSION_MINOR > 1))
2162 bdb_env->get_data_dirs (bdb_env, &bdb_data_dir);
2164 bdb_env->lock_id (bdb_env, &bdb_lock_id);
2168 lock_record (
cob_file *f,
const char *key,
const unsigned int keylen)
2170 struct indexed_file *p;
2176 len = keylen + p->filenamelen + 1;
2177 if (len > rlo_size) {
2182 memcpy ((
char *)record_lock_object, p->filename,
2183 (
size_t)(p->filenamelen + 1));
2184 memcpy ((
char *)record_lock_object + p->filenamelen + 1, key,
2186 dbt.size = (cob_dbtsize_t) len;
2187 dbt.data = record_lock_object;
2188 ret = bdb_env->lock_get (bdb_env, p->bdb_lock_id, DB_LOCK_NOWAIT,
2189 &dbt, DB_LOCK_WRITE, &p->bdb_record_lock);
2191 p->record_locked = 1;
2197 test_record_lock (
cob_file *f,
const char *key,
const unsigned int keylen)
2199 struct indexed_file *p;
2206 len = keylen + p->filenamelen + 1;
2207 if (len > rlo_size) {
2212 memcpy ((
char *)record_lock_object, p->filename,
2213 (
size_t)(p->filenamelen + 1));
2214 memcpy ((
char *)record_lock_object + p->filenamelen + 1, key,
2216 dbt.size = (cob_dbtsize_t) len;
2217 dbt.data = record_lock_object;
2218 ret = bdb_env->lock_get (bdb_env, p->bdb_lock_id, DB_LOCK_NOWAIT,
2219 &dbt, DB_LOCK_WRITE, &test_lock);
2221 bdb_env->lock_put (bdb_env, &test_lock);
2229 struct indexed_file *p;
2233 if (p->record_locked == 0) {
2236 ret = bdb_env->lock_put (bdb_env, &p->bdb_record_lock);
2237 p->record_locked = 0;
2245 struct indexed_file *p;
2252 memcpy (p->temp_key, p->key.data, (
size_t)p->key.size);
2253 p->db[i]->cursor (p->db[i],
NULL, &p->cursor[i], 0);
2254 ret = DB_SEQ (p->cursor[i], DB_SET_RANGE);
2255 while (ret == 0 && memcmp (p->key.data, p->temp_key, (
size_t)p->key.size) == 0) {
2257 sizeof(
unsigned int));
2258 ret = DB_SEQ (p->cursor[i], DB_NEXT);
2260 p->cursor[i]->c_close (p->cursor[i]);
2261 p->cursor[i] =
NULL;
2266 check_alt_keys (
cob_file *f,
const int rewrite)
2268 struct indexed_file *p;
2273 for (i = 1; i < f->
nkeys; ++i) {
2276 ret = DB_GET (p->db[i], 0);
2292 indexed_write_internal (
cob_file *f,
const int rewrite,
const int opt)
2294 struct indexed_file *p;
2302 flags = DB_WRITECURSOR;
2306 if (p->write_cursor_open) {
2309 p->db[0]->cursor (p->db[0],
NULL, &p->cursor[0], flags);
2310 p->write_cursor_open = 1;
2315 if (f->
nkeys > 1 && !rewrite) {
2316 if (check_alt_keys (f, 0)) {
2318 p->cursor[0]->c_close (p->cursor[0]);
2319 p->cursor[0] =
NULL;
2320 p->write_cursor_open = 0;
2328 if (p->cursor[0]->c_get (p->cursor[0], &p->key, &p->data, DB_SET) == 0) {
2330 p->cursor[0]->c_close (p->cursor[0]);
2331 p->cursor[0] =
NULL;
2332 p->write_cursor_open = 0;
2337 p->data.size = (cob_dbtsize_t) f->
record->
size;
2338 p->cursor[0]->c_put (p->cursor[0], &p->key, &p->data, DB_KEYFIRST);
2342 for (i = 1; i < f->
nkeys; ++i) {
2343 if (rewrite && ! p->rewrite_sec_key[i]) {
2348 dupno = get_dupno(f, i);
2352 sizeof(
unsigned int));
2353 p->data.data = p->temp_key;
2354 p->data.size = f->
keys[0].
field->
size +
sizeof(
unsigned int);;
2356 flags = DB_NOOVERWRITE;
2360 if (DB_PUT (p->db[i], flags) != 0) {
2362 p->cursor[0]->c_close (p->cursor[0]);
2363 p->cursor[0] =
NULL;
2364 p->write_cursor_open = 0;
2371 if (bdb_env !=
NULL) {
2373 if (lock_record (f, p->key.data, p->key.size)) {
2375 p->cursor[0]->c_close (p->cursor[0]);
2376 p->cursor[0] =
NULL;
2377 p->write_cursor_open = 0;
2384 p->cursor[0]->c_close (p->cursor[0]);
2385 p->cursor[0] =
NULL;
2386 p->write_cursor_open = 0;
2393 const int read_opts,
const int test_lock)
2395 struct indexed_file *p;
2402 for (p->key_index = 0; p->key_index < f->
nkeys; p->key_index++) {
2409 DBT_SET (p->key, key);
2411 if (p->key_index != 0) {
2412 p->db[0]->cursor (p->db[0],
NULL, &p->cursor[0], 0);
2414 p->db[p->key_index]->cursor (p->db[p->key_index],
NULL, &p->cursor[p->key_index], 0);
2416 ret = DB_SEQ (p->cursor[p->key_index], DB_FIRST);
2417 }
else if (cond ==
COB_LA) {
2418 ret = DB_SEQ (p->cursor[p->key_index], DB_LAST);
2420 ret = DB_SEQ (p->cursor[p->key_index], DB_SET_RANGE);
2425 ret = memcmp (p->key.data, key->
data, key->
size);
2430 ret = DB_SEQ (p->cursor[p->key_index], DB_LAST);
2432 ret = DB_SEQ (p->cursor[p->key_index], DB_PREV);
2437 ret = DB_SEQ (p->cursor[p->key_index], DB_LAST);
2438 }
else if (memcmp (p->key.data, key->
data, key->
size) != 0) {
2439 ret = DB_SEQ (p->cursor[p->key_index], DB_PREV);
2440 }
else if (f->
keys[p->key_index].
flag) {
2441 ret = DB_SEQ (p->cursor[p->key_index], DB_NEXT_NODUP);
2443 ret = DB_SEQ (p->cursor[p->key_index], DB_LAST);
2445 ret = DB_SEQ (p->cursor[p->key_index], DB_PREV);
2450 while (ret == 0 && memcmp (p->key.data, key->
data, key->
size) == 0) {
2451 ret = DB_SEQ (p->cursor[p->key_index], DB_NEXT);
2465 if (ret == 0 && p->key_index > 0) {
2467 memcpy (p->temp_key, p->key.data, f->
keys[p->key_index].
field->
size);
2471 p->key.data = p->data.data;
2473 ret = DB_GET (p->db[0], 0);
2476 if (ret == 0 && test_lock) {
2478 ret = test_record_lock (f, p->key.data, p->key.size);
2480 p->cursor[p->key_index]->c_close (p->cursor[p->key_index]);
2481 p->cursor[p->key_index] =
NULL;
2482 if (p->key_index != 0) {
2483 p->cursor[0]->c_close (p->cursor[0]);
2484 p->cursor[0] =
NULL;
2490 ret = lock_record (f, p->key.data, p->key.size);
2492 p->cursor[p->key_index]->c_close (p->cursor[p->key_index]);
2493 p->cursor[p->key_index] =
NULL;
2494 if (p->key_index != 0) {
2495 p->cursor[0]->c_close (p->cursor[0]);
2496 p->cursor[0] =
NULL;
2504 if (p->key_index == 0) {
2505 memcpy (p->last_readkey[0], p->key.data, f->
keys[0].
field->
size);
2507 memcpy (p->last_readkey[p->key_index],
2509 memcpy (p->last_readkey[p->key_index + f->
nkeys], p->key.data, f->
keys[0].
field->
size);
2511 p->last_dupno[p->key_index] = dupno;
2516 p->cursor[p->key_index]->c_close (p->cursor[p->key_index]);
2517 p->cursor[p->key_index] =
NULL;
2518 if (p->key_index != 0) {
2519 p->cursor[0]->c_close (p->cursor[0]);
2520 p->cursor[0] =
NULL;
2527 indexed_delete_internal (
cob_file *f,
const int rewrite)
2529 struct indexed_file *p;
2539 flags = DB_WRITECURSOR;
2543 if (p->write_cursor_open) {
2546 p->db[0]->cursor (p->db[0],
NULL, &p->cursor[0], flags);
2547 p->write_cursor_open = 1;
2550 if (bdb_env !=
NULL) {
2557 ret = DB_SEQ (p->cursor[0], DB_SET);
2560 p->cursor[0]->c_close (p->cursor[0]);
2561 p->cursor[0] =
NULL;
2562 p->write_cursor_open = 0;
2566 if (bdb_env !=
NULL) {
2567 ret = test_record_lock (f, p->key.data, p->key.size);
2570 p->cursor[0]->c_close (p->cursor[0]);
2571 p->cursor[0] =
NULL;
2572 p->write_cursor_open = 0;
2580 offset = (
char *) p->data.data - (
char *) f->
record->
data;
2581 for (i = 1; i < f->
nkeys; ++i) {
2583 p->key.data = (
char *)p->key.data + offset;
2586 p->rewrite_sec_key[i] = memcmp (p->key.data, f->
keys[i].
field->
data, (
size_t)p->key.size);
2587 if (!p->rewrite_sec_key[i]) {
2592 DB_DEL (p->db[i], &p->key, 0);
2594 DBT sec_key = p->key;
2596 p->db[i]->cursor (p->db[i],
NULL, &p->cursor[i], flags);
2597 if (DB_SEQ (p->cursor[i], DB_SET_RANGE) == 0) {
2598 while (sec_key.size == p->key.size &&
2599 memcmp (p->key.data, sec_key.data,
2600 (
size_t)sec_key.size) == 0) {
2601 if (memcmp (p->data.data, prim_key.data,
2602 (
size_t)prim_key.size) == 0) {
2603 p->cursor[i]->c_del (p->cursor[i], 0);
2605 if (DB_SEQ (p->cursor[i], DB_NEXT) != 0) {
2610 p->cursor[i]->c_close (p->cursor[i]);
2611 p->cursor[i] =
NULL;
2616 p->cursor[0]->c_del (p->cursor[0], 0);
2619 p->cursor[0]->c_close (p->cursor[0]);
2620 p->cursor[0] =
NULL;
2621 p->write_cursor_open = 0;
2632 if (filename[0] ==
'/' || filename[0] ==
'\\') {
2635 if (isalpha (filename[0]) && filename[1] ==
':' &&
2636 (filename[2] ==
'/' || filename[2] ==
'\\')) {
2643 if (filename[0] ==
'/') {
2652 bdb_nofile (
const char *filename)
2656 if (!bdb_env || is_absolute (filename)) {
2658 if (access (filename,
F_OK) && errno == ENOENT) {
2664 for (i = 0; bdb_data_dir && bdb_data_dir[i]; ++i) {
2666 if (is_absolute (bdb_data_dir[i])) {
2674 if (access (bdb_buff,
F_OK) == 0 || errno != ENOENT) {
2683 if (access (bdb_buff,
F_OK) == 0 || errno != ENOENT) {
2697 #ifdef WITH_ANY_ISAM
2703 snprintf (
file_open_buff, (
size_t)COB_FILE_MAX,
"%s.dat", filename);
2706 #elif defined(WITH_DB)
2709 for (i = 0; i < f->
nkeys; ++i) {
2731 #ifdef WITH_INDEX_EXTFH
2734 ret = extfh_indexed_locate (f, filename);
2738 if (access (filename,
F_OK) && errno == ENOENT) {
2749 ret = extfh_indexed_open (f, filename, mode, sharing);
2766 #elif defined(WITH_ANY_ISAM)
2768 struct indexfile *fh;
2793 if (!(errno == ENOENT &&
2806 snprintf (
file_open_buff, (
size_t)COB_FILE_MAX,
"%s.dat", filename);
2810 if (!(errno == ENOENT &&
2856 isfd =
isopen ((
void *)filename, ISINPUT | ISEXCLLOCK | vmode);
2876 ((
sizeof (
struct keydesc)) * (f->
nkeys + 1)));
2878 for (k = 0; k < f->
nkeys; ++k) {
2879 fh->key[k].k_flags = f->
keys[k].
flag ? ISDUPS : ISNODUPS;
2880 fh->key[k].k_nparts = 1;
2883 if (fh->lenkey < fh->key[k].k_leng) {
2884 fh->lenkey = fh->key[k].k_leng;
2886 fh->key[k].k_type = CHARTYPE;
2893 vmode | ISINOUT | ISEXCLLOCK);
2895 if (lmode == ISAUTOLOCK) {
2899 isfd =
isopen ((
void *)filename, omode | lmode | vmode);
2926 memset(&di, 0,
sizeof(di));
2929 fh->nkeys = di.di_nkeys & 0x7F;
2930 if (fh->nkeys != f->
nkeys) {
2933 for (k = 0; k < fh->nkeys && !ret; ++k) {
2934 memset (&fh->key[k], 0,
sizeof(
struct keydesc));
2936 if (fh->lenkey < fh->key[k].k_leng) {
2937 fh->lenkey = fh->key[k].k_leng;
2941 if (!(fh->key[k].k_flags & ISDUPS)) {
2945 if (fh->key[k].k_flags & ISDUPS) {
2949 if (fh->key[k].k_nparts != 1 ||
2950 (
int)fh->key[k].k_start != (
int)f->
keys[k].
offset ||
2968 for (k = 1; k < f->
nkeys; ++k) {
2985 fh->savekey =
cob_malloc ((
size_t)(fh->lenkey + 1));
2994 #elif defined(WITH_DB)
2996 struct indexed_file *p;
3000 db_lockmode_t lock_mode;
3022 if (bdb_nofile (filename)) {
3029 p =
cob_malloc (
sizeof (
struct indexed_file));
3030 if (bdb_env !=
NULL) {
3034 lock_mode = DB_LOCK_WRITE;
3036 lock_mode = DB_LOCK_READ;
3038 p->key.size = (cob_dbtsize_t) strlen (filename);
3039 p->key.data = filename;
3040 ret = bdb_env->lock_get (bdb_env, bdb_lock_id, DB_LOCK_NOWAIT,
3041 &p->key, lock_mode, &p->bdb_file_lock);
3044 if (ret == DB_LOCK_NOTGRANTED) {
3067 p->filenamelen = (int) strlen (filename);
3068 p->last_readkey =
cob_malloc (
sizeof (
unsigned char *) * 2 * f->
nkeys);
3072 for (i = 0; i < f->
nkeys; ++i) {
3077 for (i = 0; i < f->
nkeys; ++i) {
3090 if (errno == ENOENT &&
3095 if (!directory exists) {
3123 ret = db_create (&p->db[i], bdb_env, 0);
3131 ret = db_create (&p->db[i], bdb_env, 0);
3136 p->db[i]->set_flags (p->db[i], DB_DUP);
3149 for (j = 0; j < i; ++j) {
3150 DB_CLOSE (p->db[j]);
3152 if (handle_created) {
3153 DB_CLOSE (p->db[i]);
3159 if (bdb_env !=
NULL) {
3160 bdb_env->lock_put (bdb_env, &p->bdb_file_lock);
3164 case DB_LOCK_NOTGRANTED:
3193 p->temp_key =
cob_malloc (maxsize +
sizeof(
unsigned int));
3198 memset ((
void *)&p->key, 0, sizeof (DBT));
3199 memset ((
void *)&p->data, 0, sizeof (DBT));
3200 p->filename =
cob_malloc (strlen (filename) + 1);
3201 strcpy (p->filename, filename);
3202 p->write_cursor_open = 0;
3203 p->record_locked = 0;
3204 if (bdb_env !=
NULL) {
3205 bdb_env->lock_id (bdb_env, &p->bdb_lock_id);
3209 p->db[0]->cursor (p->db[0],
NULL, &p->cursor[0], 0);
3210 ret = DB_SEQ (p->cursor[0], DB_FIRST);
3211 p->cursor[0]->c_close (p->cursor[0]);
3212 p->cursor[0] =
NULL;
3214 memcpy (p->last_readkey[0], p->key.data, (
size_t)p->key.size);
3216 p->data.data =
NULL;
3236 #ifdef WITH_INDEX_EXTFH
3238 return extfh_indexed_close (f, opt);
3240 #elif defined(WITH_ANY_ISAM)
3242 struct indexfile *fh;
3250 if (fh->isfd >= 0) {
3257 #elif defined(WITH_DB)
3259 struct indexed_file *p;
3266 for (i = 0; i < (int)f->
nkeys; ++i) {
3268 p->cursor[i]->c_close (p->cursor[i]);
3271 for (i = (
int)f->
nkeys - 1; i >= 0; --i) {
3273 DB_CLOSE (p->db[i]);
3289 if (bdb_env !=
NULL) {
3291 bdb_env->lock_put (bdb_env, &p->bdb_file_lock);
3292 bdb_env->lock_id_free (bdb_env, p->bdb_lock_id);
3311 #ifdef WITH_INDEX_EXTFH
3313 return extfh_indexed_start (f, cond, key);
3315 #elif defined(WITH_ANY_ISAM)
3317 struct indexfile *fh;
3333 for (k = 0; k < f->
nkeys; ++k) {
3340 if (klen < 1 || klen > fh->key[k].k_leng) {
3342 klen = fh->key[k].k_leng;
3350 fh->readdir = ISNEXT;
3354 fh->readdir = ISNEXT;
3358 fh->readdir = ISNEXT;
3362 fh->readdir = ISPREV;
3366 fh->readdir = ISPREV;
3370 fh->readdir = ISNEXT;
3374 fh->readdir = ISPREV;
3398 fh->startcond = savecond;
3399 memcpy (fh->savekey, f->
record->
data + fh->key[k].k_start,
3400 (
size_t)fh->key[k].k_leng);
3407 #elif defined(WITH_DB)
3409 return indexed_start_internal (f, cond, key, 0, 0);
3422 #ifdef WITH_INDEX_EXTFH
3424 return extfh_indexed_read (f, key, read_opts);
3426 #elif defined(WITH_ANY_ISAM)
3428 struct indexfile *fh;
3440 for (k = 0; k < f->
nkeys; ++k) {
3445 if (fh->curkey != (
int)k) {
3447 isstart (fh->isfd, &fh->key[k], 0,
3454 if (read_opts & COB_READ_LOCK) {
3460 if (!(read_opts & COB_READ_IGNORE_LOCK)) {
3466 if (read_opts & COB_READ_IGNORE_LOCK) {
3480 memset (fh->savekey, 0, (
size_t)fh->key[0].k_leng);
3490 memcpy (fh->savekey, f->
record->
data + fh->key[0].k_start,
3491 (
size_t)fh->key[0].k_leng);
3500 #elif defined(WITH_DB)
3502 struct indexed_file *p;
3509 bdb_opts = read_opts;
3510 if (bdb_env !=
NULL) {
3513 bdb_opts &= ~COB_READ_LOCK;
3521 bdb_opts &= ~COB_READ_LOCK;
3524 ret = indexed_start_internal (f,
COB_EQ, key, bdb_opts, test_lock);
3530 memcpy (f->
record->
data, p->data.data, (
size_t)p->data.size);
3545 #ifdef WITH_INDEX_EXTFH
3547 return extfh_indexed_read_next (f, read_opts);
3549 #elif defined(WITH_ANY_ISAM)
3551 struct indexfile *fh;
3568 if (fh->curkey == -1) {
3570 isstart (fh->isfd, &fh->key[0], 0,
NULL, ISFIRST);
3572 fh->readdir = ISNEXT;
3577 if (read_opts & COB_READ_LOCK) {
3583 if (!(read_opts & COB_READ_IGNORE_LOCK)) {
3588 if (read_opts & COB_READ_IGNORE_LOCK) {
3589 lmode |= ISSKIPLOCK;
3598 fh->readdir = ISNEXT;
3599 if (fh->eofpending == ISNEXT) {
3604 if (fh->startiscur) {
3605 if (fh->startcond ==
COB_LA) {
3609 }
else if (fh->startcond ==
COB_FI) {
3616 switch (fh->startcond) {
3620 && memcmp (f->
record->
data + fh->key[fh->curkey].k_start, fh->savekey, (
size_t)fh->key[fh->curkey].k_leng) == 0) {
3631 && memcmp (f->
record->
data + fh->key[fh->curkey].k_start, fh->savekey, (
size_t)fh->key[fh->curkey].k_leng) == 0) {
3641 && memcmp (f->
record->
data + fh->key[fh->curkey].k_start, fh->savekey, (
size_t)fh->key[fh->curkey].k_leng) >= 0) {
3647 && memcmp (f->
record->
data + fh->key[fh->curkey].k_start, fh->savekey, (
size_t)fh->key[fh->curkey].k_leng) <= 0) {
3658 }
else if (fh->wrkhasrec == ISNEXT) {
3660 if (fh->lmode & ISLOCK) {
3663 ISCURR | fh->lmode)) {
3668 if (fh->wrkhasrec == ISPREV) {
3678 fh->readdir = ISPREV;
3679 if (fh->eofpending == ISPREV) {
3684 if (fh->startiscur) {
3685 if (fh->startcond ==
COB_FI) {
3689 }
else if (fh->startcond ==
COB_LA) {
3696 switch (fh->startcond) {
3700 && memcmp (f->
record->
data + fh->key[fh->curkey].k_start, fh->savekey, (
size_t)fh->key[fh->curkey].k_leng) == 0) {
3710 && memcmp (f->
record->
data + fh->key[fh->curkey].k_start, fh->savekey, (
size_t)fh->key[fh->curkey].k_leng) >= 0) {
3716 && memcmp (f->
record->
data + fh->key[fh->curkey].k_start, fh->savekey, (
size_t)fh->key[fh->curkey].k_leng) <= 0) {
3722 && memcmp (f->
record->
data + fh->key[fh->curkey].k_start, fh->savekey, (
size_t)fh->key[fh->curkey].k_leng) < 0) {
3733 }
else if (fh->wrkhasrec == ISPREV) {
3735 if (fh->lmode & ISLOCK) {
3738 ISCURR | fh->lmode)) {
3743 if (fh->wrkhasrec == ISNEXT) {
3753 fh->readdir = ISNEXT;
3759 fh->readdir = ISPREV;
3765 fh->readdir = ISNEXT;
3772 memset (fh->savekey, 0, (
size_t)fh->key[0].k_leng);
3784 memcpy (fh->savekey, f->
record->
data + fh->key[0].k_start,
3785 (
size_t)fh->key[0].k_leng);
3793 #ifdef COB_WITH_STATUS_02
3794 if((isstat1 ==
'0') && (isstat2 ==
'2')) {
3800 #elif defined(WITH_DB)
3802 struct indexed_file *p;
3817 bdb_opts = read_opts;
3818 if (bdb_env !=
NULL) {
3821 bdb_opts &= ~COB_READ_LOCK;
3828 bdb_opts &= ~COB_READ_LOCK;
3838 nextprev = DB_FIRST;
3841 if (p->key_index != 0) {
3842 p->db[0]->cursor (p->db[0],
NULL, &p->cursor[0], 0);
3844 p->db[p->key_index]->cursor (p->db[p->key_index],
NULL, &p->cursor[p->key_index], 0);
3849 nextprev == DB_PREV)) {
3850 p->cursor[p->key_index]->c_close (p->cursor[p->key_index]);
3851 p->cursor[p->key_index] =
NULL;
3852 if (p->key_index != 0) {
3853 p->cursor[0]->c_close (p->cursor[0]);
3854 p->cursor[0] =
NULL;
3859 p->key.size = (cob_dbtsize_t) f->
keys[p->key_index].
field->
size;
3860 p->key.data = p->last_readkey[p->key_index];
3861 ret = DB_SEQ (p->cursor[p->key_index], DB_SET);
3862 if (!ret && p->key_index > 0) {
3866 memcmp (p->key.data, p->last_readkey[p->key_index], (
size_t)p->key.size) == 0 &&
3867 dupno < p->last_dupno[p->key_index]) {
3868 ret = DB_SEQ (p->cursor[p->key_index], DB_NEXT);
3872 memcmp (p->key.data, p->last_readkey[p->key_index], (
size_t)p->key.size) == 0 &&
3873 dupno == p->last_dupno[p->key_index]) {
3874 ret = memcmp (p->last_readkey[p->key_index + f->
nkeys], p->data.data, f->
keys[0].
field->
size);
3879 ret = memcmp (p->last_readkey[p->key_index + f->
nkeys], p->data.data, f->
keys[0].
field->
size);
3883 p->key.data = p->last_readkey[p->key_index + f->
nkeys];
3884 ret = DB_GET (p->db[0], 0);
3888 if (bdb_env !=
NULL && !file_changed) {
3889 if (!(bdb_opts & COB_READ_IGNORE_LOCK)) {
3890 ret = test_record_lock (f, p->key.data, p->key.size);
3892 p->cursor[p->key_index]->c_close (p->cursor[p->key_index]);
3893 p->cursor[p->key_index] =
NULL;
3894 if (p->key_index != 0) {
3895 p->cursor[0]->c_close (p->cursor[0]);
3896 p->cursor[0] =
NULL;
3901 if (bdb_opts & COB_READ_LOCK) {
3902 ret = lock_record (f, p->key.data, p->key.size);
3904 p->cursor[p->key_index]->c_close (p->cursor[p->key_index]);
3905 p->cursor[p->key_index] =
NULL;
3906 if (p->key_index != 0) {
3907 p->cursor[0]->c_close (p->cursor[0]);
3908 p->cursor[0] =
NULL;
3916 if (nextprev == DB_FIRST || nextprev == DB_LAST) {
3919 p->key.size = (cob_dbtsize_t) f->
keys[p->key_index].
field->
size;
3920 p->key.data = p->last_readkey[p->key_index];
3921 ret = DB_SEQ (p->cursor[p->key_index], DB_SET_RANGE);
3924 if (nextprev == DB_PREV) {
3928 p->cursor[p->key_index]->c_close (p->cursor[p->key_index]);
3929 p->cursor[p->key_index] =
NULL;
3930 if (p->key_index != 0) {
3931 p->cursor[0]->c_close (p->cursor[0]);
3932 p->cursor[0] =
NULL;
3937 if (memcmp (p->key.data, p->last_readkey[p->key_index], (
size_t)p->key.size) == 0) {
3938 if (p->key_index > 0 && f->
keys[p->key_index].
flag) {
3941 memcmp (p->key.data, p->last_readkey[p->key_index], (
size_t)p->key.size) == 0 &&
3942 dupno < p->last_dupno[p->key_index]) {
3943 ret = DB_SEQ (p->cursor[p->key_index], DB_NEXT);
3947 if (nextprev == DB_PREV) {
3951 p->cursor[p->key_index]->c_close (p->cursor[p->key_index]);
3952 p->cursor[p->key_index] =
NULL;
3953 if (p->key_index != 0) {
3954 p->cursor[0]->c_close (p->cursor[0]);
3955 p->cursor[0] =
NULL;
3960 if (memcmp (p->key.data, p->last_readkey[p->key_index], (
size_t)p->key.size) == 0 &&
3961 dupno == p->last_dupno[p->key_index]) {
3964 if (nextprev == DB_PREV) {
3975 if (nextprev == DB_PREV) {
3983 if (read_nextprev) {
3984 ret = DB_SEQ (p->cursor[p->key_index], nextprev);
3986 p->cursor[p->key_index]->c_close (p->cursor[p->key_index]);
3987 p->cursor[p->key_index] =
NULL;
3988 if (p->key_index != 0) {
3989 p->cursor[0]->c_close (p->cursor[0]);
3990 p->cursor[0] =
NULL;
3996 if (p->key_index > 0) {
3998 memcpy (p->temp_key, p->key.data, (
size_t)p->key.size);
4002 p->key.data = p->data.data;
4004 if (DB_GET (p->db[0], 0) != 0) {
4005 p->cursor[p->key_index]->c_close (p->cursor[p->key_index]);
4006 p->cursor[p->key_index] =
NULL;
4007 p->cursor[0]->c_close (p->cursor[0]);
4008 p->cursor[0] =
NULL;
4012 if (bdb_env !=
NULL) {
4013 if (!(bdb_opts & COB_READ_IGNORE_LOCK)) {
4014 ret = test_record_lock (f, p->key.data, p->key.size);
4016 p->cursor[p->key_index]->c_close (p->cursor[p->key_index]);
4017 p->cursor[p->key_index] =
NULL;
4018 if (p->key_index != 0) {
4019 p->cursor[0]->c_close (p->cursor[0]);
4020 p->cursor[0] =
NULL;
4025 if (bdb_opts & COB_READ_LOCK) {
4026 ret = lock_record (f, p->key.data, p->key.size);
4028 p->cursor[p->key_index]->c_close (p->cursor[p->key_index]);
4029 p->cursor[p->key_index] =
NULL;
4030 if (p->key_index != 0) {
4031 p->cursor[0]->c_close (p->cursor[0]);
4032 p->cursor[0] =
NULL;
4038 if (p->key_index == 0) {
4039 memcpy (p->last_readkey[0], p->key.data, (
size_t)p->key.size);
4041 memcpy (p->last_readkey[p->key_index], p->temp_key,
4043 memcpy (p->last_readkey[p->key_index + f->
nkeys], p->key.data, f->
keys[0].
field->
size);
4045 p->last_dupno[p->key_index] = dupno;
4050 p->cursor[p->key_index]->c_close (p->cursor[p->key_index]);
4051 p->cursor[p->key_index] =
NULL;
4052 if (p->key_index != 0) {
4053 p->cursor[0]->c_close (p->cursor[0]);
4054 p->cursor[0] =
NULL;
4058 memcpy (f->
record->
data, p->data.data, (
size_t)p->data.size);
4074 #ifdef WITH_INDEX_EXTFH
4076 return extfh_indexed_write (f, opt);
4078 #elif defined(WITH_ANY_ISAM)
4080 struct indexfile *fh;
4089 memcmp (fh->savekey, f->
record->
data + fh->key[0].k_start,
4090 (
size_t)fh->key[0].k_leng) > 0) {
4102 memcpy (fh->savekey, f->
record->
data + fh->key[0].k_start,
4103 (
size_t)fh->key[0].k_leng);
4105 #ifdef COB_WITH_STATUS_02
4106 if((isstat1 ==
'0') && (isstat2 ==
'2')) {
4112 #elif defined(WITH_DB)
4114 struct indexed_file *p;
4120 if (bdb_env !=
NULL) {
4127 p->last_key =
cob_malloc ((
size_t)p->key.size);
4129 memcmp (p->last_key, p->key.data, (
size_t)p->key.size) > 0) {
4132 memcpy (p->last_key, p->key.data, (
size_t)p->key.size);
4134 return indexed_write_internal (f, 0, opt);
4148 #ifdef WITH_INDEX_EXTFH
4150 return extfh_indexed_delete (f);
4152 #elif defined(WITH_ANY_ISAM)
4154 struct indexfile *fh;
4162 if (fh->curkey == -1) {
4164 isstart (fh->isfd, &fh->key[0], 0,
4167 fh->readdir = ISNEXT;
4169 savefileposition (f);
4170 if (fh->curkey != 0) {
4172 isstart (fh->isfd, &fh->key[0], 0,
4181 restorefileposition (f);
4184 #elif defined(WITH_DB)
4189 return indexed_delete_internal (f, 0);
4202 #ifdef WITH_INDEX_EXTFH
4204 return extfh_indexed_rewrite (f, opt);
4206 #elif defined(WITH_ANY_ISAM)
4208 struct indexfile *fh;
4221 memcmp (fh->savekey, f->
record->
data + fh->key[0].k_start,
4222 (
size_t)fh->key[0].k_leng) != 0) {
4225 if (fh->curkey >= 0) {
4230 fh->readdir = ISNEXT;
4231 savefileposition (f);
4233 if (fh->curkey != 0) {
4235 isstart (fh->isfd, &fh->key[0], 0, (
void *)fh->recwrk,
4239 if (
isread (fh->isfd, (
void *)fh->recwrk, ISEQUAL)) {
4240 restorefileposition (f);
4244 if (fh->key[k].k_flags & ISDUPS) {
4248 isstart (fh->isfd, &fh->key[k], fh->key[k].k_leng,
4249 (
void *)fh->recwrk, ISEQUAL);
4250 if (!
isread (fh->isfd, (
void *)fh->recwrk, ISEQUAL) &&
4258 isstart (fh->isfd, &fh->key[0], 0, (
void *)fh->recwrk,
4260 if (
isread (fh->isfd, (
void *)fh->recwrk, ISEQUAL | ISLOCK)) {
4273 restorefileposition (f);
4275 #ifdef COB_WITH_STATUS_02
4276 if(!ret && (isstat1 ==
'0') && (isstat2 ==
'2')) {
4285 if (
isread (fh->isfd, (
void *)fh->recwrk, ISEQUAL | ISLOCK)) {
4302 #ifdef COB_WITH_STATUS_02
4303 if((isstat1 ==
'0') && (isstat2 ==
'2')) {
4310 #elif defined(WITH_DB)
4312 struct indexed_file *p;
4321 flags = DB_WRITECURSOR;
4325 p->db[0]->cursor (p->db[0],
NULL, &p->cursor[0], flags);
4326 p->write_cursor_open = 1;
4327 if (bdb_env !=
NULL) {
4332 if (check_alt_keys (f, 1)) {
4333 p->cursor[0]->c_close (p->cursor[0]);
4334 p->cursor[0] =
NULL;
4335 p->write_cursor_open = 0;
4340 ret = indexed_delete_internal (f, 1);
4343 p->cursor[0]->c_close (p->cursor[0]);
4344 p->cursor[0] =
NULL;
4345 p->write_cursor_open = 0;
4351 ret = indexed_write_internal (f, 1, opt);
4353 p->cursor[0]->c_close (p->cursor[0]);
4354 p->cursor[0] =
NULL;
4355 p->write_cursor_open = 0;
4369 struct indexed_file *p;
4370 #elif defined(WITH_ANY_ISAM)
4371 struct indexfile *fh;
4374 #ifndef WITH_SEQRA_EXTFH
4390 #ifndef WITH_SEQRA_EXTFH
4397 memset ((
void *)&lock, 0,
sizeof (
struct flock));
4398 lock.l_type = F_UNLCK;
4399 lock.l_whence = SEEK_SET;
4403 fcntl (f->
fd, F_SETLK, &lock);
4410 #ifdef WITH_INDEX_EXTFH
4411 extfh_indexed_unlock (f);
4412 #elif defined(WITH_DB)
4414 if (bdb_env !=
NULL && p) {
4416 bdb_env->lock_put (bdb_env, &p->bdb_file_lock);
4418 #elif defined(WITH_ANY_ISAM)
4469 f->
fd = fileno (stdin);
4480 f->
fd = fileno (stdout);
4521 for (l = file_cache; l; l = l->
next) {
4523 if (l == file_cache) {
4524 file_cache = l->
next;
4613 if (size < 1 || size > (
int)key->
size) {
4618 tempkey.
size = (size_t)size;
4663 (read_opts & COB_READ_PREVIOUS))) {
4742 if (read_opts & COB_READ_PREVIOUS) {
4755 const unsigned int check_eop)
4855 for (l = file_cache; l; l = l->
next) {
4867 for (l = file_cache; l; l = l->
next) {
4908 #ifdef WITH_SEQRA_EXTFH
4915 #ifdef WITH_INDEX_EXTFH
4944 for (i = (
int) f->
size - 1; i >= 0; --i) {
4945 if (f->
data[i] !=
' ' && f->
data[i] != 0) {
4954 for (n = 0; n < i; ++n) {
4955 if (f->
data[n] ==
'"') {
4958 s[j++] = f->
data[n];
4960 if (f->
data[n] ==
'"') {
4961 quote_switch = !quote_switch;
4969 if (s[j] ==
' ' || s[j] == 0) {
4981 unsigned char *file_handle,
const int file_flags)
4990 memset (file_handle, -1, (
size_t)4);
4994 switch (*file_access & 0x3F) {
4999 flag |= O_CREAT | O_TRUNC | O_WRONLY;
5006 fprintf (stderr,
_(
"WARNING - Call to CBL_OPEN_FILE with wrong access mode: %d"), *file_access & 0x3F);
5007 putc (
'\n', stderr);
5010 memset (file_handle, -1, (
size_t)4);
5017 memset (file_handle, -1, (
size_t)4);
5021 memcpy (file_handle, &fd, (
size_t)4);
5027 unsigned char *file_lock,
unsigned char *file_dev,
5028 unsigned char *file_handle)
5035 return open_cbl_file (file_name, file_access, file_handle, 0);
5040 unsigned char *file_lock,
unsigned char *file_dev,
5041 unsigned char *file_handle)
5050 fprintf (stderr,
_(
"WARNING - Call to CBL_CREATE_FILE with wrong file_lock: %d"), *file_lock);
5051 putc (
'\n', stderr);
5055 fprintf (stderr,
_(
"WARNING - Call to CBL_CREATE_FILE with wrong file_dev: %d"), *file_dev);
5056 putc (
'\n', stderr);
5062 return open_cbl_file (file_name, file_access, file_handle, O_CREAT | O_TRUNC);
5067 unsigned char *file_len,
unsigned char *flags,
5079 memcpy (&fd, file_handle, (
size_t)4);
5080 memcpy (&off, file_offset, (
size_t)8);
5081 memcpy (&len, file_len, (
size_t)4);
5082 #ifndef WORDS_BIGENDIAN
5086 if (lseek (fd, (off_t)off, SEEK_SET) == (off_t)-1) {
5090 rc = read (fd, buf, (
size_t)len);
5093 }
else if (rc == 0) {
5099 if ((*flags & 0x80) != 0) {
5100 if (fstat (fd, &st) < 0) {
5104 #ifndef WORDS_BIGENDIAN
5107 memcpy (file_offset, &off, (
size_t)8);
5114 unsigned char *file_len,
unsigned char *flags,
5126 memcpy (&fd, file_handle, (
size_t)4);
5127 memcpy (&off, file_offset, (
size_t)8);
5128 memcpy (&len, file_len, (
size_t)4);
5129 #ifndef WORDS_BIGENDIAN
5133 if (lseek (fd, (off_t)off, SEEK_SET) == (off_t)-1) {
5136 rc = write (fd, buf, (
size_t)len);
5150 memcpy (&fd, file_handle, (
size_t)4);
5209 fd1 = open (fn1, flag, 0);
5217 flag |= O_CREAT | O_TRUNC | O_WRONLY;
5246 short d, m, hh, mm, ss;
5259 cob_runtime_error (
_(
"'%s' - File detail area is too short"),
"CBL_CHECK_FILE_EXIST");
5264 if (stat (fn, &st) < 0) {
5270 tm = localtime (&st.st_mtime);
5271 d = (short)tm->tm_mday;
5272 m = (
short)(tm->tm_mon + 1);
5273 y = (short)(tm->tm_year + 1900);
5274 hh = (short)tm->tm_hour;
5275 mm = (
short)tm->tm_min;
5277 if (tm->tm_sec >= 60) {
5280 ss = (short)tm->tm_sec;
5283 #ifndef WORDS_BIGENDIAN
5287 memcpy (file_info, &sz, (
size_t)8);
5288 file_info[8] = (
unsigned char)d;
5289 file_info[9] = (
unsigned char)m;
5290 memcpy (file_info+10, &y, (
size_t)2);
5291 file_info[12] = (
unsigned char)hh;
5292 file_info[13] = (
unsigned char)mm;
5293 file_info[14] = (
unsigned char)ss;
5318 ret = rename (fn1, fn2);
5337 if (dir_length < 1) {
5343 memset (dir,
' ', (
size_t)dir_length);
5344 dirname = getcwd (
NULL, (
size_t)0);
5345 if (dirname ==
NULL) {
5348 dir_size = (int) strlen (dirname);
5350 if (strchr (dirname,
' ')) {
5353 if (dir_size + has_space > dir_length) {
5359 memcpy (&dir[1], dirname, (
size_t)dir_size);
5360 dir[dir_size + 1] =
'"';
5362 memcpy (dir, dirname, (
size_t)dir_size);
5385 ret = mkdir (fn, 0770);
5471 unsigned char *file_type)
5498 short d, m, hh, mm, ss;
5518 if (stat (fn, &st) < 0) {
5524 tm = localtime (&st.st_mtime);
5525 d = (short)tm->tm_mday;
5526 m = (
short)(tm->tm_mon + 1);
5527 y = (short)(tm->tm_year + 1900);
5528 hh = (short)tm->tm_hour;
5529 mm = (
short)tm->tm_min;
5531 if (tm->tm_sec >= 60) {
5534 ss = (short)tm->tm_sec;
5537 #ifndef WORDS_BIGENDIAN
5540 memcpy (file_info, &sz, (
size_t)8);
5541 dt = (y * 10000) + (m * 100) + d;
5542 #ifndef WORDS_BIGENDIAN
5545 memcpy (file_info + 8, &dt, (
size_t)4);
5546 dt = (hh * 1000000) + (mm * 10000) + (ss * 100);
5547 #ifndef WORDS_BIGENDIAN
5550 memcpy (file_info + 12, &dt, (
size_t)4);
5578 sort_cmps (
const unsigned char *s1,
const unsigned char *s2,
const size_t size,
5579 const unsigned char *col)
5585 for (i = 0; i < size; ++i) {
5586 if ((ret = col[s1[i]] - col[s2[i]]) != 0) {
5591 for (i = 0; i < size; ++i) {
5592 if ((ret = s1[i] - s2[i]) != 0) {
5605 size =
sizeof(size_t);
5623 for (i = 0; i < f->
nkeys; ++i) {
5710 fd = open (filename,
5711 _O_CREAT | _O_TRUNC | _O_RDWR | _O_BINARY | _O_TEMPORARY,
5712 _S_IREAD | _S_IWRITE);
5720 (void)unlink (filename);
5721 fp = fdopen (fd,
"w+b");
5757 destination = source ^ 2;
5763 end_of_block[0] = hp->
queue[source].
count == 0;
5764 end_of_block[1] = hp->
queue[source + 1].
count == 0;
5765 if (end_of_block[0] && end_of_block[1]) {
5768 while (!end_of_block[0] || !end_of_block[1]) {
5769 if (end_of_block[0]) {
5771 }
else if (end_of_block[1]) {
5778 move = n < 0 ? 0 : 1;
5782 end_of_block[move] = 1;
5799 source = destination & 2;
5810 if (getc (fp) != 0) {
5851 unsigned char *toptr;
5852 unsigned char *fromptr;
5861 memcpy (toptr, fromptr, fromsize);
5862 memset (toptr + fromsize,
' ', tosize - fromsize);
5864 memcpy (toptr, fromptr, tosize);
5892 for (i = 0; i < 4; ++i) {
5907 destination = source ^ 2;
5932 move = res < 0 ? 0 : 1;
5937 hp->
file[destination].
fp) != 1)) {
5952 source = destination & 2;
6054 move = res < 0 ? 0 : 1;
6105 va_start (args, varcnt);
6106 for (i = 0; i < varcnt; ++i) {
6107 fbase[i] = va_arg (args,
cob_file *);
6110 for (i = 0; i < varcnt; ++i) {
6120 hp = sort_file->
file;
6127 for (i = 0; i < varcnt; ++i) {
6139 for (i = 0; i < varcnt; ++i) {
6147 const unsigned char *collating_sequence,
6158 n =
sizeof (
struct cobitem) - offsetof (struct cobitem, item);
6173 *(
int *)sort_return = 0;
6182 if (collating_sequence) {
6192 const unsigned int offset)
6212 for (i = 0; i < 4; ++i) {
6287 for (l = file_cache; l; l = l->
next) {
6299 fprintf (stderr,
_(
"WARNING - Implicit CLOSE of %s ('%s')"),
6301 putc (
'\n', stderr);
6308 bdb_env->lock_id_free (bdb_env, bdb_lock_id);
6309 bdb_env->close (bdb_env, 0);
6312 if (record_lock_object) {
6314 record_lock_object =
NULL;
6321 #elif defined(WITH_ANY_ISAM)
6327 #if defined(WITH_INDEX_EXTFH) || defined(WITH_SEQRA_EXTFH)
6328 extfh_cob_exit_fileio ();
6336 for (l = file_cache; l;) {
6369 bdb_data_dir =
NULL;
6370 join_environment ();
6371 record_lock_object =
cob_malloc ((
size_t)1024);
6376 #if defined(WITH_INDEX_EXTFH) || defined(WITH_SEQRA_EXTFH)
6377 extfh_cob_init_fileio (&sequential_funcs, &lineseq_funcs,
static unsigned int eop_status
void cob_file_sort_close(cob_file *f)
#define COB_STATUS_42_NOT_OPEN
void cob_free(void *mptr)
#define COB_STATUS_10_END_OF_FILE
void cob_delete_file(cob_file *f, cob_field *fnstatus)
int cob_sys_file_delete(unsigned char *file_name, unsigned char *file_type)
static int indexed_read_next(cob_file *, const int)
#define COB_STATUS_41_ALREADY_OPEN
#define COB_FERROR_CODEGEN
struct sort_mem_struct * next
unsigned int cob_varseq_type
static int relative_read(cob_file *, cob_field *, const int)
struct file_struct file[4]
static int cob_sort_queues(struct cobsort *hp)
cob_file * cob_error_file
static int sort_cmps(const unsigned char *s1, const unsigned char *s2, const size_t size, const unsigned char *col)
struct sort_mem_struct * mem_base
static cob_settings * cobsetptr
int cob_add_int(cob_field *, const int, const int)
int cob_sys_check_file_exist(unsigned char *file_name, unsigned char *file_info)
unsigned char organization
void cob_write(cob_file *f, cob_field *rec, const int opt, cob_field *fnstatus, const unsigned int check_eop)
int isrewrite(const int ihandle, char *pcrow)
static int cob_get_sort_tempfile(struct cobsort *hp, const int n)
static struct file_list * file_cache
int isindexinfo(const int ihandle, void *pskeydesc, const int ikeynumber)
#define COB_FILE_SPECIAL(x)
#define COB_STATUS_14_OUT_OF_KEY_RANGE
#define COB_FIELD_IS_NUMERIC(f)
static void cob_chk_file_mapping(void)
#define COB_STATUS_23_KEY_NOT_EXISTS
void cob_file_sort_init(cob_file *f, const unsigned int nkeys, const unsigned char *collating_sequence, void *sort_return, cob_field *fnstatus)
int cob_sys_close_file(unsigned char *file_handle)
#define COB_LOCK_AUTOMATIC
unsigned int cob_display_warn
static int sequential_write(cob_file *, const int)
int cob_sys_rename_file(unsigned char *fname1, unsigned char *fname2)
int cob_sys_chdir(unsigned char *dir, unsigned char *status)
int isfullclose(const int ihandle)
#define COB_CHK_PARMS(x, z)
#define COB_STATUS_61_FILE_SHARING
#define COB_STATUS_00_SUCCESS
static int cob_read_item(struct cobsort *hp, const int n)
static int cob_file_close(cob_file *, const int)
static const struct cob_fileio_funcs lineseq_funcs
#define COB_MAYSWAP_16(x)
static int cob_write_block(struct cobsort *hp, const int n)
int(* rewrite)(cob_file *, const int)
#define COB_STATUS_35_NOT_EXISTS
int cob_sys_write_file(unsigned char *file_handle, unsigned char *file_offset, unsigned char *file_len, unsigned char *flags, unsigned char *buf)
int(* read)(cob_file *, cob_field *, const int)
void cob_file_sort_init_key(cob_file *f, cob_field *field, const int flag, const unsigned int offset)
void cob_file_sort_using(cob_file *sort_file, cob_file *data_file)
int cob_sys_mkdir(unsigned char *dir)
void cob_exit_fileio(void)
static unsigned int cob_seq_write_opt(cob_file *f, const int opt)
static int indexed_write(cob_file *, const int)
static int open_cbl_file(unsigned char *file_name, unsigned char *file_access, unsigned char *file_handle, const int file_flags)
#define COB_MAYSWAP_32(x)
static int indexed_start(cob_file *, const int, cob_field *)
static void * cob_str_from_fld(const cob_field *f)
static COB_INLINE void unique_copy(unsigned char *s1, const unsigned char *s2)
static int relative_start(cob_file *, const int, cob_field *)
static const struct cob_fileio_funcs relative_funcs
static int relative_delete(cob_file *)
static int cob_file_sort_retrieve(cob_file *f, unsigned char *p)
static int sequential_rewrite(cob_file *, const int)
static int dummy_read(cob_file *, cob_field *, const int)
#define COB_FILE_EXCLUSIVE
int iserase(char *pcfilename)
void cob_read_next(cob_file *f, cob_field *fnstatus, const int read_opts)
#define COB_READ_PREVIOUS
unsigned char unique[sizeof(size_t)]
unsigned char flag_operation
#define COB_STATUS_05_SUCCESS_OPTIONAL
#define COB_SELECT_LINAGE
static char * file_open_name
#define COB_BSWAP_32(val)
#define COB_STATUS_44_RECORD_OVERFLOW
static FILE * cob_srttmpfile(void)
#define COB_BSWAP_16(val)
unsigned char flag_optional
void cob_unlock_file(cob_file *f, cob_field *fnstatus)
void cob_file_return(cob_file *f)
#define COB_STATUS_07_SUCCESS_NO_UNIT
unsigned char * file_status
#define COB_STATUS_39_CONFLICT_ATTRIBUTE
static void cob_free_list(struct cobsort *hp)
static const struct cob_fileio_funcs sequential_funcs
static struct cobitem * cob_new_item(struct cobsort *hp, const size_t size)
int isstart(const int ihandle, struct keydesc *pskeydesc, int ilength, char *pcrow, int imode)
unsigned int cob_ls_nulls
#define COB_STATUS_22_KEY_EXISTS
static int indexed_rewrite(cob_file *, const int)
int cob_get_int(cob_field *)
int iswrite(const int ihandle, char *pcrow)
void cob_field_to_string(const cob_field *, void *, const size_t)
static char * runtime_buffer
#define COB_READ_WAIT_LOCK
static int cob_file_sort_compare(struct cobitem *k1, struct cobitem *k2, void *pointer)
void cob_fatal_error(const int fatal_error)
void cob_runtime_error(const char *,...) COB_A_FORMAT12
int cob_numeric_cmp(cob_field *, cob_field *)
#define COB_STATUS_46_READ_ERROR
static int indexed_open(cob_file *, char *, const int, const int)
static cob_global * cobglobptr
static const int status_exception[]
int cob_sys_open_file(unsigned char *file_name, unsigned char *file_access, unsigned char *file_lock, unsigned char *file_dev, unsigned char *file_handle)
#define COB_FILE_STDOUT(x)
#define COB_STATUS_04_SUCCESS_INCOMPLETE
static int dummy_start(cob_file *, const int, cob_field *)
#define COB_STATUS_24_KEY_BOUNDARY
static int cob_file_open(cob_file *, char *, const int, const int)
static int cob_file_sort_process(struct cobsort *hp)
int isopen(const char *pcfilename, int imode)
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
static size_t cob_vsq_len
#define COB_CLOSE_NO_REWIND
static int indexed_read(cob_file *, cob_field *, const int)
int cob_sys_flush_file(unsigned char *file_handle)
#define COB_ORG_SEQUENTIAL
static const char *const prefix[]
#define COB_STATUS_48_OUTPUT_DENIED
void cob_start(cob_file *f, const int cond, cob_field *key, cob_field *keysize, cob_field *fnstatus)
#define COB_STATUS_30_PERMANENT_ERROR
static int relative_read_next(cob_file *, const int)
static void save_status(cob_file *f, cob_field *fnstatus, const int status)
unsigned char end_of_block
int cob_sys_change_dir(unsigned char *dir)
void cob_set_exception(const int id)
unsigned int cob_ls_fixed
void cob_open(cob_file *f, const int mode, const int sharing, cob_field *fnstatus)
static unsigned int check_eop_status
int isdelete(const int ihandle, char *pcrow)
static void indexed_file_delete(cob_file *f, const char *filename)
#define COB_FILE_STDIN(x)
struct queue_struct queue[4]
#define COB_STORE_KEEP_ON_OVERFLOW
unsigned char flag_first_read
int cob_sys_file_info(unsigned char *file_name, unsigned char *file_info)
unsigned char flag_read_done
int isrewcurr(const int ihandle, char *pcrow)
#define COB_ACCESS_SEQUENTIAL
static int indexed_delete(cob_file *)
void cob_set_int(cob_field *, const int)
#define offsetof(s_name, m_name)
#define COB_READ_IGNORE_LOCK
unsigned int cob_ls_uses_cr
static char * file_open_buff
int(* close)(cob_file *, const int)
#define COB_STATUS_21_KEY_INVALID
static int dummy_rnxt_rewrite(cob_file *, const int)
#define COB_STATUS_38_CLOSED_WITH_LOCK
#define COB_STATUS_43_READ_NOT_DONE
void cob_read(cob_file *f, cob_field *key, cob_field *fnstatus, const int read_opts)
int(* read_next)(cob_file *, const int)
static char * cob_chk_file_env(const char *src)
static int lineseq_write(cob_file *, const int)
#define COB_STATUS_49_I_O_DENIED
unsigned char flag_needs_top
int cob_sys_read_file(unsigned char *file_handle, unsigned char *file_offset, unsigned char *file_len, unsigned char *flags, unsigned char *buf)
int isaddindex(const int ihandle, struct keydesc *pskeydesc)
static void cob_cache_file(cob_file *f)
#define COB_STATUS_57_I_O_LINAGE
#define COB_STATUS_51_RECORD_LOCKED
static const struct cob_fileio_funcs * fileio_funcs[COB_ORG_MAX]
static int cob_file_sort_submit(cob_file *f, const unsigned char *p)
cob_field * variable_record
void cob_incr_temp_iteration(void)
int cob_sys_create_dir(unsigned char *dir)
void cob_close(cob_file *f, cob_field *fnstatus, const int opt, const int remfil)
unsigned char flag_select_features
static void cob_copy_check(cob_file *to, cob_file *from)
#define COB_LOCK_MULTIPLE
int(* start)(cob_file *, const int, cob_field *)
char * cob_strdup(const char *)
int cob_sys_get_current_dir(const int flags, const int dir_length, unsigned char *dir)
#define COB_STATUS_47_INPUT_DENIED
int cob_sys_create_file(unsigned char *file_name, unsigned char *file_access, unsigned char *file_lock, unsigned char *file_dev, unsigned char *file_handle)
#define COB_ACCESS_RANDOM
void * cob_malloc(const size_t size)
int isbuild(const char *pcfilename, const int imaxrowlength, struct keydesc *pskey, int imode)
const unsigned char * sort_collating
unsigned char last_open_mode
static int cob_file_write_opt(cob_file *, const int)
#define COB_ORG_LINE_SEQUENTIAL
#define COB_LOCK_OPEN_EXCLUSIVE
unsigned int cob_env_mangle
void cob_delete(cob_file *f, cob_field *fnstatus)
int cob_sys_copyfile(unsigned char *fname1, unsigned char *fname2, unsigned char *file_type)
#define COB_NOT_CONFIGURED
int(* write)(cob_file *, const int)
static size_t file_linage_check(cob_file *f)
int isflush(const int ihandle)
static char * file_open_env
void * cob_fast_malloc(const size_t size)
#define COB_STATUS_02_SUCCESS_DUPLICATE
static int relative_rewrite(cob_file *, const int)
static int dummy_delete(cob_file *)
unsigned char flag_begin_of_file
static int relative_write(cob_file *, const int)
static int sequential_read(cob_file *, const int)
int cob_sys_delete_dir(unsigned char *dir)
int isread(const int ihandle, char *pcrow, int imode)
void cob_file_release(cob_file *f)
static int cob_linage_write_opt(cob_file *f, const int opt)
unsigned char access_mode
void cob_file_sort_giving(cob_file *sort_file, const size_t varcnt,...)
unsigned char flag_nonexistent
unsigned char flag_end_of_file
int cob_sys_copy_file(unsigned char *fname1, unsigned char *fname2)
#define COB_STATUS_91_NOT_AVAILABLE
int isrelease(const int ihandle)
unsigned char flag_needs_nl
static const struct cob_fileio_funcs indexed_funcs
#define COB_STATUS_37_PERMISSION_DENIED
static void cob_sync(cob_file *f)
void cob_rewrite(cob_file *f, cob_field *rec, const int opt, cob_field *fnstatus)
static int indexed_close(cob_file *, const int)
#define COB_BSWAP_64(val)
int cob_sys_delete_file(unsigned char *file_name)
int(* open)(cob_file *, char *, const int, const int)
static void cob_file_unlock(cob_file *f)
void cob_init_fileio(cob_global *lptr, cob_settings *sptr)
static int cob_fd_file_open(cob_file *f, char *filename, const int mode, const int sharing)
void cob_temp_name(char *filename, const char *ext)
int(* fdelete)(cob_file *)
void cob_stop_run(const int status)
static int lineseq_read(cob_file *, const int)