OpenCOBOL 1.1pre-rel
Data Structures | Defines | Functions | Variables
fileio.h File Reference
#include <libcob/common.h>
Include dependency graph for fileio.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  cob_file_key
struct  linage_struct
struct  cob_file
struct  cob_fileio_funcs

Defines

#define COB_FILE_VERSION   0
#define COB_EQ   1
#define COB_LT   2
#define COB_LE   3
#define COB_GT   4
#define COB_GE   5
#define COB_NE   6
#define COB_ASCENDING   0
#define COB_DESCENDING   1
#define COB_FILE_MODE   0644
#define COB_ORG_SEQUENTIAL   0
#define COB_ORG_LINE_SEQUENTIAL   1
#define COB_ORG_RELATIVE   2
#define COB_ORG_INDEXED   3
#define COB_ORG_SORT   4
#define COB_ORG_MAX   5
#define COB_ACCESS_SEQUENTIAL   1
#define COB_ACCESS_DYNAMIC   2
#define COB_ACCESS_RANDOM   3
#define COB_SELECT_FILE_STATUS   0x01
#define COB_SELECT_EXTERNAL   0x02
#define COB_SELECT_LINAGE   0x04
#define COB_SELECT_SPLITKEY   0x08
#define COB_LOCK_EXCLUSIVE   1
#define COB_LOCK_MANUAL   2
#define COB_LOCK_AUTOMATIC   4
#define COB_LOCK_MULTIPLE   8
#define COB_LOCK_MASK   0x7
#define COB_OPEN_CLOSED   0
#define COB_OPEN_INPUT   1
#define COB_OPEN_OUTPUT   2
#define COB_OPEN_I_O   3
#define COB_OPEN_EXTEND   4
#define COB_OPEN_LOCKED   5
#define COB_CLOSE_NORMAL   0
#define COB_CLOSE_LOCK   1
#define COB_CLOSE_NO_REWIND   2
#define COB_CLOSE_UNIT   3
#define COB_CLOSE_UNIT_REMOVAL   4
#define COB_WRITE_MASK   0x0000ffff
#define COB_WRITE_LINES   0x00010000
#define COB_WRITE_PAGE   0x00020000
#define COB_WRITE_CHANNEL   0x00040000
#define COB_WRITE_AFTER   0x00100000
#define COB_WRITE_BEFORE   0x00200000
#define COB_WRITE_EOP   0x00400000
#define COB_WRITE_LOCK   0x00800000
#define COB_READ_NEXT   0x01
#define COB_READ_PREVIOUS   0x02
#define COB_READ_FIRST   0x04
#define COB_READ_LAST   0x08
#define COB_READ_LOCK   0x10
#define COB_READ_NO_LOCK   0x20
#define COB_READ_KEPT_LOCK   0x40
#define COB_READ_WAIT_LOCK   0x80
#define COB_READ_IGNORE_LOCK   0x100
#define COB_STATUS_00_SUCCESS   00
#define COB_STATUS_02_SUCCESS_DUPLICATE   02
#define COB_STATUS_04_SUCCESS_INCOMPLETE   04
#define COB_STATUS_05_SUCCESS_OPTIONAL   05
#define COB_STATUS_07_SUCCESS_NO_UNIT   07
#define COB_STATUS_10_END_OF_FILE   10
#define COB_STATUS_14_OUT_OF_KEY_RANGE   14
#define COB_STATUS_21_KEY_INVALID   21
#define COB_STATUS_22_KEY_EXISTS   22
#define COB_STATUS_23_KEY_NOT_EXISTS   23
#define COB_STATUS_30_PERMANENT_ERROR   30
#define COB_STATUS_31_INCONSISTENT_FILENAME   31
#define COB_STATUS_34_BOUNDARY_VIOLATION   34
#define COB_STATUS_35_NOT_EXISTS   35
#define COB_STATUS_37_PERMISSION_DENIED   37
#define COB_STATUS_38_CLOSED_WITH_LOCK   38
#define COB_STATUS_39_CONFLICT_ATTRIBUTE   39
#define COB_STATUS_41_ALREADY_OPEN   41
#define COB_STATUS_42_NOT_OPEN   42
#define COB_STATUS_43_READ_NOT_DONE   43
#define COB_STATUS_44_RECORD_OVERFLOW   44
#define COB_STATUS_46_READ_ERROR   46
#define COB_STATUS_47_INPUT_DENIED   47
#define COB_STATUS_48_OUTPUT_DENIED   48
#define COB_STATUS_49_I_O_DENIED   49
#define COB_STATUS_51_RECORD_LOCKED   51
#define COB_STATUS_52_EOP   52
#define COB_STATUS_57_I_O_LINAGE   57
#define COB_STATUS_61_FILE_SHARING   61
#define COB_STATUS_91_NOT_AVAILABLE   91
#define COB_LINAGE_INVALID   16384
#define COB_NOT_CONFIGURED   32768

Functions

void cob_default_error_handle (void)
void cob_open (cob_file *, const int, const int, cob_field *)
void cob_close (cob_file *, const int, cob_field *)
void cob_read (cob_file *, cob_field *, cob_field *, int)
void cob_write (cob_file *, cob_field *, const int, cob_field *)
void cob_rewrite (cob_file *, cob_field *, const int, cob_field *)
void cob_delete (cob_file *, cob_field *)
void cob_start (cob_file *, const int, cob_field *, cob_field *)
void cob_unlock_file (cob_file *, cob_field *)
void cob_commit (void)
void cob_rollback (void)
int CBL_OPEN_FILE (unsigned char *, unsigned char *, unsigned char *, unsigned char *, unsigned char *)
int CBL_CREATE_FILE (unsigned char *, unsigned char *, unsigned char *, unsigned char *, unsigned char *)
int CBL_READ_FILE (unsigned char *, unsigned char *, unsigned char *, unsigned char *, unsigned char *)
int CBL_WRITE_FILE (unsigned char *, unsigned char *, unsigned char *, unsigned char *, unsigned char *)
int CBL_CLOSE_FILE (unsigned char *)
int CBL_FLUSH_FILE (unsigned char *)
int CBL_DELETE_FILE (unsigned char *)
int CBL_COPY_FILE (unsigned char *, unsigned char *)
int CBL_CHECK_FILE_EXIST (unsigned char *, unsigned char *)
int CBL_RENAME_FILE (unsigned char *, unsigned char *)
int CBL_GET_CURRENT_DIR (const int, const int, unsigned char *)
int CBL_CHANGE_DIR (unsigned char *)
int CBL_CREATE_DIR (unsigned char *)
int CBL_DELETE_DIR (unsigned char *)
int cob_acuw_chdir (unsigned char *, unsigned char *)
int cob_acuw_mkdir (unsigned char *)
int cob_acuw_copyfile (unsigned char *, unsigned char *, unsigned char *)
int cob_acuw_file_info (unsigned char *, unsigned char *)
int cob_acuw_file_delete (unsigned char *, unsigned char *)
void cob_file_sort_init (cob_file *, const int, const unsigned char *, void *, cob_field *)
void cob_file_sort_init_key (cob_file *, const int, cob_field *, size_t)
void cob_file_sort_close (cob_file *)
void cob_file_sort_using (cob_file *, cob_file *)
void cob_file_sort_giving (cob_file *, const size_t,...)
void cob_file_release (cob_file *)
void cob_file_return (cob_file *)

Variables

DLL_EXPIMP cob_filecob_error_file

Define Documentation

#define COB_ACCESS_DYNAMIC   2

Definition at line 53 of file fileio.h.

#define COB_ACCESS_RANDOM   3

Definition at line 54 of file fileio.h.

#define COB_ACCESS_SEQUENTIAL   1

Definition at line 52 of file fileio.h.

#define COB_ASCENDING   0

Definition at line 36 of file fileio.h.

#define COB_CLOSE_LOCK   1

Definition at line 83 of file fileio.h.

#define COB_CLOSE_NO_REWIND   2

Definition at line 84 of file fileio.h.

#define COB_CLOSE_NORMAL   0

Definition at line 82 of file fileio.h.

#define COB_CLOSE_UNIT   3

Definition at line 85 of file fileio.h.

#define COB_CLOSE_UNIT_REMOVAL   4

Definition at line 86 of file fileio.h.

#define COB_DESCENDING   1

Definition at line 37 of file fileio.h.

#define COB_EQ   1

Definition at line 29 of file fileio.h.

#define COB_FILE_MODE   0644

Definition at line 39 of file fileio.h.

#define COB_FILE_VERSION   0

Definition at line 27 of file fileio.h.

#define COB_GE   5

Definition at line 33 of file fileio.h.

#define COB_GT   4

Definition at line 32 of file fileio.h.

#define COB_LE   3

Definition at line 31 of file fileio.h.

#define COB_LINAGE_INVALID   16384

Definition at line 146 of file fileio.h.

#define COB_LOCK_AUTOMATIC   4

Definition at line 67 of file fileio.h.

#define COB_LOCK_EXCLUSIVE   1

Definition at line 65 of file fileio.h.

#define COB_LOCK_MANUAL   2

Definition at line 66 of file fileio.h.

#define COB_LOCK_MASK   0x7

Definition at line 69 of file fileio.h.

#define COB_LOCK_MULTIPLE   8

Definition at line 68 of file fileio.h.

#define COB_LT   2

Definition at line 30 of file fileio.h.

#define COB_NE   6

Definition at line 34 of file fileio.h.

#define COB_NOT_CONFIGURED   32768

Definition at line 148 of file fileio.h.

#define COB_OPEN_CLOSED   0

Definition at line 73 of file fileio.h.

#define COB_OPEN_EXTEND   4

Definition at line 77 of file fileio.h.

#define COB_OPEN_I_O   3

Definition at line 76 of file fileio.h.

#define COB_OPEN_INPUT   1

Definition at line 74 of file fileio.h.

#define COB_OPEN_LOCKED   5

Definition at line 78 of file fileio.h.

#define COB_OPEN_OUTPUT   2

Definition at line 75 of file fileio.h.

#define COB_ORG_INDEXED   3

Definition at line 46 of file fileio.h.

#define COB_ORG_LINE_SEQUENTIAL   1

Definition at line 44 of file fileio.h.

#define COB_ORG_MAX   5

Definition at line 48 of file fileio.h.

#define COB_ORG_RELATIVE   2

Definition at line 45 of file fileio.h.

#define COB_ORG_SEQUENTIAL   0

Definition at line 43 of file fileio.h.

#define COB_ORG_SORT   4

Definition at line 47 of file fileio.h.

#define COB_READ_FIRST   0x04

Definition at line 102 of file fileio.h.

#define COB_READ_IGNORE_LOCK   0x100

Definition at line 108 of file fileio.h.

#define COB_READ_KEPT_LOCK   0x40

Definition at line 106 of file fileio.h.

#define COB_READ_LAST   0x08

Definition at line 103 of file fileio.h.

#define COB_READ_LOCK   0x10

Definition at line 104 of file fileio.h.

#define COB_READ_NEXT   0x01

Definition at line 100 of file fileio.h.

#define COB_READ_NO_LOCK   0x20

Definition at line 105 of file fileio.h.

#define COB_READ_PREVIOUS   0x02

Definition at line 101 of file fileio.h.

#define COB_READ_WAIT_LOCK   0x80

Definition at line 107 of file fileio.h.

#define COB_SELECT_EXTERNAL   0x02

Definition at line 59 of file fileio.h.

#define COB_SELECT_FILE_STATUS   0x01

Definition at line 58 of file fileio.h.

#define COB_SELECT_LINAGE   0x04

Definition at line 60 of file fileio.h.

#define COB_SELECT_SPLITKEY   0x08

Definition at line 61 of file fileio.h.

#define COB_STATUS_00_SUCCESS   00

Definition at line 112 of file fileio.h.

#define COB_STATUS_02_SUCCESS_DUPLICATE   02

Definition at line 113 of file fileio.h.

#define COB_STATUS_04_SUCCESS_INCOMPLETE   04

Definition at line 114 of file fileio.h.

#define COB_STATUS_05_SUCCESS_OPTIONAL   05

Definition at line 115 of file fileio.h.

#define COB_STATUS_07_SUCCESS_NO_UNIT   07

Definition at line 116 of file fileio.h.

#define COB_STATUS_10_END_OF_FILE   10

Definition at line 117 of file fileio.h.

#define COB_STATUS_14_OUT_OF_KEY_RANGE   14

Definition at line 118 of file fileio.h.

#define COB_STATUS_21_KEY_INVALID   21

Definition at line 119 of file fileio.h.

#define COB_STATUS_22_KEY_EXISTS   22

Definition at line 120 of file fileio.h.

#define COB_STATUS_23_KEY_NOT_EXISTS   23

Definition at line 121 of file fileio.h.

#define COB_STATUS_30_PERMANENT_ERROR   30

Definition at line 122 of file fileio.h.

#define COB_STATUS_31_INCONSISTENT_FILENAME   31

Definition at line 123 of file fileio.h.

#define COB_STATUS_34_BOUNDARY_VIOLATION   34

Definition at line 124 of file fileio.h.

#define COB_STATUS_35_NOT_EXISTS   35

Definition at line 125 of file fileio.h.

#define COB_STATUS_37_PERMISSION_DENIED   37

Definition at line 126 of file fileio.h.

#define COB_STATUS_38_CLOSED_WITH_LOCK   38

Definition at line 127 of file fileio.h.

#define COB_STATUS_39_CONFLICT_ATTRIBUTE   39

Definition at line 128 of file fileio.h.

#define COB_STATUS_41_ALREADY_OPEN   41

Definition at line 129 of file fileio.h.

#define COB_STATUS_42_NOT_OPEN   42

Definition at line 130 of file fileio.h.

#define COB_STATUS_43_READ_NOT_DONE   43

Definition at line 131 of file fileio.h.

#define COB_STATUS_44_RECORD_OVERFLOW   44

Definition at line 132 of file fileio.h.

#define COB_STATUS_46_READ_ERROR   46

Definition at line 133 of file fileio.h.

#define COB_STATUS_47_INPUT_DENIED   47

Definition at line 134 of file fileio.h.

#define COB_STATUS_48_OUTPUT_DENIED   48

Definition at line 135 of file fileio.h.

#define COB_STATUS_49_I_O_DENIED   49

Definition at line 136 of file fileio.h.

#define COB_STATUS_51_RECORD_LOCKED   51

Definition at line 137 of file fileio.h.

#define COB_STATUS_52_EOP   52

Definition at line 138 of file fileio.h.

#define COB_STATUS_57_I_O_LINAGE   57

Definition at line 139 of file fileio.h.

#define COB_STATUS_61_FILE_SHARING   61

Definition at line 140 of file fileio.h.

#define COB_STATUS_91_NOT_AVAILABLE   91

Definition at line 141 of file fileio.h.

#define COB_WRITE_AFTER   0x00100000

Definition at line 94 of file fileio.h.

#define COB_WRITE_BEFORE   0x00200000

Definition at line 95 of file fileio.h.

#define COB_WRITE_CHANNEL   0x00040000

Definition at line 93 of file fileio.h.

#define COB_WRITE_EOP   0x00400000

Definition at line 96 of file fileio.h.

#define COB_WRITE_LINES   0x00010000

Definition at line 91 of file fileio.h.

#define COB_WRITE_LOCK   0x00800000

Definition at line 97 of file fileio.h.

#define COB_WRITE_MASK   0x0000ffff

Definition at line 90 of file fileio.h.

#define COB_WRITE_PAGE   0x00020000

Definition at line 92 of file fileio.h.


Function Documentation

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;
}

Here is the call graph for this function:

Here is the caller graph for this function:

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;
}

Here is the call graph for this function:

Here is the caller graph for this function:

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);
}

Here is the call graph for this function:

Here is the caller graph for this function:

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;
}

Here is the call graph for this function:

Here is the caller graph for this function:

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;
}

Here is the call graph for this function:

Here is the caller graph for this function:

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);
}

Here is the call graph for this function:

Here is the caller graph for this function:

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;
}

Here is the call graph for this function:

Here is the caller graph for this function:

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;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int CBL_FLUSH_FILE ( unsigned char *  )

Definition at line 4642 of file fileio.c.

{
        COB_CHK_PARMS (CBL_FLUSH_FILE, 1);

        return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

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;
}

Here is the call graph for this function:

Here is the caller graph for this function:

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);
}

Here is the call graph for this function:

Here is the caller graph for this function:

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;
}

Here is the call graph for this function:

Here is the caller graph for this function:

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;
}

Here is the call graph for this function:

Here is the caller graph for this function:

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;
}

Here is the call graph for this function:

Here is the caller graph for this function:

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;
}

Here is the call graph for this function:

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;
}

Here is the call graph for this function:

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;
}

Here is the call graph for this function:

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;
}

Here is the call graph for this function:

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;
}

Here is the call graph for this function:

void cob_close ( cob_file ,
const int  ,
cob_field  
)

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);
}

Here is the caller graph for this function:

void cob_commit ( void  )

Definition at line 4273 of file fileio.c.

{
        struct file_list        *l;

        for (l = file_cache; l; l = l->next) {
                cob_file_unlock (l->file);
        }
}

Here is the call graph for this function:

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);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void cob_delete ( cob_file ,
cob_field  
)

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);
}

Here is the call graph for this function:

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;
        }
}

Here is the call graph for this function:

Here is the caller graph for this function:

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;
        }
}

Here is the call graph for this function:

Here is the caller graph for this function:

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);
}

Here is the call graph for this function:

Here is the caller graph for this function:

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);
}

Here is the call graph for this function:

void cob_file_sort_init ( cob_file ,
const int  ,
const unsigned char *  ,
void *  ,
cob_field  
)

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);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void cob_file_sort_init_key ( cob_file ,
const int  ,
cob_field ,
size_t   
)

Definition at line 5621 of file fileio.c.

{
        f->keys[f->nkeys].flag = flag;
        f->keys[f->nkeys].field = field;
        f->keys[f->nkeys].offset = offset;
        f->nkeys++;
}

Here is the caller graph for this function:

void cob_file_sort_using ( cob_file ,
cob_file  
)

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);
}

Here is the call graph for this function:

void cob_open ( cob_file ,
const int  ,
const int  ,
cob_field  
)

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);
        }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void cob_read ( cob_file ,
cob_field ,
cob_field ,
int   
)

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);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void cob_rewrite ( cob_file ,
cob_field ,
const int  ,
cob_field  
)

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);
}

Here is the call graph for this function:

void cob_rollback ( void  )

Definition at line 4283 of file fileio.c.

{
        struct file_list        *l;

        for (l = file_cache; l; l = l->next) {
                cob_file_unlock (l->file);
        }
}

Here is the call graph for this function:

void cob_start ( cob_file ,
const int  ,
cob_field ,
cob_field  
)

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);
}
void cob_unlock_file ( cob_file ,
cob_field  
)

Definition at line 3727 of file fileio.c.

Here is the call graph for this function:

void cob_write ( cob_file ,
cob_field ,
const int  ,
cob_field  
)

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);
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

DLL_EXPIMP cob_file* cob_error_file

Definition at line 197 of file fileio.c.

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines