Browse Source

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)
master
Felix von Leitner 7 years ago
parent
commit
f2b0c2fb95
  1. 8
      buffer.h
  2. 1
      buffer/buffer_puts.c
  3. 1
      buffer/buffer_putsflush.c

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
buffer/buffer_puts.c

@ -1,3 +1,4 @@
#define __LIBOWFAT_INTERNAL
#include "str.h"
#include "buffer.h"

1
buffer/buffer_putsflush.c

@ -1,3 +1,4 @@
#define __LIBOWFAT_INTERNAL
#include "str.h"
#include "buffer.h"

Loading…
Cancel
Save