Debian Codegraph @

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

raw
1 /* Glue functions for the minIni library, based on the EFS Library, see
2 * https://sourceforge.net/projects/efsl/
3 *
4 * By CompuPhase, 2008-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 * (EFSL is copyright 2005-2006 Lennart Ysboodt and Michael De Nil, and
9 * licensed under the GPL with an exception clause for static linking.)
10 */
11
12 #define INI_BUFFERSIZE 256 /* maximum line length, maximum path length */
13 #define INI_LINETERM "\r\n" /* set line termination explicitly */
14
15 #include "efs.h"
16 extern EmbeddedFileSystem g_efs;
17
18 #define INI_FILETYPE EmbeddedFile
19 #define ini_openread(filename,file) (file_fopen((file), &g_efs.myFs, (char*)(filename), 'r') == 0)
20 #define ini_openwrite(filename,file) (file_fopen((file), &g_efs.myFs, (char*)(filename), 'w') == 0)
21 #define ini_close(file) file_fclose(file)
22 #define ini_read(buffer,size,file) (file_read((file), (size), (buffer)) > 0)
23 #define ini_write(buffer,file) (file_write((file), strlen(buffer), (char*)(buffer)) > 0)
24 #define ini_remove(filename) rmfile(&g_efs.myFs, (char*)(filename))
25
26 #define INI_FILEPOS euint32
27 #define ini_tell(file,pos) (*(pos) = (file)->FilePtr))
28 #define ini_seek(file,pos) file_setpos((file), (*pos))
29
30 #if ! defined INI_READONLY
31 /* EFSL lacks a rename function, so instead we copy the file to the new name
32 * and delete the old file
33 */
34 static int ini_rename(char *source, const char *dest)
35 {
36 EmbeddedFile fr, fw;
37 int n;
38
39 if (file_fopen(&fr, &g_efs.myFs, source, 'r') != 0)
40 return 0;
41 if (rmfile(&g_efs.myFs, (char*)dest) != 0)
42 return 0;
43 if (file_fopen(&fw, &g_efs.myFs, (char*)dest, 'w') != 0)
44 return 0;
45
46 /* With some "insider knowledge", we can save some memory: the "source"
47 * parameter holds a filename that was built from the "dest" parameter. It
48 * was built in buffer and this buffer has the size INI_BUFFERSIZE. We can
49 * reuse this buffer for copying the file.
50 */
51 while (n=file_read(&fr, INI_BUFFERSIZE, source))
52 file_write(&fw, n, source);
53
54 file_fclose(&fr);
55 file_fclose(&fw);
56
57 /* Now we need to delete the source file. However, we have garbled the buffer
58 * that held the filename of the source. So we need to build it again.
59 */
60 ini_tempname(source, dest, INI_BUFFERSIZE);
61 return rmfile(&g_efs.myFs, source) == 0;
62 }
63 #endif