diff options
author | Anil Madhavapeddy <avsm@cvs.openbsd.org> | 2004-06-22 03:15:34 +0000 |
---|---|---|
committer | Anil Madhavapeddy <avsm@cvs.openbsd.org> | 2004-06-22 03:15:34 +0000 |
commit | 812e4a0e725b5e54bed5fd8f4fb84a50f7d297e6 (patch) | |
tree | 5b29659ad1da2f08faf22d78cc007eb7f6823fe6 /usr.sbin/cron/misc.c | |
parent | 23f2f7013f3dee748995253841a77581c0454018 (diff) |
use snprintf(3) instead of home-grown glue_strings() function
millert@ ok
Diffstat (limited to 'usr.sbin/cron/misc.c')
-rw-r--r-- | usr.sbin/cron/misc.c | 47 |
1 files changed, 6 insertions, 41 deletions
diff --git a/usr.sbin/cron/misc.c b/usr.sbin/cron/misc.c index 017e8e0a7ce..565b51d9939 100644 --- a/usr.sbin/cron/misc.c +++ b/usr.sbin/cron/misc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: misc.c,v 1.30 2004/06/17 22:11:55 millert Exp $ */ +/* $OpenBSD: misc.c,v 1.31 2004/06/22 03:15:33 avsm Exp $ */ /* Copyright 1988,1990,1993,1994 by Paul Vixie * All rights reserved @@ -22,7 +22,7 @@ */ #if !defined(lint) && !defined(LINT) -static char const rcsid[] = "$OpenBSD: misc.c,v 1.30 2004/06/17 22:11:55 millert Exp $"; +static char const rcsid[] = "$OpenBSD: misc.c,v 1.31 2004/06/22 03:15:33 avsm Exp $"; #endif /* vix 26jan87 [RCS has the rest of the log] @@ -50,41 +50,6 @@ static int LogFD = ERR; static int syslog_open = FALSE; #endif -/* - * glue_strings is the overflow-safe equivalent of - * snprintf(buffer, buffer_size, "%s%c%s", a, separator, b); - * - * returns 1 on success, 0 on failure. 'buffer' MUST NOT be used if - * glue_strings fails. - */ -int -glue_strings(char *buffer, size_t buffer_size, const char *a, const char *b, - char separator) -{ - char *buf; - char *buf_end; - - if (buffer_size <= 0) - return (0); - buf_end = buffer + buffer_size; - buf = buffer; - - for ( /* nothing */; buf < buf_end && *a != '\0'; buf++, a++ ) - *buf = *a; - if (buf == buf_end) - return (0); - if (separator != '/' || buf == buffer || buf[-1] != '/') - *buf++ = separator; - if (buf == buf_end) - return (0); - for ( /* nothing */; buf < buf_end && *b != '\0'; buf++, b++ ) - *buf = *b; - if (buf == buf_end) - return (0); - *buf = '\0'; - return (1); -} - int strcmp_until(const char *left, const char *right, char until) { while (*left && *left != until && *left == *right) { @@ -769,8 +734,8 @@ open_socket() "can't make socket non-blocking"); exit(ERROR_EXIT); } - if (!glue_strings(s_un.sun_path, sizeof s_un.sun_path, SPOOL_DIR, - CRONSOCK, '/')) { + if (snprintf(s_un.sun_path, sizeof s_un.sun_path, "%s/%s", + SPOOL_DIR, CRONSOCK) >= sizeof(s_un.sun_path)) { fprintf(stderr, "%s/%s: path too long\n", SPOOL_DIR, CRONSOCK); log_it("CRON", getpid(), "DEATH", "path too long"); exit(ERROR_EXIT); @@ -811,8 +776,8 @@ poke_daemon(const char *spool_dir, unsigned char cookie) { return; } - if (glue_strings(s_un.sun_path, sizeof s_un.sun_path, SPOOL_DIR, - CRONSOCK, '/')) { + if (snprintf(s_un.sun_path, sizeof s_un.sun_path, "%s/%s", + SPOOL_DIR, CRONSOCK) >= sizeof(s_un.sun_path)) { s_un.sun_family = AF_UNIX; #ifdef SUN_LEN s_un.sun_len = SUN_LEN(&s_un); |