Reformatted code example

This commit is contained in:
Michael Kerrisk 2007-06-02 06:08:57 +00:00
parent 8de12063a6
commit 4594917527
2 changed files with 20 additions and 5 deletions

View File

@ -537,7 +537,10 @@ main(int argc, char *argv[])
int status;
cpid = fork();
if (cpid == -1) { perror("fork"); exit(EXIT_FAILURE); }
if (cpid == -1) {
perror("fork");
exit(EXIT_FAILURE);
}
if (cpid == 0) { /* Code executed by child */
printf("Child PID is %ld\\n", (long) getpid());
@ -548,7 +551,10 @@ main(int argc, char *argv[])
} else { /* Code executed by parent */
do {
w = waitpid(cpid, &status, WUNTRACED | WCONTINUED);
if (w == -1) { perror("waitpid"); exit(EXIT_FAILURE); }
if (w == -1) {
perror("waitpid");
exit(EXIT_FAILURE);
}
if (WIFEXITED(status)) {
printf("exited, status=%d\\n", WEXITSTATUS(status));

View File

@ -177,10 +177,16 @@ main(int argc, char *argv[])
assert(argc == 2);
in = fmemopen(argv[1], strlen(argv[1]), "r");
if (in == NULL) { perror("fmemopen"); exit(EXIT_FAILURE);}
if (in == NULL) {
perror("fmemopen");
exit(EXIT_FAILURE);
}
out = open_memstream(&ptr, &size);
if (out == NULL) { perror("fmemopen"); exit(EXIT_FAILURE);}
if (out == NULL) {
perror("fmemopen");
exit(EXIT_FAILURE);
}
for (;;) {
s = fscanf(in, "%d", &v);
@ -188,7 +194,10 @@ main(int argc, char *argv[])
break;
s = fprintf(out, "%d ", v * v);
if (s == -1) { perror("fprintf"); exit(EXIT_FAILURE); }
if (s == -1) {
perror("fprintf");
exit(EXIT_FAILURE);
}
}
fclose(in);
fclose(out);