Version 6.3
Copyright © 2005 - 2012 Lowell D. Thomas
APG
  … ABNF Parser Generator
All Data Structures Files Functions Variables Typedefs Macros Pages
Files.c
Go to the documentation of this file.
1 /*******************************************************************************
2  APG Version 6.3
3  Copyright (C) 2005 - 2012 Lowell D. Thomas, all rights reserved
4 
5  author: Lowell D. Thomas
6  email: lowell@coasttocoastresearch.com
7  website: http://www.coasttocoastresearch.com
8 
9  This program is free software: you can redistribute it and/or modify
10  it under the terms of the GNU General Public License as published by
11  the Free Software Foundation, either version 2 of the License, or
12  (at your option) any later version.
13 
14  This program is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with this program. If not, see
21  <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>
22  or write to the Free Software Foundation, Inc.,
23  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 *******************************************************************************/
25 
26 #include "ApgUtilities.h"
27 
30 // FILE HELPERS
33 
40 apg_uint uiGetFileSize(const char* cpFileName)
41 {
42  FILE* spFile = NULL;
43  int iTest;
44  apg_uint uiReturn = 0;
45  apg_uint uiLen;
46 
47 
48  while(APG_TRUE)
49  {
50  spFile = fopen(cpFileName, "rb");
51  if(!spFile){break;}
52  iTest = fseek(spFile, 0, SEEK_END);
53  if(iTest != 0){break;}
54  uiLen = ftell(spFile);
55 
56  // success
57  uiReturn = uiLen;
58  break;
59  }
60 
61  if(spFile){fclose(spFile);}
62  return uiReturn;
63 }
64 
71 apg_uint uiGetFile(const char* cpFileName, void* vpBuffer)
72 {
73  apg_uint uiSize;
74  FILE* spFile = NULL;
75  int iTest;
76  apg_uint uiReturn = 0;
77  apg_uint uiLen;
78 
79 
80 
81  while(APG_TRUE)
82  {
83  spFile = fopen(cpFileName, "rb");
84  if(!spFile){break;}
85  iTest = fseek(spFile, 0, SEEK_END);
86  if(iTest != 0){break;}
87  uiLen = ftell(spFile);
88  iTest = fseek(spFile, 0, SEEK_SET);
89  if(iTest != 0){break;}
90  uiSize = fread(vpBuffer, 1, uiLen, spFile);
91  if(uiSize != uiLen){break;}
92 
93  // success
94  uiReturn = uiLen;
95  break;
96  }
97 
98  if(spFile){fclose(spFile);}
99  return uiReturn;
100 }
101 
108 apg_uint uiWriteFile(const char* cpFileName, void* vpData, apg_uint uiDataLen)
109 {
110  apg_uint uiReturn = 0;
111  FILE* spFile = NULL;
112  apg_uint uiBytesWritten = 0;
113 
114 
115  while(APG_TRUE)
116  {
117  // validate
118  if(!vpData){break;}
119  if(uiDataLen ==0){break;}
120 
121  // open the file
122  spFile = fopen(cpFileName, "wb");
123  if(!spFile){break;}
124 
125  // write the data
126  uiBytesWritten = fwrite(vpData, 1, uiDataLen, spFile);
127  if(uiBytesWritten != uiDataLen){break;}
128 
129  // success
130  uiReturn = uiDataLen;
131  break;
132  }
133 
134  if(spFile){fclose(spFile);}
135  return uiReturn;
136 }
137 
139 void vJavaScriptApgBytes(FILE* in, FILE* out)
140 {
141  int c;
142  int count = 0;
143  while(1)
144  {
145  c = getc(in);
146  if(c == EOF){break;}
147  fprintf(out, "0x%02X ", c);
148  count++;
149  if(count > 8)
150  {
151  fprintf(out, "\n");
152  count = 0;
153  }
154  }
155 }
uiGetFile
apg_uint uiGetFile(const char *cpFileName, void *vpBuffer)
Definition: Files.c:71
apg_uint
unsigned int apg_uint
Definition: Apg.h:169
uiWriteFile
apg_uint uiWriteFile(const char *cpFileName, void *vpData, apg_uint uiDataLen)
Definition: Files.c:108
APG_TRUE
#define APG_TRUE
Definition: Apg.h:187
ApgUtilities.h
Declarations of all APG utility functions.
uiGetFileSize
apg_uint uiGetFileSize(const char *cpFileName)
Definition: Files.c:40
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/licenses.html or write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.