home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Frostbyte's 1980s DOS Shareware Collection
/
floppyshareware.zip
/
floppyshareware
/
DOOG
/
CBASE09.ZIP
/
CBASE.ZIP
/
CBCREATE.C
< prev
next >
Wrap
Text File
|
1989-08-31
|
3KB
|
119 lines
/* Copyright (c) 1989 Citadel */
/* All Rights Reserved */
/* #ident "cbcreate.c 1.1 - 89/08/31" */
#include <blkio.h>
#include <btree.h>
#include <errno.h>
#include <lseq.h>
#include "cbase_.h"
/*man---------------------------------------------------------------------------
NAME
cbcreate - create a cbase
SYNOPSIS
#include <cbase.h>
int cbcreate(cbname, recsize, fields, fldcnt)
char *cbname;
size_t recsize;
cbfield_t fields[];
size_t fldcnt;
DESCRIPTION
The cbcreate function creates the cbase named by cbname.
cbname points to a character string that contains the name of the
cbase to be created.
recsize specifies the size of the records in the cbase.
fields is an array of field definition structures. The list of field
definitions must be in order of occurrence in the record. cbfield_t
is defined as follows:
typedef struct {
size_t offset; /* offset of field in record *\/
size_t size; /* size of field *\/
int type; /* type of field *\/
int flags; /* flags *\/
char filename[FILENAME_MAX]; /* name of file to store keys in *\/
} cbfield_t;
flags values are constructed by OR-ing flags from the following list:
CBFKEY Field is to be a key.
CBFUNIQ Only for use with CBFKEY. Indicates that
key value should be unique.
fldcnt specifies the number of fields in each record.
cbcreate will fail if one or more of the following is true:
[EEXIST] Either the record file or one of
the key files exists.
[EINVAL] cbname is the NULL pointer.
[EINVAL] recsize is less than sizeof(lspos_t).
[EINVAL] fldcnt is not in the range [1..CBFIELD_MAX].
[EINVAL] keycnt is not in the range [0..CBKEY_MAX].
[EINVAL] There is a field overlap in the field
definition list.
[EINVAL] fields specifies an invalid type.
[EINVAL] keys specifies a non-existent field.
SEE ALSO
cbopen.
DIAGNOSTICS
Upon successful completion, a value of 0 is returned. Otherwise, a
value of -1 is returned, and errno set to indicate the error.
------------------------------------------------------------------------------*/
int cbcreate(cbname, recsize, fields, fldcnt)
char * cbname;
size_t recsize;
cbfield_t fields[];
size_t fldcnt;
{
int rs = 0;
int i = 0;
errno = 0;
/* validate arguments */
if (cbname == NULL) {
errno = EINVAL;
return -1;
}
if (recsize < sizeof(lspos_t)) {
errno = EINVAL;
return -1;
}
if (!cb_fdlvalid(fields, fldcnt, recsize)) {
errno = EINVAL;
return -1;
}
/* create lseq file for records */
rs = lscreate(cbname, recsize);
if (rs == -1) {
if ((errno != EEXIST)) CBEPRINT;
return -1;
}
/* create btree files for keys */
for (i = 0; i < fldcnt; i++) {
if (fields[i].flags & CBFKEY) {
rs = btcreate(fields[i].filename, CBM, fields[i].size + sizeof(cbrpos_t));
if (rs == -1) {
if ((errno != EEXIST)) CBEPRINT;
return -1;
}
}
}
errno = 0;
return 0;
}