Skip to content

Commit b40dff4

Browse files
committed
Replace calls to strrchr() by strchr() when searching for the '\0' string terminator.
Minor updates (mostly comments) in a few example glue files.
1 parent e115772 commit b40dff4

File tree

4 files changed

+21
-12
lines changed

4 files changed

+21
-12
lines changed

dev/minGlue-FatFs.h

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* Glue functions for the minIni library, based on the FatFs and Petit-FatFs
22
* libraries, see http://elm-chan.org/fsw/ff/00index_e.html
33
*
4-
* By CompuPhase, 2008-2012
4+
* By CompuPhase, 2008-2019
55
* This "glue file" is in the public domain. It is distributed without
66
* warranties or conditions of any kind, either express or implied.
77
*
@@ -11,16 +11,24 @@
1111

1212
#define INI_BUFFERSIZE 256 /* maximum line length, maximum path length */
1313

14-
/* You must set _USE_STRFUNC to 1 or 2 in the include file ff.h (or tff.h)
14+
/* You must set FF_USE_STRFUNC to 1 or 2 in the include file ff.h (or tff.h)
1515
* to enable the "string functions" fgets() and fputs().
1616
*/
1717
#include "ff.h" /* include tff.h for Tiny-FatFs */
1818

19+
/* When setting FF_USE_STRFUNC to 2 (for LF to CR/LF translation), INI_LINETERM
20+
* should be defined to "\n" (otherwise "\r\n" will be translated by FatFS to
21+
* "\r\r\n").
22+
*/
23+
#if defined FF_USE_STRFUNC && FF_USE_STRFUNC == 2 && !defined INI_LINETERM
24+
#define INI_LINETERM "\n"
25+
#endif
26+
1927
#define INI_FILETYPE FIL
2028
#define ini_openread(filename,file) (f_open((file), (filename), FA_READ+FA_OPEN_EXISTING) == FR_OK)
2129
#define ini_openwrite(filename,file) (f_open((file), (filename), FA_WRITE+FA_CREATE_ALWAYS) == FR_OK)
2230
#define ini_close(file) (f_close(file) == FR_OK)
23-
#define ini_read(buffer,size,file) f_gets((buffer), (size),(file))
31+
#define ini_read(buffer,size,file) f_gets((buffer), (size), (file))
2432
#define ini_write(buffer,file) f_puts((buffer), (file))
2533
#define ini_remove(filename) (f_unlink(filename) == FR_OK)
2634

dev/minGlue-efsl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* Glue functions for the minIni library, based on the EFS Library, see
2-
* http://www.efsl.be/
2+
* https://sourceforge.net/projects/efsl/
33
*
44
* By CompuPhase, 2008-2012
55
* This "glue file" is in the public domain. It is distributed without

dev/minGlue-ffs.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
/* Glue functions for the minIni library, based on the "FAT Filing System"
2-
* library by embedded-code.com
2+
* library by embedded-code.com, now IBEX UK.
3+
* https://github.com/ibexuk/C_Memory_SD_Card_FAT_Driver
34
*
45
* By CompuPhase, 2008-2012
56
* This "glue file" is in the public domain. It is distributed without
67
* warranties or conditions of any kind, either express or implied.
78
*
8-
* (The "FAT Filing System" library itself is copyright embedded-code.com, and
9-
* licensed at its own terms.)
9+
* (The "FAT Filing System" library itself is copyright IBEX UK, and licensed
10+
* at its own terms.)
1011
*/
1112

1213
#define INI_BUFFERSIZE 256 /* maximum line length, maximum path length */

dev/minIni.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ int ini_getkey(const TCHAR *Section, int idx, TCHAR *Buffer, int BufferSize, co
460460
* callback stops the browsing, this function will return 1
461461
* (for success).
462462
*/
463-
int ini_browse(INI_CALLBACK Callback, void *UserData, const TCHAR *Filename)
463+
int ini_browse(INI_CALLBACK Callback, void *UserData, const TCHAR *Filename)
464464
{
465465
TCHAR LocalBuffer[INI_BUFFERSIZE];
466466
int lenSec, lenKey;
@@ -520,7 +520,7 @@ static void ini_tempname(TCHAR *dest, const TCHAR *source, int maxlength)
520520
TCHAR *p;
521521

522522
ini_strncpy(dest, source, maxlength, QUOTE_NONE);
523-
p = _tcsrchr(dest, '\0');
523+
p = _tcschr(dest, '\0');
524524
assert(p != NULL);
525525
*(p - 1) = '~';
526526
}
@@ -544,7 +544,7 @@ static void writesection(TCHAR *LocalBuffer, const TCHAR *Section, INI_FILETYPE
544544
TCHAR *p;
545545
LocalBuffer[0] = '[';
546546
ini_strncpy(LocalBuffer + 1, Section, INI_BUFFERSIZE - 4, QUOTE_NONE); /* -1 for '[', -1 for ']', -2 for '\r\n' */
547-
p = _tcsrchr(LocalBuffer, '\0');
547+
p = _tcschr(LocalBuffer, '\0');
548548
assert(p != NULL);
549549
*p++ = ']';
550550
_tcscpy(p, INI_LINETERM); /* copy line terminator (typically "\n") */
@@ -558,11 +558,11 @@ static void writekey(TCHAR *LocalBuffer, const TCHAR *Key, const TCHAR *Value, I
558558
TCHAR *p;
559559
enum quote_option option = check_enquote(Value);
560560
ini_strncpy(LocalBuffer, Key, INI_BUFFERSIZE - 3, QUOTE_NONE); /* -1 for '=', -2 for '\r\n' */
561-
p = _tcsrchr(LocalBuffer, '\0');
561+
p = _tcschr(LocalBuffer, '\0');
562562
assert(p != NULL);
563563
*p++ = '=';
564564
ini_strncpy(p, Value, INI_BUFFERSIZE - (p - LocalBuffer) - 2, option); /* -2 for '\r\n' */
565-
p = _tcsrchr(LocalBuffer, '\0');
565+
p = _tcschr(LocalBuffer, '\0');
566566
assert(p != NULL);
567567
_tcscpy(p, INI_LINETERM); /* copy line terminator (typically "\n") */
568568
if (fp != NULL)

0 commit comments

Comments
 (0)