Unverified Commit ed40d791 by Stéphane Graber Committed by GitHub

Merge pull request #2365 from brauner/2018-05-30/improve_strprint

confile: improve strprint()
parents 9715e65c 9496659c
...@@ -41,21 +41,24 @@ ...@@ -41,21 +41,24 @@
#define MACVLAN_MODE_PASSTHRU 8 #define MACVLAN_MODE_PASSTHRU 8
#endif #endif
#define strprint(str, inlen, ...) \ #define strprint(str, inlen, ...) \
do { \ do { \
len = snprintf(str, inlen, ##__VA_ARGS__); \ if (str) \
if (len < 0) { \ len = snprintf(str, inlen, ##__VA_ARGS__); \
SYSERROR("failed to create string"); \ else \
return -1; \ len = snprintf((char *){""}, 0, ##__VA_ARGS__); \
}; \ if (len < 0) { \
fulllen += len; \ SYSERROR("failed to create string"); \
if (inlen > 0) { \ return -1; \
if (str) \ }; \
str += len; \ fulllen += len; \
inlen -= len; \ if (inlen > 0) { \
if (inlen < 0) \ if (str) \
inlen = 0; \ str += len; \
} \ inlen -= len; \
if (inlen < 0) \
inlen = 0; \
} \
} while (0); } while (0);
extern int parse_idmaps(const char *idmap, char *type, unsigned long *nsid, extern int parse_idmaps(const char *idmap, char *type, unsigned long *nsid,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment