mirror of https://github.com/mkerrisk/man-pages
Reformatted code example
This commit is contained in:
parent
8de12063a6
commit
4594917527
10
man2/wait.2
10
man2/wait.2
|
@ -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));
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue