|
OpenCOBOL 1.1pre-rel
|
#include <libcob/common.h>

Go to the source code of this file.
| int CBL_CHANGE_DIR | ( | unsigned char * | ) |
Definition at line 4857 of file fileio.c.
{
char *fn;
int ret;
COB_CHK_PARMS (CBL_CHANGE_DIR, 1);
if (!cob_current_module->cob_procedure_parameters[0]) {
return -1;
}
fn = cob_str_from_fld (cob_current_module->cob_procedure_parameters[0]);
ret = chdir (fn);
free (fn);
if (ret) {
return 128;
}
return 0;
}


| int CBL_CHECK_FILE_EXIST | ( | unsigned char * | , |
| unsigned char * | |||
| ) |
Definition at line 4722 of file fileio.c.
{
char *fn;
struct tm *tm;
long long sz;
struct stat st;
short y;
char d, m, hh, mm, ss;
COB_CHK_PARMS (CBL_CHECK_FILE_EXIST, 2);
if (!cob_current_module->cob_procedure_parameters[0]) {
return -1;
}
fn = cob_str_from_fld (cob_current_module->cob_procedure_parameters[0]);
if (stat (fn, &st) < 0) {
free (fn);
return 35;
}
free (fn);
sz = st.st_size;
tm = localtime (&st.st_mtime);
d = (char) tm->tm_mday;
m = (char) tm->tm_mon + 1;
y = tm->tm_year + 1900;
hh = (char) tm->tm_hour;
mm = (char) tm->tm_min;
ss = (char) tm->tm_sec;
#ifndef WORDS_BIGENDIAN
sz = COB_BSWAP_64 (sz);
y = COB_BSWAP_16 (y);
#endif
memcpy (file_info, &sz, 8);
file_info[8] = d;
file_info[9] = m;
memcpy (file_info+10, &y, 2);
file_info[12] = hh;
file_info[13] = mm;
file_info[14] = ss;
file_info[15] = 0;
return 0;
}


| int CBL_CLOSE_FILE | ( | unsigned char * | ) |
Definition at line 4631 of file fileio.c.
{
int fd;
COB_CHK_PARMS (CBL_CLOSE_FILE, 1);
memcpy (&fd, file_handle, 4);
return close (fd);
}


| int CBL_COPY_FILE | ( | unsigned char * | , |
| unsigned char * | |||
| ) |
Definition at line 4670 of file fileio.c.
{
char *fn1;
char *fn2;
#ifdef O_BINARY
int flag = O_BINARY;
#else
int flag = 0;
#endif
int ret;
int i;
int fd1, fd2;
COB_CHK_PARMS (CBL_COPY_FILE, 2);
if (!cob_current_module->cob_procedure_parameters[0]) {
return -1;
}
if (!cob_current_module->cob_procedure_parameters[1]) {
return -1;
}
fn1 = cob_str_from_fld (cob_current_module->cob_procedure_parameters[0]);
flag |= O_RDONLY;
fd1 = open (fn1, flag, 0);
if (fd1 < 0) {
free (fn1);
return -1;
}
free (fn1);
fn2 = cob_str_from_fld (cob_current_module->cob_procedure_parameters[1]);
flag &= ~O_RDONLY;
flag |= O_CREAT | O_TRUNC | O_WRONLY;
fd2 = open (fn2, flag, 0660);
if (fd2 < 0) {
close (fd1);
free (fn2);
return -1;
}
free (fn2);
ret = 0;
while ((i = read (fd1, fn1, sizeof(fn1))) > 0) {
if (write (fd2, fn1, (size_t)i) < 0) {
ret = -1;
break;
}
}
close (fd1);
close (fd2);
return ret;
}


| int CBL_CREATE_DIR | ( | unsigned char * | ) |
Definition at line 4833 of file fileio.c.
{
char *fn;
int ret;
COB_CHK_PARMS (CBL_CREATE_DIR, 1);
if (!cob_current_module->cob_procedure_parameters[0]) {
return -1;
}
fn = cob_str_from_fld (cob_current_module->cob_procedure_parameters[0]);
#ifdef _WIN32
ret = mkdir (fn);
#else
ret = mkdir (fn, 0770);
#endif
free (fn);
if (ret) {
return 128;
}
return 0;
}


| int CBL_CREATE_FILE | ( | unsigned char * | , |
| unsigned char * | , | ||
| unsigned char * | , | ||
| unsigned char * | , | ||
| unsigned char * | |||
| ) |
Definition at line 4548 of file fileio.c.
{
COB_CHK_PARMS (CBL_CREATE_FILE, 5);
return open_cbl_file (file_name, file_access, file_handle, O_CREAT | O_TRUNC);
}


| int CBL_DELETE_DIR | ( | unsigned char * | ) |
Definition at line 4877 of file fileio.c.
{
char *fn;
int ret;
COB_CHK_PARMS (CBL_DELETE_DIR, 1);
if (!cob_current_module->cob_procedure_parameters[0]) {
return -1;
}
fn = cob_str_from_fld (cob_current_module->cob_procedure_parameters[0]);
ret = rmdir (fn);
free (fn);
if (ret) {
return 128;
}
return 0;
}


| int CBL_DELETE_FILE | ( | unsigned char * | ) |
Definition at line 4650 of file fileio.c.
{
char *fn;
int ret;
COB_CHK_PARMS (CBL_DELETE_FILE, 1);
if (!cob_current_module->cob_procedure_parameters[0]) {
return -1;
}
fn = cob_str_from_fld (cob_current_module->cob_procedure_parameters[0]);
ret = unlink (fn);
free (fn);
if (ret) {
return 128;
}
return 0;
}


| int CBL_FLUSH_FILE | ( | unsigned char * | ) |
Definition at line 4642 of file fileio.c.
{
COB_CHK_PARMS (CBL_FLUSH_FILE, 1);
return 0;
}


| int CBL_GET_CURRENT_DIR | ( | const int | , |
| const int | , | ||
| unsigned char * | |||
| ) |
Definition at line 4793 of file fileio.c.
{
char *dirname;
int dir_size;
int has_space;
COB_CHK_PARMS (CBL_GET_CURRENT_DIR, 3);
if (dir_length < 1) {
return 128;
}
if (flags) {
return 129;
}
memset (dir, ' ', (size_t)dir_length);
dirname = getcwd (NULL, 0);
if (dirname == NULL) {
return 128;
}
dir_size = (int) strlen (dirname);
has_space = 0;
if (strchr (dirname, ' ')) {
has_space = 2;
}
if (dir_size + has_space > dir_length) {
free (dirname);
return 128;
}
if (has_space) {
*dir = '"';
memcpy (&dir[1], dirname, (size_t)dir_size);
dir[dir_size + 1] = '"';
} else {
memcpy (dir, dirname, (size_t)dir_size);
}
free (dirname);
return 0;
}


| int CBL_OPEN_FILE | ( | unsigned char * | , |
| unsigned char * | , | ||
| unsigned char * | , | ||
| unsigned char * | , | ||
| unsigned char * | |||
| ) |
Definition at line 4538 of file fileio.c.
{
COB_CHK_PARMS (CBL_OPEN_FILE, 5);
return open_cbl_file (file_name, file_access, file_handle, 0);
}


| int CBL_READ_FILE | ( | unsigned char * | , |
| unsigned char * | , | ||
| unsigned char * | , | ||
| unsigned char * | , | ||
| unsigned char * | |||
| ) |
Definition at line 4558 of file fileio.c.
{
long long off;
int fd;
int len;
int rc = 0;
struct stat st;
COB_CHK_PARMS (CBL_READ_FILE, 5);
memcpy (&fd, file_handle, 4);
memcpy (&off, file_offset, 8);
memcpy (&len, file_len, 4);
#ifndef WORDS_BIGENDIAN
off = COB_BSWAP_64 (off);
len = COB_BSWAP_32 (len);
#endif
if (lseek (fd, (off_t)off, SEEK_SET) < 0) {
return -1;
}
if (len > 0) {
rc = read (fd, buf, (size_t)len);
if (rc < 0) {
rc = -1;
} else if (rc == 0) {
rc = 10;
} else {
rc = 0;
}
}
if ((*flags & 0x80) != 0) {
if (fstat (fd, &st) < 0) {
return -1;
}
off = st.st_size;
#ifndef WORDS_BIGENDIAN
off = COB_BSWAP_64 (off);
#endif
memcpy (file_offset, &off, 8);
}
return rc;
}


| int CBL_RENAME_FILE | ( | unsigned char * | , |
| unsigned char * | |||
| ) |
Definition at line 4767 of file fileio.c.
{
char *fn1;
char *fn2;
int ret;
COB_CHK_PARMS (CBL_RENAME_FILE, 2);
if (!cob_current_module->cob_procedure_parameters[0]) {
return -1;
}
if (!cob_current_module->cob_procedure_parameters[1]) {
return -1;
}
fn1 = cob_str_from_fld (cob_current_module->cob_procedure_parameters[0]);
fn2 = cob_str_from_fld (cob_current_module->cob_procedure_parameters[1]);
ret = rename (fn1, fn2);
free (fn1);
free (fn2);
if (ret) {
return 128;
}
return 0;
}


| int CBL_WRITE_FILE | ( | unsigned char * | , |
| unsigned char * | , | ||
| unsigned char * | , | ||
| unsigned char * | , | ||
| unsigned char * | |||
| ) |
Definition at line 4603 of file fileio.c.
{
long long off;
int fd;
int len;
int rc;
COB_CHK_PARMS (CBL_WRITE_FILE, 5);
memcpy (&fd, file_handle, 4);
memcpy (&off, file_offset, 8);
memcpy (&len, file_len, 4);
#ifndef WORDS_BIGENDIAN
off = COB_BSWAP_64 (off);
len = COB_BSWAP_32 (len);
#endif
if (lseek (fd, (off_t)off, SEEK_SET) < 0) {
return -1;
}
rc = write (fd, buf, (size_t)len);
if (rc < 0) {
return 30;
}
return 0;
}


| int cob_acuw_chdir | ( | unsigned char * | , |
| unsigned char * | |||
| ) |
Definition at line 4911 of file fileio.c.
{
int ret;
COB_CHK_PARMS (C$CHDIR, 2);
ret = CBL_CHANGE_DIR (dir);
if (ret < 0) {
ret = 128;
}
cob_set_int (cob_current_module->cob_procedure_parameters[1], ret);
return ret;
}

| int cob_acuw_copyfile | ( | unsigned char * | , |
| unsigned char * | , | ||
| unsigned char * | |||
| ) |
Definition at line 4926 of file fileio.c.
{
int ret = 128;
/* RXW - Type is not yet evaluated */
COB_CHK_PARMS (C$COPY, 3);
if (cob_call_params < 3) {
return 128;
}
ret = CBL_COPY_FILE (fname1, fname2);
if (ret < 0) {
ret = 128;
}
return ret;
}

| int cob_acuw_file_delete | ( | unsigned char * | , |
| unsigned char * | |||
| ) |
Definition at line 4993 of file fileio.c.
{
int ret;
/* RXW - Type is not yet evaluated */
COB_CHK_PARMS (C$DELETE, 2);
if (cob_call_params < 2 || !cob_current_module->cob_procedure_parameters[0]) {
return 128;
}
ret = CBL_DELETE_FILE (file_name);
if (ret < 0) {
ret = 128;
}
return ret;
}

| int cob_acuw_file_info | ( | unsigned char * | , |
| unsigned char * | |||
| ) |
Definition at line 4945 of file fileio.c.
{
char *fn;
struct tm *tm;
unsigned long long sz;
unsigned int dt;
short y;
short d, m, hh, mm, ss;
struct stat st;
COB_CHK_PARMS (C$FILEINFO, 2);
if (cob_call_params < 2 || !cob_current_module->cob_procedure_parameters[0]) {
return 128;
}
fn = cob_str_from_fld (cob_current_module->cob_procedure_parameters[0]);
if (stat (fn, &st) < 0) {
free (fn);
return 35;
}
free (fn);
sz = st.st_size;
tm = localtime (&st.st_mtime);
d = tm->tm_mday;
m = tm->tm_mon + 1;
y = tm->tm_year + 1900;
hh = tm->tm_hour;
mm = tm->tm_min;
ss = tm->tm_sec;
#ifndef WORDS_BIGENDIAN
sz = COB_BSWAP_64 (sz);
#endif
memcpy (file_info, &sz, 8);
dt = (y * 10000) + (m * 100) + d;
#ifndef WORDS_BIGENDIAN
dt = COB_BSWAP_32 (dt);
#endif
memcpy (file_info + 8, &dt, 4);
dt = (hh * 1000000) + (mm * 10000) + (ss * 100);
#ifndef WORDS_BIGENDIAN
dt = COB_BSWAP_32 (dt);
#endif
memcpy (file_info + 12, &dt, 4);
return 0;
}
| int cob_acuw_mkdir | ( | unsigned char * | ) |
Definition at line 4897 of file fileio.c.
{
int ret;
COB_CHK_PARMS (C$MAKEDIR, 1);
ret = CBL_CREATE_DIR (dir);
if (ret < 0) {
ret = 128;
}
return ret;
}

Definition at line 3987 of file fileio.c.
{
int ret;
f->flag_read_done = 0;
if (f->special) {
f->open_mode = COB_OPEN_CLOSED;
RETURN_STATUS (COB_STATUS_00_SUCCESS);
}
if (f->open_mode == COB_OPEN_CLOSED) {
RETURN_STATUS (COB_STATUS_42_NOT_OPEN);
}
if (f->flag_nonexistent) {
ret = COB_STATUS_00_SUCCESS;
} else {
#ifdef WITH_SEQRA_EXTFH
if (f->organization != COB_ORG_INDEXED) {
ret = extfh_cob_file_close (f, opt);
} else {
#endif
ret = fileio_funcs[(int)f->organization]->close (f, opt);
#ifdef WITH_SEQRA_EXTFH
}
#endif
}
if (ret == COB_STATUS_00_SUCCESS) {
switch (opt) {
case COB_CLOSE_LOCK:
f->open_mode = COB_OPEN_LOCKED;
break;
default:
f->open_mode = COB_OPEN_CLOSED;
break;
}
}
RETURN_STATUS (ret);
}

| void cob_commit | ( | void | ) |
| void cob_default_error_handle | ( | void | ) |
Definition at line 4293 of file fileio.c.
{
const char *msg;
unsigned char *file_status;
char *filename;
int status;
file_status = cob_error_file->file_status;
status = cob_d2i(file_status[0]) * 10 + cob_d2i(file_status[1]);
switch (status) {
case COB_STATUS_10_END_OF_FILE:
msg = "End of file";
break;
case COB_STATUS_14_OUT_OF_KEY_RANGE:
msg = "Key out of range";
break;
case COB_STATUS_21_KEY_INVALID:
msg = "Key order not ascending";
break;
case COB_STATUS_22_KEY_EXISTS:
msg = "Record key already exists";
break;
case COB_STATUS_23_KEY_NOT_EXISTS:
msg = "Record key does not exist";
break;
case COB_STATUS_30_PERMANENT_ERROR:
msg = "Permanent file error";
break;
case COB_STATUS_35_NOT_EXISTS:
msg = "File does not exist";
break;
case COB_STATUS_37_PERMISSION_DENIED:
msg = "Permission denied";
break;
case COB_STATUS_41_ALREADY_OPEN:
msg = "File already open";
break;
case COB_STATUS_42_NOT_OPEN:
msg = "File not open";
break;
case COB_STATUS_43_READ_NOT_DONE:
msg = "READ must be executed first";
break;
case COB_STATUS_44_RECORD_OVERFLOW:
msg = "Record overflow";
break;
case COB_STATUS_46_READ_ERROR:
msg = "Failed to read";
break;
case COB_STATUS_47_INPUT_DENIED:
msg = "READ/START not allowed";
break;
case COB_STATUS_48_OUTPUT_DENIED:
msg = "WRITE not allowed";
break;
case COB_STATUS_49_I_O_DENIED:
msg = "DELETE/REWRITE not allowed";
break;
case COB_STATUS_51_RECORD_LOCKED:
msg = "Record locked by another file connector";
break;
case COB_STATUS_52_EOP:
msg = "A page overflow condition occurred";
break;
case COB_STATUS_57_I_O_LINAGE:
msg = "LINAGE values invalid";
break;
case COB_STATUS_61_FILE_SHARING:
msg = "File sharing conflict";
break;
case COB_STATUS_91_NOT_AVAILABLE:
msg = "Runtime library is not configured for this operation";
break;
default:
msg = "Unknown file error";
break;
}
filename = cob_malloc (COB_MEDIUM_BUFF);
cob_field_to_string (cob_error_file->assign, filename);
cob_runtime_error ("%s (STATUS = %02d) File : '%s'", msg,
status, filename);
free (filename);
}

Definition at line 4247 of file fileio.c.
{
int ret;
int read_done = f->flag_read_done;
f->flag_read_done = 0;
if (unlikely(f->open_mode == COB_OPEN_CLOSED ||
f->open_mode != COB_OPEN_I_O)) {
RETURN_STATUS (COB_STATUS_49_I_O_DENIED);
}
if (f->access_mode == COB_ACCESS_SEQUENTIAL && !read_done) {
RETURN_STATUS (COB_STATUS_43_READ_NOT_DONE);
}
ret = fileio_funcs[(int)f->organization]->fdelete (f);
if (unlikely(cob_do_sync && ret == 0)) {
cob_sync (f, cob_do_sync);
}
RETURN_STATUS (ret);
}
| void cob_file_release | ( | cob_file * | ) |
Definition at line 5654 of file fileio.c.
{
struct cobsort *hp;
cob_field *fnstatus = NULL;
int ret;
hp = f->file;
if (likely(hp)) {
fnstatus = hp->fnstatus;
}
ret = cob_file_sort_submit (f, f->record->data);
switch (ret) {
case 0:
RETURN_STATUS (COB_STATUS_00_SUCCESS);
break;
default:
if (likely(hp)) {
*(int *)(hp->sort_return) = 16;
}
RETURN_STATUS (COB_STATUS_30_PERMANENT_ERROR);
break;
}
}
| void cob_file_return | ( | cob_file * | ) |
Definition at line 5679 of file fileio.c.
{
struct cobsort *hp;
cob_field *fnstatus = NULL;
int ret;
hp = f->file;
if (likely(hp)) {
fnstatus = hp->fnstatus;
}
ret = cob_file_sort_retrieve (f, f->record->data);
switch (ret) {
case 0:
RETURN_STATUS (COB_STATUS_00_SUCCESS);
break;
case COBSORTEND:
RETURN_STATUS (COB_STATUS_10_END_OF_FILE);
break;
default:
if (likely(hp)) {
*(int *)(hp->sort_return) = 16;
}
RETURN_STATUS (COB_STATUS_30_PERMANENT_ERROR);
break;
}
}
| void cob_file_sort_close | ( | cob_file * | ) |
Definition at line 5631 of file fileio.c.
{
struct cobsort *hp;
cob_field *fnstatus = NULL;
size_t i;
hp = f->file;
if (likely(hp)) {
fnstatus = hp->fnstatus;
cob_free_list (hp->empty);
for (i = 0; i < 4; i++) {
cob_free_list (hp->queue[i].first);
if (hp->file[i].fp != NULL) {
fclose (hp->file[i].fp);
}
}
free (hp);
}
f->file = NULL;
RETURN_STATUS (COB_STATUS_00_SUCCESS);
}
| void cob_file_sort_giving | ( | cob_file * | , |
| const size_t | , | ||
| ... | |||
| ) |
Definition at line 5544 of file fileio.c.
{
cob_file **fbase;
struct cobsort *hp;
size_t i;
int ret;
int opt;
va_list args;
fbase = cob_malloc (varcnt * sizeof(cob_file *));
va_start (args, varcnt);
for (i = 0; i < varcnt; i++) {
fbase[i] = va_arg (args, cob_file *);
}
va_end (args);
for (i = 0; i < varcnt; i++) {
cob_open (fbase[i], COB_OPEN_OUTPUT, 0, NULL);
}
while (1) {
ret = cob_file_sort_retrieve (sort_file, sort_file->record->data);
if (ret) {
if (ret == COBSORTEND) {
sort_file->file_status[0] = '1';
sort_file->file_status[1] = '0';
} else {
hp = sort_file->file;
*(int *)(hp->sort_return) = 16;
sort_file->file_status[0] = '3';
sort_file->file_status[1] = '0';
}
break;
}
for (i = 0; i < varcnt; i++) {
if (fbase[i]->special ||
fbase[i]->organization == COB_ORG_LINE_SEQUENTIAL) {
opt = COB_WRITE_BEFORE | COB_WRITE_LINES | 1;
} else {
opt = 0;
}
cob_copy_check (fbase[i], sort_file);
cob_write (fbase[i], fbase[i]->record, opt, NULL);
}
}
for (i = 0; i < varcnt; i++) {
cob_close (fbase[i], COB_CLOSE_NORMAL, NULL);
}
free (fbase);
}

Definition at line 5594 of file fileio.c.
{
struct cobsort *p;
p = cob_malloc (sizeof (struct cobsort));
p->fnstatus = fnstatus;
p->size = f->record_max;
p->r_size = f->record_max + sizeof(size_t);
p->w_size = f->record_max + sizeof(size_t) + 1;
p->pointer = f;
p->sort_return = sort_return;
*(int *)sort_return = 0;
p->memory = (size_t)cob_sort_memory / (p->size + sizeof(struct cobitem));
f->file = p;
f->keys = cob_malloc (sizeof (struct cob_file_key) * nkeys);
f->nkeys = 0;
if (collating_sequence) {
f->sort_collating = collating_sequence;
} else {
f->sort_collating = cob_current_module->collating_sequence;
}
RETURN_STATUS (COB_STATUS_00_SUCCESS);
}

Definition at line 5524 of file fileio.c.
{
int ret;
cob_open (data_file, COB_OPEN_INPUT, 0, NULL);
while (1) {
cob_read (data_file, NULL, NULL, COB_READ_NEXT);
if (data_file->file_status[0] != '0') {
break;
}
cob_copy_check (sort_file, data_file);
ret = cob_file_sort_submit (sort_file, sort_file->record->data);
if (ret) {
break;
}
}
cob_close (data_file, COB_CLOSE_NORMAL, NULL);
}

Definition at line 3734 of file fileio.c.
{
char *p;
char *src;
char *dst;
size_t i;
size_t simple;
int was_not_exist = 0;
struct stat st;
f->flag_read_done = 0;
/* file was previously closed with lock */
if (f->open_mode == COB_OPEN_LOCKED) {
RETURN_STATUS (COB_STATUS_38_CLOSED_WITH_LOCK);
}
/* file is already open */
if (f->open_mode != COB_OPEN_CLOSED) {
RETURN_STATUS (COB_STATUS_41_ALREADY_OPEN);
}
f->last_open_mode = mode;
f->flag_nonexistent = 0;
f->flag_end_of_file = 0;
f->flag_begin_of_file = 0;
f->flag_first_read = 2;
if (f->special) {
if (f->special == 1) {
if (mode != COB_OPEN_INPUT) {
RETURN_STATUS (COB_STATUS_30_PERMANENT_ERROR);
}
f->file = stdin;
f->open_mode = mode;
RETURN_STATUS (COB_STATUS_00_SUCCESS);
} else {
if (mode != COB_OPEN_OUTPUT) {
RETURN_STATUS (COB_STATUS_30_PERMANENT_ERROR);
}
f->file = stdout;
f->open_mode = mode;
RETURN_STATUS (COB_STATUS_00_SUCCESS);
}
}
/* obtain the file name */
cob_field_to_string (f->assign, file_open_name);
#ifdef WITH_INDEX_EXTFH
if (f->organization == COB_ORG_INDEXED) {
int ret;
ret = extfh_indexed_locate (f, file_open_name);
switch (ret) {
case COB_NOT_CONFIGURED:
/* EXTFH requires OC to process the filename */
break;
case COB_STATUS_00_SUCCESS:
/* EXTFH recognized the file */
goto file_available;
default:
/* EXTFH detected an error */
RETURN_STATUS (ret);
}
}
#endif /* WITH_INDEX_EXTFH */
#ifdef WITH_SEQRA_EXTFH
if (f->organization != COB_ORG_INDEXED) {
int ret;
ret = extfh_seqra_locate (f, file_open_name);
switch (ret) {
case COB_NOT_CONFIGURED:
/* EXTFH requires OC to process the filename */
break;
case COB_STATUS_00_SUCCESS:
/* EXTFH recognized the file */
goto file_available;
default:
/* EXTFH detected an error */
RETURN_STATUS (ret);
}
}
#endif /* WITH_SEQRA_EXTFH */
if (cob_current_module->flag_filename_mapping) {
src = file_open_name;
dst = file_open_buff;
simple = 1;
/* expand envoronment variables */
/* ex. "$TMPDIR/foo" -> "/tmp/foo" */
while (*src) {
if (!isalnum (*src) && *src != '_' && *src != '-') {
simple = 0;
}
if (*src == '$') {
for (i = 1; ; i++) {
if (!isalnum (src[i]) && src[i] != '_' && *src != '-') {
break;
}
}
memcpy (file_open_env, src + 1, i - 1);
file_open_env[i - 1] = 0;
if ((p = getenv (file_open_env)) != NULL) {
strcpy (dst, p);
dst += strlen (p);
}
src += i;
} else {
*dst++ = *src++;
}
}
*dst = 0;
strncpy (file_open_name, file_open_buff, COB_SMALL_MAX);
/* resolve by environment variables */
/* ex. "TMPFILE" -> DD_TMPFILE, dd_TMPFILE, or TMPFILE */
if (simple) {
for (i = 0; i < NUM_PREFIX; i++) {
snprintf (file_open_buff, COB_SMALL_MAX, "%s%s",
prefix[i], file_open_name);
if ((p = getenv (file_open_buff)) != NULL) {
strncpy (file_open_name, p, COB_SMALL_MAX);
break;
}
}
if (i == NUM_PREFIX && cob_file_path) {
snprintf (file_open_buff, COB_SMALL_MAX, "%s/%s",
cob_file_path, file_open_name);
strncpy (file_open_name, file_open_buff,
COB_SMALL_MAX);
}
}
}
/* check if the file exists */
#ifdef USE_DB41
if (f->organization == COB_ORG_INDEXED) {
if ((bdb_env && bdb_nofile (file_open_name)) ||
(!bdb_env && stat (file_open_name, &st) == -1 && errno == ENOENT)) {
was_not_exist = 1;
if (mode != COB_OPEN_OUTPUT && f->flag_optional == 0) {
RETURN_STATUS (COB_STATUS_35_NOT_EXISTS);
}
}
} else if (stat (file_open_name, &st) == -1 && errno == ENOENT) {
#else /* USE_DB41 */
#if defined(WITH_CISAM) || defined(WITH_DISAM) || defined(WITH_VBISAM)
if (f->organization == COB_ORG_INDEXED) {
strncpy (file_open_buff, file_open_name, COB_SMALL_MAX);
strcat (file_open_buff, ".idx");
if (stat (file_open_buff, &st) == -1 && errno == ENOENT) {
was_not_exist = 1;
if (mode != COB_OPEN_OUTPUT && f->flag_optional == 0) {
RETURN_STATUS (COB_STATUS_35_NOT_EXISTS);
}
}
strncpy (file_open_buff, file_open_name, COB_SMALL_MAX);
strcat (file_open_buff, ".dat");
if (stat (file_open_buff, &st) == -1 && errno == ENOENT) {
was_not_exist = 1;
if (mode != COB_OPEN_OUTPUT && f->flag_optional == 0) {
RETURN_STATUS (COB_STATUS_35_NOT_EXISTS);
}
}
} else if (stat (file_open_name, &st) == -1 && errno == ENOENT) {
#else /* WITH_CISAM || WITH_DISAM || WITH_VBISAM */
if (stat (file_open_name, &st) == -1 && errno == ENOENT) {
#endif /* WITH_CISAM || WITH_DISAM || WITH_VBISAM */
#endif /* USE_DB41 */
was_not_exist = 1;
if (mode != COB_OPEN_OUTPUT && f->flag_optional == 0) {
RETURN_STATUS (COB_STATUS_35_NOT_EXISTS);
}
}
#if defined(WITH_INDEX_EXTFH) || defined(WITH_SEQRA_EXTFH)
file_available:
#endif /* WITH_INDEX_EXTFH || WITH_SEQRA_EXTFH */
cob_cache_file (f);
/* open the file */
#ifdef WITH_SEQRA_EXTFH
if (f->organization != COB_ORG_INDEXED) {
int ret;
ret = extfh_cob_file_open (f, file_open_name, mode, sharing);
switch (ret) {
case COB_STATUS_00_SUCCESS:
f->open_mode = mode;
break;
case COB_STATUS_35_NOT_EXISTS:
if (f->flag_optional) {
f->open_mode = mode;
f->flag_nonexistent = 1;
f->flag_end_of_file = 1;
f->flag_begin_of_file = 1;
RETURN_STATUS (COB_STATUS_05_SUCCESS_OPTIONAL);
}
break;
}
RETURN_STATUS (ret);
}
#endif
#if defined(WITH_CISAM) || defined(WITH_DISAM) || defined(WITH_VBISAM)
if (f->organization == COB_ORG_INDEXED) {
/* Do this here to avoid mangling of the status in the 'switch' below */
RETURN_STATUS (fileio_funcs[(int)f->organization]->open (f, file_open_name, mode, sharing));
}
#endif
switch (fileio_funcs[(int)f->organization]->open (f, file_open_name, mode, sharing)) {
case 0:
f->open_mode = mode;
if (f->flag_optional && was_not_exist) {
RETURN_STATUS (COB_STATUS_05_SUCCESS_OPTIONAL);
} else {
RETURN_STATUS (COB_STATUS_00_SUCCESS);
}
case ENOENT:
if (mode == COB_OPEN_EXTEND || mode == COB_OPEN_OUTPUT) {
RETURN_STATUS (COB_STATUS_30_PERMANENT_ERROR);
}
if (f->flag_optional) {
f->open_mode = mode;
f->flag_nonexistent = 1;
f->flag_end_of_file = 1;
f->flag_begin_of_file = 1;
RETURN_STATUS (COB_STATUS_05_SUCCESS_OPTIONAL);
} else {
RETURN_STATUS (COB_STATUS_35_NOT_EXISTS);
}
case EACCES:
case EISDIR:
case EROFS:
RETURN_STATUS (COB_STATUS_37_PERMISSION_DENIED);
case EAGAIN:
case COB_STATUS_61_FILE_SHARING:
RETURN_STATUS (COB_STATUS_61_FILE_SHARING);
case COB_STATUS_91_NOT_AVAILABLE:
RETURN_STATUS (COB_STATUS_91_NOT_AVAILABLE);
case COB_LINAGE_INVALID:
RETURN_STATUS (COB_STATUS_57_I_O_LINAGE);
default:
RETURN_STATUS (COB_STATUS_30_PERMANENT_ERROR);
}
}


Definition at line 4081 of file fileio.c.
{
int ret;
f->flag_read_done = 0;
if (unlikely(f->flag_nonexistent)) {
if (f->flag_first_read == 0) {
RETURN_STATUS (COB_STATUS_23_KEY_NOT_EXISTS);
}
f->flag_first_read = 0;
RETURN_STATUS (COB_STATUS_10_END_OF_FILE);
}
/* sequential read at the end of file is an error */
if (key == NULL) {
if (f->flag_end_of_file && !(read_opts & COB_READ_PREVIOUS)) {
RETURN_STATUS (COB_STATUS_46_READ_ERROR);
}
if (f->flag_begin_of_file && (read_opts & COB_READ_PREVIOUS)) {
RETURN_STATUS (COB_STATUS_46_READ_ERROR);
}
}
if (unlikely(f->open_mode == COB_OPEN_CLOSED
|| f->open_mode == COB_OPEN_OUTPUT
|| f->open_mode == COB_OPEN_EXTEND)) {
RETURN_STATUS (COB_STATUS_47_INPUT_DENIED);
}
#ifdef USE_DB41
if (f->organization == COB_ORG_INDEXED && bdb_env != NULL) {
if (f->open_mode != COB_OPEN_I_O ||
(f->lock_mode & COB_LOCK_EXCLUSIVE)) {
read_opts &= ~COB_READ_LOCK;
} else if ((f->lock_mode & COB_LOCK_AUTOMATIC) &&
!(read_opts & COB_READ_NO_LOCK)) {
read_opts |= COB_READ_LOCK;
}
} else {
read_opts &= ~COB_READ_LOCK;
}
#endif
if (key) {
ret = fileio_funcs[(int)f->organization]->read (f, key, read_opts);
} else {
ret = fileio_funcs[(int)f->organization]->read_next (f, read_opts);
}
switch (ret) {
case COB_STATUS_00_SUCCESS:
f->flag_first_read = 0;
f->flag_read_done = 1;
f->flag_end_of_file = 0;
f->flag_begin_of_file = 0;
if (f->record_size && f->organization != COB_ORG_LINE_SEQUENTIAL) {
cob_set_int (f->record_size, (int) f->record->size);
}
break;
case COB_STATUS_10_END_OF_FILE:
if (read_opts & COB_READ_PREVIOUS) {
f->flag_begin_of_file = 1;
} else {
f->flag_end_of_file = 1;
}
break;
}
RETURN_STATUS (ret);
}


Definition at line 4201 of file fileio.c.
{
int ret;
int read_done = f->flag_read_done;
f->flag_read_done = 0;
if (unlikely(f->open_mode == COB_OPEN_CLOSED ||
f->open_mode != COB_OPEN_I_O)) {
RETURN_STATUS (COB_STATUS_49_I_O_DENIED);
}
if (f->access_mode == COB_ACCESS_SEQUENTIAL && !read_done) {
RETURN_STATUS (COB_STATUS_43_READ_NOT_DONE);
}
if (f->organization == COB_ORG_SEQUENTIAL) {
if (f->record->size != rec->size) {
RETURN_STATUS (COB_STATUS_44_RECORD_OVERFLOW);
}
if (f->record_size) {
if (f->record->size != (size_t)cob_get_int (f->record_size)) {
RETURN_STATUS (COB_STATUS_44_RECORD_OVERFLOW);
}
}
}
/* RXW
#ifdef USE_DB41
if (f->organization != COB_ORG_INDEXED || bdb_env == NULL) {
opt &= ~COB_WRITE_LOCK;
}
#endif
*/
ret = fileio_funcs[(int)f->organization]->rewrite (f, opt);
if (unlikely(cob_do_sync && ret == 0)) {
cob_sync (f, cob_do_sync);
}
RETURN_STATUS (ret);
}

| void cob_rollback | ( | void | ) |
Definition at line 4052 of file fileio.c.
{
int ret;
f->flag_read_done = 0;
f->flag_first_read = 0;
if (f->flag_nonexistent) {
RETURN_STATUS (COB_STATUS_23_KEY_NOT_EXISTS);
}
if (f->open_mode == COB_OPEN_CLOSED
|| f->open_mode == COB_OPEN_OUTPUT
|| f->open_mode == COB_OPEN_EXTEND
|| f->access_mode == COB_ACCESS_RANDOM) {
RETURN_STATUS (COB_STATUS_47_INPUT_DENIED);
}
ret = fileio_funcs[(int)f->organization]->start (f, cond, key);
if (ret == COB_STATUS_00_SUCCESS) {
f->flag_end_of_file = 0;
f->flag_begin_of_file = 0;
f->flag_first_read = 1;
}
RETURN_STATUS (ret);
}
Definition at line 3727 of file fileio.c.
{
cob_file_unlock (f);
RETURN_STATUS (COB_STATUS_00_SUCCESS);
}
Definition at line 4153 of file fileio.c.
{
int ret;
f->flag_read_done = 0;
if (f->access_mode == COB_ACCESS_SEQUENTIAL) {
if (f->open_mode == COB_OPEN_CLOSED
|| f->open_mode == COB_OPEN_INPUT
|| f->open_mode == COB_OPEN_I_O) {
RETURN_STATUS (COB_STATUS_48_OUTPUT_DENIED);
}
} else {
if (f->open_mode == COB_OPEN_CLOSED
|| f->open_mode == COB_OPEN_INPUT
|| f->open_mode == COB_OPEN_EXTEND) {
RETURN_STATUS (COB_STATUS_48_OUTPUT_DENIED);
}
}
if (f->record_size) {
f->record->size = cob_get_int (f->record_size);
} else {
f->record->size = rec->size;
}
if (f->record->size < f->record_min || f->record_max < f->record->size) {
RETURN_STATUS (COB_STATUS_44_RECORD_OVERFLOW);
}
/* RXW
#ifdef USE_DB41
if (f->organization != COB_ORG_INDEXED || bdb_env == NULL) {
opt &= ~COB_WRITE_LOCK;
}
#endif
*/
ret = fileio_funcs[(int)f->organization]->write (f, opt);
if (unlikely(cob_do_sync && ret == 0)) {
cob_sync (f, cob_do_sync);
}
RETURN_STATUS (ret);
}


| DLL_EXPIMP cob_file* cob_error_file |
1.7.4