Format code automatically for regression tests

This commit is contained in:
Ruihan Li
2024-03-16 00:15:19 +08:00
committed by Tate, Hongliang Tian
parent 60cd65d837
commit 82de200d03
22 changed files with 1344 additions and 1123 deletions

View File

@ -8,33 +8,34 @@
#define MESG1 "Hello from child"
#define MESG2 "Hello from parent"
int main() {
int sockets[2], child;
char buf[1024];
if (socketpair(AF_UNIX, SOCK_STREAM, 0, sockets) < 0) {
perror("create socket pair");
exit(1);
}
if ((child = fork()) == -1)
perror("fork");
else if (child) {
// parent
close(sockets[0]);
if (read(sockets[1], buf, 1024) < 0)
perror("read from child");
printf("Receive from child: %s\n", buf);
if (write(sockets[1], MESG2, sizeof(MESG2)) < 0)
perror("write to child");
close(sockets[1]);
} else {
// child
close(sockets[1]);
if (write(sockets[0], MESG1, sizeof(MESG1)) < 0)
perror("write to parent");
if (read(sockets[0], buf, 1024) < 0)
perror("read from parent");
printf("Receive from parent: %s\n", buf);
close(sockets[0]);
}
return 0;
int main()
{
int sockets[2], child;
char buf[1024];
if (socketpair(AF_UNIX, SOCK_STREAM, 0, sockets) < 0) {
perror("create socket pair");
exit(1);
}
if ((child = fork()) == -1)
perror("fork");
else if (child) {
// parent
close(sockets[0]);
if (read(sockets[1], buf, 1024) < 0)
perror("read from child");
printf("Receive from child: %s\n", buf);
if (write(sockets[1], MESG2, sizeof(MESG2)) < 0)
perror("write to child");
close(sockets[1]);
} else {
// child
close(sockets[1]);
if (write(sockets[0], MESG1, sizeof(MESG1)) < 0)
perror("write to parent");
if (read(sockets[0], buf, 1024) < 0)
perror("read from parent");
printf("Receive from parent: %s\n", buf);
close(sockets[0]);
}
return 0;
}