Reformat the source code

The source code was a mix of different styles; normalize on NASM
style; basically K&R style with 4 space indentation.
This commit is contained in:
H. Peter Anvin 2008-07-08 17:14:44 -04:00
parent 62533e7441
commit 22accddda0
18 changed files with 2794 additions and 2820 deletions

View file

@ -6,23 +6,22 @@
#include "config.h"
void (*bsd_signal(int signum, void (*handler)(int)))(int)
{
struct sigaction action, oldaction;
void (*bsd_signal(int signum, void (*handler) (int))) (int) {
struct sigaction action, oldaction;
memset(&action, 0, sizeof action);
action.sa_handler = handler;
sigemptyset(&action.sa_mask);
sigaddset(&action.sa_mask, signum);
action.sa_flags = SA_RESTART;
if (sigaction(signum, &action, &oldaction) == -1) {
memset(&action, 0, sizeof action);
action.sa_handler = handler;
sigemptyset(&action.sa_mask);
sigaddset(&action.sa_mask, signum);
action.sa_flags = SA_RESTART;
if (sigaction(signum, &action, &oldaction) == -1) {
#ifdef SIG_ERR
return SIG_ERR;
return SIG_ERR;
#else
return NULL;
return NULL;
#endif
}
}
return oldaction.sa_handler;
return oldaction.sa_handler;
}

View file

@ -6,32 +6,31 @@
int daemon(int nochdir, int noclose)
{
int nullfd;
pid_t f;
if (!nochdir) {
if (chdir("/"))
return -1;
}
int nullfd;
pid_t f;
if (!noclose) {
if ((nullfd = open("/dev/null", O_RDWR)) < 0 ||
dup2(nullfd, 0) < 0 ||
dup2(nullfd, 1) < 0 ||
dup2(nullfd, 2) < 0)
return -1;
close(nullfd);
}
if (!nochdir) {
if (chdir("/"))
return -1;
}
f = fork();
if (f < 0)
return -1;
else if (f > 0)
_exit(0);
if (!noclose) {
if ((nullfd = open("/dev/null", O_RDWR)) < 0 ||
dup2(nullfd, 0) < 0 ||
dup2(nullfd, 1) < 0 || dup2(nullfd, 2) < 0)
return -1;
close(nullfd);
}
f = fork();
if (f < 0)
return -1;
else if (f > 0)
_exit(0);
#ifdef HAVE_SETSID
return setsid();
return setsid();
#else
return 0;
return 0;
#endif
}

View file

@ -8,18 +8,16 @@
int dup2(int oldfd, int newfd)
{
int rv, nfd;
int rv, nfd;
close(newfd);
close(newfd);
nfd = rv = dup(oldfd);
nfd = rv = dup(oldfd);
if (rv >= 0 && rv != newfd) {
rv = dup2(oldfd, newfd);
close(nfd);
}
if (rv >= 0 && rv != newfd) {
rv = dup2(oldfd, newfd);
close(nfd);
}
return rv;
return rv;
}

View file

@ -9,12 +9,12 @@
void *xmalloc(size_t size)
{
void *p = malloc(size);
void *p = malloc(size);
if ( !p ) {
fprintf(stderr, "Out of memory!\n");
exit(128);
}
if (!p) {
fprintf(stderr, "Out of memory!\n");
exit(128);
}
return p;
return p;
}

View file

@ -9,12 +9,12 @@
char *xstrdup(const char *s)
{
char *p = strdup(s);
char *p = strdup(s);
if ( !p ) {
fprintf(stderr, "Out of memory!\n");
exit(128);
}
if (!p) {
fprintf(stderr, "Out of memory!\n");
exit(128);
}
return p;
return p;
}