Debian Codegraph @

android/app/jni/extern/SAASound/src/minIni/minGlue-ccs.h

raw
1 /* minIni glue functions for FAT library by CCS, Inc. (as provided with their
2 * PIC MCU compiler)
3 *
4 * By CompuPhase, 2011-2012
5 * This "glue file" is in the public domain. It is distributed without
6 * warranties or conditions of any kind, either express or implied.
7 *
8 * (The FAT library is copyright (c) 2007 Custom Computer Services, and
9 * licensed at its own terms.)
10 */
11
12 #define INI_BUFFERSIZE 256 /* maximum line length, maximum path length */
13
14 #ifndef FAT_PIC_C
15 #error FAT library must be included before this module
16 #endif
17 #define const /* keyword not supported by CCS */
18
19 #define INI_FILETYPE FILE
20 #define ini_openread(filename,file) (fatopen((filename), "r", (file)) == GOODEC)
21 #define ini_openwrite(filename,file) (fatopen((filename), "w", (file)) == GOODEC)
22 #define ini_close(file) (fatclose((file)) == 0)
23 #define ini_read(buffer,size,file) (fatgets((buffer), (size), (file)) != NULL)
24 #define ini_write(buffer,file) (fatputs((buffer), (file)) == GOODEC)
25 #define ini_remove(filename) (rm_file((filename)) == 0)
26
27 #define INI_FILEPOS fatpos_t
28 #define ini_tell(file,pos) (fatgetpos((file), (pos)) == 0)
29 #define ini_seek(file,pos) (fatsetpos((file), (pos)) == 0)
30
31 #ifndef INI_READONLY
32 /* CCS FAT library lacks a rename function, so instead we copy the file to the
33 * new name and delete the old file
34 */
35 static int ini_rename(char *source, char *dest)
36 {
37 FILE fr, fw;
38 int n;
39
40 if (fatopen(source, "r", &fr) != GOODEC)
41 return 0;
42 if (rm_file(dest) != 0)
43 return 0;
44 if (fatopen(dest, "w", &fw) != GOODEC)
45 return 0;
46
47 /* With some "insider knowledge", we can save some memory: the "source"
48 * parameter holds a filename that was built from the "dest" parameter. It
49 * was built in a local buffer with the size INI_BUFFERSIZE. We can reuse
50 * this buffer for copying the file.
51 */
52 while (n=fatread(source, 1, INI_BUFFERSIZE, &fr))
53 fatwrite(source, 1, n, &fw);
54
55 fatclose(&fr);
56 fatclose(&fw);
57
58 /* Now we need to delete the source file. However, we have garbled the buffer
59 * that held the filename of the source. So we need to build it again.
60 */
61 ini_tempname(source, dest, INI_BUFFERSIZE);
62 return rm_file(source) == 0;
63 }
64 #endif