diff options
author | Denis Fondras <denis@cvs.openbsd.org> | 2024-08-17 15:42:21 +0000 |
---|---|---|
committer | Denis Fondras <denis@cvs.openbsd.org> | 2024-08-17 15:42:21 +0000 |
commit | 0d9efc6deb832c398ac169a2ed68760c58eb758e (patch) | |
tree | 89805b919f308d0164d9839e99061ba289a3f815 /usr.sbin | |
parent | ec86af961558d8113ae0b25229e36cf2822e9c70 (diff) |
Replace homemade copy_of() with strdup()
OK tb@
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/pppd/chat/chat.c | 30 |
1 files changed, 9 insertions, 21 deletions
diff --git a/usr.sbin/pppd/chat/chat.c b/usr.sbin/pppd/chat/chat.c index c574a3f1327..058211a3eb3 100644 --- a/usr.sbin/pppd/chat/chat.c +++ b/usr.sbin/pppd/chat/chat.c @@ -1,4 +1,4 @@ -/* $OpenBSD: chat.c,v 1.37 2024/08/10 05:32:28 jsg Exp $ */ +/* $OpenBSD: chat.c,v 1.38 2024/08/17 15:42:20 denis Exp $ */ /* * Chat -- a program for automatic session establishment (i.e. dial @@ -172,7 +172,6 @@ int clear_report_next = 0; int say_next = 0, hup_next = 0; -void *dup_mem(void *b, size_t c); void usage(void); void logmsg(const char *fmt, ...); void fatal(int code, const char *fmt, ...); @@ -204,22 +203,6 @@ int vfmtmsg(char *, int, const char *, va_list); /* vsnprintf++ */ int main(int, char *[]); -void * -dup_mem(void *b, size_t c) -{ - void *ans = malloc (c); - if (!ans) - fatal(2, "memory error!"); - - memcpy (ans, b, c); - return ans; -} - -void *copy_of (char *s) -{ - return dup_mem (s, strlen (s) + 1); -} - /* * chat [ -v ] [-T number] [-U number] [ -t timeout ] [ -f chat-file ] \ * [ -r report-file ] \ @@ -257,7 +240,8 @@ main(int argc, char **argv) break; case 'f': - chat_file = strdup(optarg); + if ((chat_file = strdup(optarg)) == NULL) + fatal(2, "memory error!"); break; case 't': @@ -267,7 +251,8 @@ main(int argc, char **argv) case 'r': if (report_fp != NULL) fclose (report_fp); - report_file = copy_of (optarg); + if ((report_file = strdup(optarg)) == NULL) + fatal(2, "memory error!"); report_fp = fopen (report_file, "a"); if (report_fp != NULL) { if (verbose) @@ -278,11 +263,14 @@ main(int argc, char **argv) break; case 'T': - phone_num = strdup(optarg); + if ((phone_num = strdup(optarg)) == NULL) + fatal(2, "memory error!"); break; case 'U': phone_num2 = strdup(optarg); + if ((phone_num2 = strdup(optarg)) == NULL) + fatal(2, "memory error!"); break; case ':': |