Commit 7d56f504 authored by lw's avatar lw

*** empty log message ***

parent 08569a49
...@@ -21,6 +21,79 @@ ...@@ -21,6 +21,79 @@
#include "co_platform.h" #include "co_platform.h"
pwr_tBoolean
dbs_AlignedRead(pwr_tStatus *sts, void *buf, pwr_tUInt32 size, const dbs_sEnv *ep)
{
int offset;
*sts = DBS__SUCCESS;
if (fread(buf, size, 1, ep->f) == 0)
pwr_Return(NO, sts, errno_GetStatus());
if ((offset = dbs_dPadding(size)) > 0)
if(fseek(ep->f, offset, SEEK_CUR))
pwr_Return(NO, sts, errno_GetStatus());
return YES;
}
pwr_tBoolean
dbs_Close(pwr_tStatus *sts, dbs_sEnv *ep)
{
*sts = DBS__SUCCESS;
fclose(ep->f);
ep->f = NULL;
return TRUE;
}
dbs_sEnv *
dbs_Open(pwr_tStatus *sts, dbs_sEnv *ep, const char *filename)
{
FILE *f;
co_mFormat srcFormat, ownFormat;
PDR pdrs;
*sts = DBS__SUCCESS;
memset(ep, 0, sizeof(*ep));
f = fopen(filename, "r");
if (f == NULL) {
*sts = errno_GetStatus();
return NULL;
}
if (fread(&ep->file, sizeof(ep->file), 1, f) == 0) {
*sts = errno_GetStatus();
fclose(f);
return NULL;
}
#if 0
srcFormat.m = ntohl(ep->file.format.m);
#else
srcFormat.m = ep->file.format.m;
#endif
co_GetOwnFormat(&ownFormat);
if (srcFormat.m != ownFormat.m) {
pdrmem_create(&pdrs, &ep->file, sizeof(ep->file), PDR_DECODE, srcFormat, ownFormat);
if (!pdr_dbs_sFile(&pdrs, &ep->file)) {
*sts = DBS__PDRFILE;
fclose(f);
return NULL;
}
}
fseek(f, 0, SEEK_SET);
ep->f = f;
return ep;
}
#if defined(OS_LINUX) || defined(OS_LYNX)
static pwr_tBoolean static pwr_tBoolean
checkQ(const dbs_sEnv *ep, dbs_sQlink *item) checkQ(const dbs_sEnv *ep, dbs_sQlink *item)
{ {
...@@ -300,60 +373,6 @@ dbs_Reference(pwr_tStatus *sts, const dbs_sEnv *ep, void *adrs) ...@@ -300,60 +373,6 @@ dbs_Reference(pwr_tStatus *sts, const dbs_sEnv *ep, void *adrs)
#endif #endif
pwr_tBoolean
dbs_Close(pwr_tStatus *sts, dbs_sEnv *ep)
{
*sts = DBS__SUCCESS;
fclose(ep->f);
ep->f = NULL;
return TRUE;
}
dbs_sEnv *
dbs_Open(pwr_tStatus *sts, dbs_sEnv *ep, const char *filename)
{
FILE *f;
co_mFormat srcFormat, ownFormat;
PDR pdrs;
*sts = DBS__SUCCESS;
memset(ep, 0, sizeof(*ep));
f = fopen(filename, "r");
if (f == NULL) {
*sts = errno_GetStatus();
return NULL;
}
if (fread(&ep->file, sizeof(ep->file), 1, f) == 0) {
*sts = errno_GetStatus();
fclose(f);
return NULL;
}
#if 0
srcFormat.m = ntohl(ep->file.format.m);
#else
srcFormat.m = ep->file.format.m;
#endif
co_GetOwnFormat(&ownFormat);
if (srcFormat.m != ownFormat.m) {
pdrmem_create(&pdrs, &ep->file, sizeof(ep->file), PDR_DECODE, srcFormat, ownFormat);
if (!pdr_dbs_sFile(&pdrs, &ep->file)) {
*sts = DBS__PDRFILE;
fclose(f);
return NULL;
}
}
fseek(f, 0, SEEK_SET);
ep->f = f;
return ep;
}
static void static void
printTree(dbs_sEnv *ep, dbs_sObject *op, int indent) printTree(dbs_sEnv *ep, dbs_sObject *op, int indent)
{ {
...@@ -878,23 +897,6 @@ dbs_Ancestor(pwr_tStatus *sts, const dbs_sEnv *ep, dbs_sObject *op) ...@@ -878,23 +897,6 @@ dbs_Ancestor(pwr_tStatus *sts, const dbs_sEnv *ep, dbs_sObject *op)
return op; return op;
} }
pwr_tBoolean
dbs_AlignedRead(pwr_tStatus *sts, void *buf, pwr_tUInt32 size, const dbs_sEnv *ep)
{
int offset;
*sts = DBS__SUCCESS;
if (fread(buf, size, 1, ep->f) == 0)
pwr_Return(NO, sts, errno_GetStatus());
if ((offset = dbs_dPadding(size)) > 0)
if(fseek(ep->f, offset, SEEK_CUR))
pwr_Return(NO, sts, errno_GetStatus());
return YES;
}
void void
dbs_GetVolumeName(pwr_tStatus *sts, dbs_sEnv *ep, char *name) dbs_GetVolumeName(pwr_tStatus *sts, dbs_sEnv *ep, char *name)
{ {
...@@ -986,3 +988,4 @@ dbs_NextDbody(pwr_tStatus *sts, const dbs_sEnv *ep, dbs_sBody *bp) ...@@ -986,3 +988,4 @@ dbs_NextDbody(pwr_tStatus *sts, const dbs_sEnv *ep, dbs_sBody *bp)
return bp; return bp;
} }
#endif
...@@ -564,6 +564,10 @@ struct dbs_sScObject { ...@@ -564,6 +564,10 @@ struct dbs_sScObject {
%#define dbs_Qitem(a, b, c) ((b *)((char *)a - offsetof(b, c))) %#define dbs_Qitem(a, b, c) ((b *)((char *)a - offsetof(b, c)))
%#define dbs_Qlink(a, b, c) ((dbs_sQlink *)((char *)a + offsetof(b, c))) %#define dbs_Qlink(a, b, c) ((dbs_sQlink *)((char *)a + offsetof(b, c)))
% %
%pwr_tBoolean dbs_AlignedRead(pwr_tStatus *sts, void *buf, pwr_tUInt32 size, const dbs_sEnv *ep);
%pwr_tBoolean dbs_Close(pwr_tStatus *sts, dbs_sEnv *ep);
%dbs_sEnv *dbs_Open(pwr_tStatus *sts, dbs_sEnv *ep, const char *filename);
%#if defined(OS_LINUX) || defined(OS_LYNX)
%void *dbs_Address(pwr_tStatus*, const dbs_sEnv*, dbs_tRef); %void *dbs_Address(pwr_tStatus*, const dbs_sEnv*, dbs_tRef);
%void *dbs_Alloc(pwr_tStatus*, const dbs_sEnv*, pwr_tUInt32); %void *dbs_Alloc(pwr_tStatus*, const dbs_sEnv*, pwr_tUInt32);
%pwr_tBoolean dbs_AllocLookasideSegment(pwr_tStatus*, const dbs_sEnv*, pwr_tUInt32, pwr_tUInt32); %pwr_tBoolean dbs_AllocLookasideSegment(pwr_tStatus*, const dbs_sEnv*, pwr_tUInt32, pwr_tUInt32);
...@@ -592,9 +596,6 @@ struct dbs_sScObject { ...@@ -592,9 +596,6 @@ struct dbs_sScObject {
%dbs_tRef dbs_RefAlloc(pwr_tStatus*, const dbs_sEnv*, pwr_tUInt32); %dbs_tRef dbs_RefAlloc(pwr_tStatus*, const dbs_sEnv*, pwr_tUInt32);
%dbs_tRef dbs_Reference(pwr_tStatus*, const dbs_sEnv*, void*); %dbs_tRef dbs_Reference(pwr_tStatus*, const dbs_sEnv*, void*);
% %
%pwr_tBoolean dbs_AlignedRead(pwr_tStatus *sts, void *buf, pwr_tUInt32 size, const dbs_sEnv *ep);
%pwr_tBoolean dbs_Close(pwr_tStatus *sts, dbs_sEnv *ep);
%dbs_sEnv *dbs_Open(pwr_tStatus *sts, dbs_sEnv *ep, const char *filename);
%dbs_sEnv *dbs_Map(pwr_tStatus *sts, dbs_sEnv *ep, const char *filename); %dbs_sEnv *dbs_Map(pwr_tStatus *sts, dbs_sEnv *ep, const char *filename);
% %
%dbs_sObject *dbs_OidToObject(pwr_tStatus *sts, const dbs_sEnv *ep, pwr_tOid oid); %dbs_sObject *dbs_OidToObject(pwr_tStatus *sts, const dbs_sEnv *ep, pwr_tOid oid);
...@@ -617,7 +618,7 @@ struct dbs_sScObject { ...@@ -617,7 +618,7 @@ struct dbs_sScObject {
%dbs_sObject *dbs_NextHead(pwr_tStatus *sts, const dbs_sEnv *ep, dbs_sObject *op); %dbs_sObject *dbs_NextHead(pwr_tStatus *sts, const dbs_sEnv *ep, dbs_sObject *op);
%dbs_sBody *dbs_NextRbody(pwr_tStatus *sts, const dbs_sEnv *ep, dbs_sBody *bp); %dbs_sBody *dbs_NextRbody(pwr_tStatus *sts, const dbs_sEnv *ep, dbs_sBody *bp);
%dbs_sBody *dbs_NextDbody(pwr_tStatus *sts, const dbs_sEnv *ep, dbs_sBody *bp); %dbs_sBody *dbs_NextDbody(pwr_tStatus *sts, const dbs_sEnv *ep, dbs_sBody *bp);
% %#endif
% %
%#ifdef __cplusplus %#ifdef __cplusplus
%} %}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment