summaryrefslogtreecommitdiff
path: root/storage/connect/filamdbf.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'storage/connect/filamdbf.cpp')
-rw-r--r--storage/connect/filamdbf.cpp63
1 files changed, 32 insertions, 31 deletions
diff --git a/storage/connect/filamdbf.cpp b/storage/connect/filamdbf.cpp
index f1fc466a5fc..8afda723578 100644
--- a/storage/connect/filamdbf.cpp
+++ b/storage/connect/filamdbf.cpp
@@ -1,11 +1,11 @@
/*********** File AM Dbf C++ Program Source Code File (.CPP) ****************/
/* PROGRAM NAME: FILAMDBF */
/* ------------- */
-/* Version 1.7 */
+/* Version 1.8 */
/* */
/* COPYRIGHT: */
/* ---------- */
-/* (C) Copyright to the author Olivier BERTRAND 2005-2014 */
+/* (C) Copyright to the author Olivier BERTRAND 2005-2015 */
/* */
/* WHAT THIS PROGRAM DOES: */
/* ----------------------- */
@@ -22,12 +22,12 @@
/* Include relevant sections of the System header files. */
/***********************************************************************/
#include "my_global.h"
-#if defined(WIN32)
+#if defined(__WIN__)
#include <io.h>
#include <fcntl.h>
//#include <errno.h>
//#include <windows.h>
-#else // !WIN32
+#else // !__WIN__
#if defined(UNIX)
#include <errno.h>
#include <unistd.h>
@@ -35,7 +35,7 @@
//#include <io.h>
#endif // !UNIX
//#include <fcntl.h>
-#endif // !WIN32
+#endif // !__WIN__
#include <ctype.h>
#include <stdio.h>
#include <string.h>
@@ -74,28 +74,28 @@ typedef struct _dbfheader {
//uchar Dbfox :4; /* FoxPro if equal to 3 */
uchar Version; /* Version information flags */
char Filedate[3]; /* date, YYMMDD, binary. YY=year-1900 */
-private:
+ private:
/* The following four members are stored in little-endian format on disk */
char m_RecordsBuf[4]; /* records in the file */
char m_HeadlenBuf[2]; /* bytes in the header */
char m_ReclenBuf[2]; /* bytes in a record */
char m_FieldsBuf[2]; /* Reserved but used to store fields */
-public:
+ public:
char Incompleteflag; /* 01 if incomplete, else 00 */
char Encryptflag; /* 01 if encrypted, else 00 */
char Reserved2[12]; /* for LAN use */
char Mdxflag; /* 01 if production .mdx, else 00 */
char Language; /* Codepage */
char Reserved3[2];
-
- uint Records() const { return uint4korr(m_RecordsBuf); }
- ushort Headlen() const { return uint2korr(m_HeadlenBuf); }
- ushort Reclen() const { return uint2korr(m_ReclenBuf); }
- ushort Fields() const { return uint2korr(m_FieldsBuf); }
-
- void SetHeadlen(ushort num) { int2store(m_HeadlenBuf, num); }
- void SetReclen(ushort num) { int2store(m_ReclenBuf, num); }
- void SetFields(ushort num) { int2store(m_FieldsBuf, num); }
+
+ uint Records(void) const {return uint4korr(m_RecordsBuf);}
+ ushort Headlen(void) const {return uint2korr(m_HeadlenBuf);}
+ ushort Reclen(void) const {return uint2korr(m_ReclenBuf);}
+ ushort Fields(void) const {return uint2korr(m_FieldsBuf);}
+
+ void SetHeadlen(ushort num) {int2store(m_HeadlenBuf, num);}
+ void SetReclen(ushort num) {int2store(m_ReclenBuf, num);}
+ void SetFields(ushort num) {int2store(m_FieldsBuf, num);}
} DBFHEADER;
/****************************************************************************/
@@ -410,13 +410,13 @@ int DBFBASE::ScanHeader(PGLOBAL g, PSZ fname, int lrecl, char *defpath)
} else if (rc == RC_FX)
return -1;
- if ((int) header.Reclen() != lrecl) {
+ if ((int)header.Reclen() != lrecl) {
sprintf(g->Message, MSG(BAD_LRECL), lrecl, header.Reclen());
return -1;
} // endif Lrecl
- Records = (int) header.Records();
- return (int) header.Headlen();
+ Records = (int)header.Records();
+ return (int)header.Headlen();
} // end of ScanHeader
/* ---------------------------- Class DBFFAM ------------------------------ */
@@ -528,7 +528,7 @@ bool DBFFAM::AllocateBuffer(PGLOBAL g)
To_Buf = (char*)PlugSubAlloc(g, NULL, Buflen);
if (mode == MODE_INSERT) {
-#if defined(WIN32)
+#if defined(__WIN__)
/************************************************************************/
/* Now we can revert to binary mode in particular because the eventual */
/* writing of a new header must be done in binary mode to avoid */
@@ -538,7 +538,7 @@ bool DBFFAM::AllocateBuffer(PGLOBAL g)
sprintf(g->Message, MSG(BIN_MODE_FAIL), strerror(errno));
return true;
} // endif setmode
-#endif // WIN32
+#endif // __WIN__
/************************************************************************/
/* If this is a new file, the header must be generated. */
@@ -577,8 +577,8 @@ bool DBFFAM::AllocateBuffer(PGLOBAL g)
header->Filedate[0] = datm->tm_year - 100;
header->Filedate[1] = datm->tm_mon + 1;
header->Filedate[2] = datm->tm_mday;
- header->SetHeadlen((ushort) hlen);
- header->SetReclen((ushort) reclen);
+ header->SetHeadlen((ushort)hlen);
+ header->SetReclen((ushort)reclen);
descp = (DESCRIPTOR*)header;
// Currently only standard Xbase types are supported
@@ -639,13 +639,13 @@ bool DBFFAM::AllocateBuffer(PGLOBAL g)
DBFHEADER header;
if ((rc = dbfhead(g, Stream, Tdbp->GetFile(g), &header)) == RC_OK) {
- if (Lrecl != (int) header.Reclen()) {
+ if (Lrecl != (int)header.Reclen()) {
sprintf(g->Message, MSG(BAD_LRECL), Lrecl, header.Reclen());
return true;
} // endif Lrecl
- Records = (int) header.Records();
- Headlen = (int) header.Headlen();
+ Records = (int)header.Records();
+ Headlen = (int)header.Headlen();
} else if (rc == RC_NF) {
Records = 0;
Headlen = 0;
@@ -881,9 +881,10 @@ void DBFFAM::CloseTableFile(PGLOBAL g, bool abort)
if ((Stream= global_fopen(g, MSGID_OPEN_MODE_STRERROR, filename, "r+b")))
{
char nRecords[4];
- int4store(&nRecords, n);
+ int4store(nRecords, n);
+
fseek(Stream, 4, SEEK_SET); // Get header.Records position
- fwrite(&nRecords, sizeof(nRecords), 1, Stream);
+ fwrite(nRecords, sizeof(nRecords), 1, Stream);
fclose(Stream);
Stream= NULL;
Records= n; // Update Records value
@@ -958,13 +959,13 @@ bool DBMFAM::AllocateBuffer(PGLOBAL g)
/************************************************************************/
DBFHEADER *hp = (DBFHEADER*)Memory;
- if (Lrecl != (int) hp->Reclen()) {
+ if (Lrecl != (int)hp->Reclen()) {
sprintf(g->Message, MSG(BAD_LRECL), Lrecl, hp->Reclen());
return true;
} // endif Lrecl
- Records = (int) hp->Records();
- Headlen = (int) hp->Headlen();
+ Records = (int)hp->Records();
+ Headlen = (int)hp->Headlen();
} // endif Headlen
/**************************************************************************/