use gcc magic and a #define to convert buffer_puts to buffer_put if the
string argument length is known at compile time (same for buffer_putsflush)
This commit is contained in:
parent
fce165fdcb
commit
214ad3a92e
8
buffer.h
8
buffer.h
@ -43,6 +43,14 @@ int buffer_puts(buffer* b,const char* x);
|
||||
int buffer_putsalign(buffer* b,const char* x);
|
||||
int buffer_putsflush(buffer* b,const char* x);
|
||||
|
||||
#if defined(__GNUC__) && !defined(__LIBOWFAT_INTERNAL)
|
||||
/* as a little gcc-specific hack, if somebody calls buffer_puts with a
|
||||
* constant string, where we know its length at compile-time, call
|
||||
* buffer_put with the known length instead */
|
||||
#define buffer_puts(b,s) (__builtin_constant_p(s) ? buffer_put(b,s,sizeof(s)-1) : buffer_puts(b,s))
|
||||
#define buffer_putsflush(b,s) (__builtin_constant_p(s) ? buffer_putflush(b,s,sizeof(s)-1) : buffer_putsflush(b,s))
|
||||
#endif
|
||||
|
||||
int buffer_putm_internal(buffer*b,...);
|
||||
int buffer_putm_internal_flush(buffer*b,...);
|
||||
#define buffer_putm(b,...) buffer_putm_internal(b,__VA_ARGS__,(char*)0)
|
||||
|
@ -1,3 +1,4 @@
|
||||
#define __LIBOWFAT_INTERNAL
|
||||
#include "str.h"
|
||||
#include "buffer.h"
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
#define __LIBOWFAT_INTERNAL
|
||||
#include "str.h"
|
||||
#include "buffer.h"
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user