freemyipod r52 - Code Review

Jump to: navigation, search
Repository:freemyipod
Revision:r51‎ | r52 | r53 >
Date:16:35, 7 August 2010
Author:theseven
Status:new
Tags:
Comment:
Clean up printf function attributes
Modified paths:
  • /embios/trunk/console.h (modified) (history)
  • /embios/trunk/file.c (modified) (history)
  • /embios/trunk/gcc_extensions.h (added) (history)
  • /embios/trunk/panic.h (modified) (history)
  • /embios/trunk/snprintf.c (modified) (history)
  • /embios/trunk/snprintf.h (modified) (history)

Diff [purge]

Index: embios/trunk/snprintf.c
@@ -34,7 +34,8 @@
3535 #include "format.h"
3636
3737
38 -struct for_snprintf {
 38+struct for_snprintf
 39+{
3940 unsigned char *ptr; /* where to store it */
4041 size_t bytes; /* amount already stored */
4142 size_t max; /* max amount to store */
@@ -43,7 +44,8 @@
4445 static int sprfunc(void *ptr, unsigned char letter)
4546 {
4647 struct for_snprintf *pr = (struct for_snprintf *)ptr;
47 - if(pr->bytes < pr->max) {
 48+ if(pr->bytes < pr->max)
 49+ {
4850 *pr->ptr = letter;
4951 pr->ptr++;
5052 pr->bytes++;
Index: embios/trunk/console.h
@@ -26,6 +26,7 @@
2727
2828
2929 #include "global.h"
 30+#include "gcc_extensions.h"
3031 #include <stdarg.h>
3132
3233
@@ -33,7 +34,8 @@
3435 void cputc(unsigned int consoles, char string) ICODE_ATTR;
3536 void cputs(unsigned int consoles, const char* string) ICODE_ATTR;
3637 void cwrite(unsigned int consoles, const char* string, size_t length) ICODE_ATTR;
37 -int cprintf(unsigned int consoles, const char* fmt, ...) ICODE_ATTR;
 38+int cprintf(unsigned int consoles, const char* fmt, ...) ICODE_ATTR
 39+ ATTRIBUTE_PRINTF(2, 3);
3840 int cvprintf(unsigned int consoles, const char* fmt, va_list ap) ICODE_ATTR;
3941 void cflush(unsigned int consoles) ICODE_ATTR;
4042 int cgetc(unsigned int consoles, int timeout) ICODE_ATTR;
Index: embios/trunk/snprintf.h
@@ -25,15 +25,14 @@
2626 #define __SNPRINTF_H__
2727
2828
29 -#define __need___va_list
 29+#include "global.h"
 30+#include "gcc_extensions.h"
3031 #include <stdarg.h>
31 -#include "global.h"
3232
3333
34 -int vsnprintf (char *buf, size_t size, const char *fmt, __VALIST ap);
 34+int vsnprintf(char *buf, size_t size, const char *fmt, va_list ap);
3535
36 -int snprintf (char *buf, size_t size, const char *fmt, ...)
37 - ATTRIBUTE_PRINTF(3, 4);
 36+int snprintf(char *buf, size_t size, const char *fmt, ...) ATTRIBUTE_PRINTF(3, 4);
3837
3938
4039 #endif
Index: embios/trunk/panic.h
@@ -26,6 +26,8 @@
2727
2828
2929 #include "global.h"
 30+#include "gcc_extensions.h"
 31+#include <stdarg.h>
3032
3133
3234 enum panic_severity
@@ -37,7 +39,8 @@
3840
3941
4042 void panic(enum panic_severity severity, const char* string) ICODE_ATTR;
41 -void panicf(enum panic_severity severity, const char* string, ...) ICODE_ATTR;
 43+void panicf(enum panic_severity severity, const char* string, ...) ICODE_ATTR
 44+ ATTRIBUTE_PRINTF(2, 3);
4245
4346
4447 #endif
Index: embios/trunk/file.c
@@ -18,16 +18,15 @@
1919 * KIND, either express or implied.
2020 *
2121 ****************************************************************************/
 22+#include "global.h"
2223 #include <string.h>
2324 #include <errno.h>
24 -#include <stdbool.h>
2525 #include "file.h"
2626 #include "fat.h"
2727 #include "dir.h"
2828 #include "debug.h"
29 -#include "dircache.h"
3029 #include "filefuncs.h"
31 -#include "system.h"
 30+#include "gcc_extensions.h"
3231
3332 /*
3433 These functions provide a roughly POSIX-compatible file IO API.
Index: embios/trunk/gcc_extensions.h
@@ -0,0 +1,46 @@
 2+/***************************************************************************
 3+ * __________ __ ___.
 4+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
 5+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
 6+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
 7+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
 8+ * \/ \/ \/ \/ \/
 9+ *
 10+ * Copyright © 2010 Rafaël Carré
 11+ *
 12+ * This program is free software; you can redistribute it and/or
 13+ * modify it under the terms of the GNU General Public License
 14+ * as published by the Free Software Foundation; either version 2
 15+ * of the License, or (at your option) any later version.
 16+ *
 17+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
 18+ * KIND, either express or implied.
 19+ *
 20+ ****************************************************************************/
 21+
 22+#ifndef __GCC_EXTENSIONS_H__
 23+#define __GCC_EXTENSIONS_H__
 24+
 25+/* Support for some GCC extensions */
 26+
 27+/* Compile time check of format for printf/scanf like functions */
 28+#ifdef __GNUC__
 29+#define ATTRIBUTE_PRINTF(fmt, arg1) __attribute__( ( format( printf, fmt, arg1 ) ) )
 30+#define ATTRIBUTE_SCANF(fmt, arg1) __attribute__( ( format( scanf, fmt, arg1 ) ) )
 31+#else
 32+#define ATTRIBUTE_PRINTF(fmt, arg1)
 33+#define ATTRIBUTE_SCANF(fmt, arg1)
 34+#endif
 35+
 36+
 37+/* Use to give gcc hints on which branch is most likely taken */
 38+#if defined(__GNUC__) && __GNUC__ >= 3
 39+#define LIKELY(x) __builtin_expect(!!(x), 1)
 40+#define UNLIKELY(x) __builtin_expect(!!(x), 0)
 41+#else
 42+#define LIKELY(x) (x)
 43+#define UNLIKELY(x) (x)
 44+#endif
 45+
 46+
 47+#endif /* _GCC_EXTENSIONS_H_ */
Property changes on: embios/trunk/gcc_extensions.h
___________________________________________________________________
Added: svn:mergeinfo
## -0,0 +0,1 ##
148 Merged /embios/trunk/gcc_extensions.h:r18-19