check for the return values
committer: Markus Bröker <mbroeker@largo.homelinux.org>
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,7 @@
CC = gcc -g -ggdb $(PROF)
CPP = g++ -g -ggdb $(PROF)
CFLAGS = -Wall -O2 -Iinclude $(EXTRA)
- EXTRA = -D_XOPEN_SOURCE
+ EXTRA =
LDFLAGS = -L/usr/lib
RM = rm -f
FIND = find
--- a/connection.c
+++ b/connection.c
@@ -67,7 +67,10 @@
return EXIT_FAILURE;
}
- write (sockfd, "GET /\r\n", 7);
+ if (write (sockfd, "GET /\r\n", 7) == -1) {
+ perror ("write");
+ return EXIT_FAILURE;
+ }
while ((num = read (sockfd, buffer, 1023)) != 0) {
buffer[num] = 0;
--- a/counter.c
+++ b/counter.c
@@ -25,7 +25,9 @@
start = time_str->tm_hour * 60 * 60 + time_str->tm_min * 60 + time_str->tm_sec;
- system (argv[1]);
+ if (system (argv[1]) == -1) {
+ return EXIT_FAILURE;
+ }
time (&t);
time_str = gmtime (&t);
--- a/crypt.c
+++ b/crypt.c
@@ -3,6 +3,8 @@
* Copyright (C) 2008 Markus Broeker
*/
+#define _XOPEN_SOURCE 500
+
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
--- a/daemon.c
+++ b/daemon.c
@@ -32,7 +32,8 @@
strftime (time_stamp, sizeof (time_stamp), "%a %d %T", localtime (&t));
len = snprintf (response, sizeof (response), "%s %s", time_stamp, buffer);
- write (fd, response, len);
+ if (write (fd, response, len) == -1)
+ perror ("write");
}
void sigproc ()
@@ -80,7 +81,10 @@
sanity_check (argc, argv);
- daemon (0, 0);
+ if (daemon (0, 0) == -1) {
+ perror ("daemon");
+ return EXIT_FAILURE;
+ }
signal (SIGTERM, sigproc);
for (;;) {
--- a/file_demo.c
+++ b/file_demo.c
@@ -22,8 +22,10 @@
return -1;
mode = strtoul (argv[1], NULL, 8);
- system ("/bin/rm -f /home/mbroeker/Desktop/test1.txt");
- system ("/bin/rm -f /home/mbroeker/Desktop/test2.txt");
+ if (system ("/bin/rm -f /home/mbroeker/Desktop/test1.txt") != 0)
+ return EXIT_FAILURE;
+ if (system ("/bin/rm -f /home/mbroeker/Desktop/test2.txt") != 0)
+ return EXIT_FAILURE;
/*
* Opens ReadOnly
--- a/files.c
+++ b/files.c
@@ -58,7 +58,8 @@
}
close (fd);
}
- chdir ("..");
+ if (chdir ("..") == -1)
+ break;
}
return EXIT_SUCCESS;
}
--- a/recursive_compiler.c
+++ b/recursive_compiler.c
@@ -98,7 +98,8 @@
int main (int argc, char **argv)
{
printf ("Bitte geben Sie einen Ausdruck in Infix-Notation ein:\n\n\t");
- fgets (expression, MAX, stdin);
+ if (fgets (expression, MAX, stdin) == NULL)
+ return EXIT_FAILURE;
printf ("\nCompilierter Ausdruck in Postfix-Notation:\n\n\t");
compile_mode = MODE_POSTFIX;