PostGIS  3.4.0dev-r@@SVN_REVISION@@

◆ DBFWriteHeader()

static void DBFWriteHeader ( DBFHandle  psDBF)
static

Definition at line 127 of file dbfopen.c.

129 {
130  unsigned char abyHeader[XBASE_FILEHDR_SZ] = { 0 };
131 
132  if( !psDBF->bNoHeader )
133  return;
134 
135  psDBF->bNoHeader = FALSE;
136 
137 /* -------------------------------------------------------------------- */
138 /* Initialize the file header information. */
139 /* -------------------------------------------------------------------- */
140  abyHeader[0] = 0x03; /* memo field? - just copying */
141 
142  /* write out update date */
143  abyHeader[1] = STATIC_CAST(unsigned char, psDBF->nUpdateYearSince1900);
144  abyHeader[2] = STATIC_CAST(unsigned char, psDBF->nUpdateMonth);
145  abyHeader[3] = STATIC_CAST(unsigned char, psDBF->nUpdateDay);
146 
147  /* record count preset at zero */
148 
149  abyHeader[8] = STATIC_CAST(unsigned char, psDBF->nHeaderLength % 256);
150  abyHeader[9] = STATIC_CAST(unsigned char, psDBF->nHeaderLength / 256);
151 
152  abyHeader[10] = STATIC_CAST(unsigned char, psDBF->nRecordLength % 256);
153  abyHeader[11] = STATIC_CAST(unsigned char, psDBF->nRecordLength / 256);
154 
155  abyHeader[29] = STATIC_CAST(unsigned char, psDBF->iLanguageDriver);
156 
157 /* -------------------------------------------------------------------- */
158 /* Write the initial 32 byte file header, and all the field */
159 /* descriptions. */
160 /* -------------------------------------------------------------------- */
161  psDBF->sHooks.FSeek( psDBF->fp, 0, 0 );
162  psDBF->sHooks.FWrite( abyHeader, XBASE_FILEHDR_SZ, 1, psDBF->fp );
163  psDBF->sHooks.FWrite( psDBF->pszHeader, XBASE_FLDHDR_SZ, psDBF->nFields,
164  psDBF->fp );
165 
166 /* -------------------------------------------------------------------- */
167 /* Write out the newline character if there is room for it. */
168 /* -------------------------------------------------------------------- */
169  if( psDBF->nHeaderLength > XBASE_FLDHDR_SZ*psDBF->nFields +
171  {
172  char cNewline;
173 
174  cNewline = HEADER_RECORD_TERMINATOR;
175  psDBF->sHooks.FWrite( &cNewline, 1, 1, psDBF->fp );
176  }
177 
178 /* -------------------------------------------------------------------- */
179 /* If the file is new, add a EOF character. */
180 /* -------------------------------------------------------------------- */
181  if( psDBF->nRecords == 0 && psDBF->bWriteEndOfFileChar )
182  {
183  char ch = END_OF_FILE_CHARACTER;
184 
185  psDBF->sHooks.FWrite( &ch, 1, 1, psDBF->fp );
186  }
187 }
#define STATIC_CAST(type, x)
Definition: dbfopen.c:96
#define HEADER_RECORD_TERMINATOR
Definition: dbfopen.c:79
#define XBASE_FILEHDR_SZ
Definition: dbfopen.c:77
#define FALSE
Definition: dbfopen.c:72
#define END_OF_FILE_CHARACTER
Definition: dbfopen.c:82
#define XBASE_FLDHDR_SZ
Definition: shapefil.h:648
int nUpdateDay
Definition: shapefil.h:629
int bWriteEndOfFileChar
Definition: shapefil.h:631
int nRecordLength
Definition: shapefil.h:596
int nUpdateMonth
Definition: shapefil.h:628
int nFields
Definition: shapefil.h:600
int nHeaderLength
Definition: shapefil.h:597
char * pszHeader
Definition: shapefil.h:606
int nUpdateYearSince1900
Definition: shapefil.h:627
SAFile fp
Definition: shapefil.h:592
SAHooks sHooks
Definition: shapefil.h:590
int bNoHeader
Definition: shapefil.h:615
int iLanguageDriver
Definition: shapefil.h:624
int nRecords
Definition: shapefil.h:594
SAOffset(* FWrite)(void *p, SAOffset size, SAOffset nmemb, SAFile file)
Definition: shapefil.h:292
SAOffset(* FSeek)(SAFile file, SAOffset offset, int whence)
Definition: shapefil.h:293

References DBFInfo::bNoHeader, DBFInfo::bWriteEndOfFileChar, END_OF_FILE_CHARACTER, FALSE, DBFInfo::fp, SAHooks::FSeek, SAHooks::FWrite, HEADER_RECORD_TERMINATOR, DBFInfo::iLanguageDriver, DBFInfo::nFields, DBFInfo::nHeaderLength, DBFInfo::nRecordLength, DBFInfo::nRecords, DBFInfo::nUpdateDay, DBFInfo::nUpdateMonth, DBFInfo::nUpdateYearSince1900, DBFInfo::pszHeader, DBFInfo::sHooks, STATIC_CAST, XBASE_FILEHDR_SZ, and XBASE_FLDHDR_SZ.

Referenced by DBFCloneEmpty(), DBFClose(), DBFUpdateHeader(), DBFWriteAttribute(), DBFWriteAttributeDirectly(), and DBFWriteTuple().

Here is the caller graph for this function: