aboutsummaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
authorGravatar Carl Worth <cworth@cworth.org>2011-06-21 14:54:10 -0700
committerGravatar Carl Worth <cworth@cworth.org>2011-06-22 06:38:33 -0700
commitb0ba84f9e71b0f117dc0bdf0b790c6e2341d3949 (patch)
tree23e518cd1af6a199b16b9f4aac16c1133eb55658 /test
parent41a094624a079f4a145aba37e8059f8774dfaec6 (diff)
smtp-dummy: Prefer return rather than exit() in main.
The main() function should be written as just another function with a return value. This allows for more reliable code reuse. Imagine that main() grows too large and needs to be factored into multiple functions. At that point, exit() is probably the wrong thing, yet can also be hard to notice as it's in less-frequently-tested exceptional cases.
Diffstat (limited to 'test')
-rw-r--r--test/smtp-dummy.c18
1 files changed, 9 insertions, 9 deletions
diff --git a/test/smtp-dummy.c b/test/smtp-dummy.c
index 133d6c4e..9da8202f 100644
--- a/test/smtp-dummy.c
+++ b/test/smtp-dummy.c
@@ -127,7 +127,7 @@ main (int argc, char *argv[])
if (argc != 2) {
fprintf (stderr, "Usage: %s <output-file>\n", argv[0]);
- exit (1);
+ return 1;
}
output_filename = argv[1];
@@ -135,14 +135,14 @@ main (int argc, char *argv[])
if (output == NULL) {
fprintf (stderr, "Failed to open %s for writing: %s\n",
output_filename, strerror (errno));
- exit (1);
+ return 1;
}
sock = socket (AF_INET, SOCK_STREAM, 0);
if (sock == -1) {
fprintf (stderr, "Error: socket() failed: %s\n",
strerror (errno));
- exit (1);
+ return 1;
}
reuse = 1;
@@ -150,13 +150,13 @@ main (int argc, char *argv[])
if (err) {
fprintf (stderr, "Error: setsockopt() failed: %s\n",
strerror (errno));
- exit (1);
+ return 1;
}
hostinfo = gethostbyname ("localhost");
if (hostinfo == NULL) {
fprintf (stderr, "Unknown host: localhost\n");
- exit (1);
+ return 1;
}
addr.sin_family = AF_INET;
@@ -167,7 +167,7 @@ main (int argc, char *argv[])
fprintf (stderr, "Error: bind() failed: %s\n",
strerror (errno));
close (sock);
- exit (1);
+ return 1;
}
err = listen (sock, 1);
@@ -175,7 +175,7 @@ main (int argc, char *argv[])
fprintf (stderr, "Error: listen() failed: %s\n",
strerror (errno));
close (sock);
- exit (1);
+ return 1;
}
peer_addr_len = sizeof (peer_addr);
@@ -183,14 +183,14 @@ main (int argc, char *argv[])
if (peer == -1) {
fprintf (stderr, "Error: accept() failed: %s\n",
strerror (errno));
- exit (1);
+ return 1;
}
peer_file = fdopen (peer, "w+");
if (peer_file == NULL) {
fprintf (stderr, "Error: fdopen() failed: %s\n",
strerror (errno));
- exit (1);
+ return 1;
}
do_smtp_to_file (peer_file, output);