diff options
Diffstat (limited to '')
-rw-r--r-- | src/utils.c | 94 |
1 files changed, 47 insertions, 47 deletions
diff --git a/src/utils.c b/src/utils.c index a457857..4f1df87 100644 --- a/src/utils.c +++ b/src/utils.c @@ -35,7 +35,7 @@ */ int send_http_message (struct conn_s *connptr, int http_code, - const char *error_title, const char *message) + const char *error_title, const char *message) { static char *headers[] = { "Server: " PACKAGE "/" VERSION, @@ -78,12 +78,12 @@ create_file_safely (const char *filename, unsigned int truncate_file) * existing", exit. */ if (errno != ENOENT) - { - fprintf (stderr, - "%s: Error checking file %s: %s\n", - PACKAGE, filename, strerror (errno)); - return -EACCES; - } + { + fprintf (stderr, + "%s: Error checking file %s: %s\n", + PACKAGE, filename, strerror (errno)); + return -EACCES; + } /* * The file doesn't exist, so create it with O_EXCL to make @@ -91,12 +91,12 @@ create_file_safely (const char *filename, unsigned int truncate_file) * and open() */ if ((fildes = open (filename, O_RDWR | O_CREAT | O_EXCL, 0600)) < 0) - { - fprintf (stderr, - "%s: Could not create file %s: %s\n", - PACKAGE, filename, strerror (errno)); - return fildes; - } + { + fprintf (stderr, + "%s: Could not create file %s: %s\n", + PACKAGE, filename, strerror (errno)); + return fildes; + } } else { @@ -105,34 +105,34 @@ create_file_safely (const char *filename, unsigned int truncate_file) flags = O_RDWR; if (!truncate_file) - flags |= O_APPEND; + flags |= O_APPEND; /* * Open an existing file. */ if ((fildes = open (filename, flags)) < 0) - { - fprintf (stderr, - "%s: Could not open file %s: %s\n", - PACKAGE, filename, strerror (errno)); - return fildes; - } + { + fprintf (stderr, + "%s: Could not open file %s: %s\n", + PACKAGE, filename, strerror (errno)); + return fildes; + } /* * fstat() the opened file and check that the file mode bits, * inode, and device match. */ if (fstat (fildes, &fstatinfo) < 0 - || lstatinfo.st_mode != fstatinfo.st_mode - || lstatinfo.st_ino != fstatinfo.st_ino - || lstatinfo.st_dev != fstatinfo.st_dev) - { - fprintf (stderr, - "%s: The file %s has been changed before it could be opened\n", - PACKAGE, filename); - close (fildes); - return -EIO; - } + || lstatinfo.st_mode != fstatinfo.st_mode + || lstatinfo.st_ino != fstatinfo.st_ino + || lstatinfo.st_dev != fstatinfo.st_dev) + { + fprintf (stderr, + "%s: The file %s has been changed before it could be opened\n", + PACKAGE, filename); + close (fildes); + return -EIO; + } /* * If the above check was passed, we know that the lstat() @@ -142,21 +142,21 @@ create_file_safely (const char *filename, unsigned int truncate_file) * st_mode check would also find this) */ if (fstatinfo.st_nlink > 1 || !S_ISREG (lstatinfo.st_mode)) - { - fprintf (stderr, - "%s: The file %s has too many links, " - "or is not a regular file: %s\n", - PACKAGE, filename, strerror (errno)); - close (fildes); - return -EMLINK; - } + { + fprintf (stderr, + "%s: The file %s has too many links, " + "or is not a regular file: %s\n", + PACKAGE, filename, strerror (errno)); + close (fildes); + return -EMLINK; + } /* * Just return the file descriptor if we _don't_ want the file * truncated. */ if (!truncate_file) - return fildes; + return fildes; /* * On systems which don't support ftruncate() the best we can @@ -171,12 +171,12 @@ create_file_safely (const char *filename, unsigned int truncate_file) #else close (fildes); if ((fildes = open (filename, O_RDWR | O_CREAT | O_TRUNC, 0600)) < 0) - { - fprintf (stderr, - "%s: Could not open file %s: %s.", - PACKAGE, filename, strerror (errno)); - return fildes; - } + { + fprintf (stderr, + "%s: Could not open file %s: %s.", + PACKAGE, filename, strerror (errno)); + return fildes; + } #endif /* HAVE_FTRUNCATE */ } @@ -204,8 +204,8 @@ pidfile_create (const char *filename) if ((fd = fdopen (fildes, "w")) == NULL) { fprintf (stderr, - "%s: Could not write PID file %s: %s.", - PACKAGE, filename, strerror (errno)); + "%s: Could not write PID file %s: %s.", + PACKAGE, filename, strerror (errno)); close (fildes); unlink (filename); return -EIO; |