[DRBD-cvs] user by phil; Clifford provided an improved version of...

drbd-user@lists.linbit.com drbd-user@lists.linbit.com
Mon, 9 Feb 2004 12:15:54 +0100 (CET)


DRBD CVS committal

Author  : phil
Project : drbd
Module  : user

Dir     : drbd/user


Modified Files:
      Tag: rel-0_7-branch
	drbdadm.h drbdadm_main.c 


Log Message:
Clifford provided an improved version of the ssprintf(...) macro

===================================================================
RCS file: /var/lib/cvs/drbd/drbd/user/Attic/drbdadm.h,v
retrieving revision 1.1.2.15
retrieving revision 1.1.2.16
diff -u -3 -r1.1.2.15 -r1.1.2.16
--- drbdadm.h	15 Dec 2003 15:25:53 -0000	1.1.2.15
+++ drbdadm.h	9 Feb 2004 11:15:49 -0000	1.1.2.16
@@ -58,14 +58,15 @@
 
 extern int dry_run;
 extern char* drbdsetup;
-extern char ss_buffer[255];
 
 /* ssprintf() places the result of the printf in the current stack
    frame and sets ptr to the resulting string. If the current stack
    frame is destroyed (=function returns), the allocated memory is
    freed automatically */
 
-#define ssprintf(ptr,...) \
-  ptr=strcpy(alloca(snprintf(ss_buffer,255,##__VA_ARGS__)+1),ss_buffer)
-
+#define ssprintf(...) \
+         ({ int _ss_size = snprintf(0, 0, ##__VA_ARGS__);        \
+         char *_ss_ret = __builtin_alloca(_ss_size+1);           \
+         snprintf(_ss_ret, _ss_size+1, ##__VA_ARGS__);           \
+         _ss_ret; })
 #endif
===================================================================
RCS file: /var/lib/cvs/drbd/drbd/user/Attic/drbdadm_main.c,v
retrieving revision 1.1.2.30
retrieving revision 1.1.2.31
diff -u -3 -r1.1.2.30 -r1.1.2.31
--- drbdadm_main.c	6 Feb 2004 15:43:55 -0000	1.1.2.30
+++ drbdadm_main.c	9 Feb 2004 11:15:49 -0000	1.1.2.31
@@ -84,7 +84,6 @@
 static int sh_mod_parms(struct d_resource* ,char* );
 static int sh_ll_dev(struct d_resource* ,char* );
 
-char ss_buffer[255];
 int line=1;
 struct d_globals global_options = { 0, 0 };
 char *config_file = NULL;