Skip to content

Commit 9648a01

Browse files
committed
Fix compile error in one of the runpipe tests with some gcc versions.
1 parent 061d77f commit 9648a01

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

judge/runpipe_test/S_closes_stdin/judge.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,23 @@
1+
#define _XOPEN_SOURCE 700
2+
13
#include <stdio.h>
24
#include <signal.h>
5+
#include <unistd.h>
6+
#include <time.h>
37

48
int main() {
59
signal(SIGPIPE, SIG_IGN);
610

7-
usleep(500000);
11+
struct timespec req = {0};
12+
req.tv_nsec = 500000000L; // 0.5 seconds
13+
nanosleep(&req, NULL);
14+
815
printf("123\n");
916
fflush(stdout);
1017
int x;
11-
scanf("%d", &x);
18+
if (scanf("%d", &x) != 1) {
19+
return 1;
20+
}
1221
if (x == 42)
1322
return 42;
1423
return 43;
Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
1+
#define _XOPEN_SOURCE 700
2+
13
#include <stdio.h>
4+
#include <unistd.h>
5+
#include <time.h>
26

37
int main() {
48
fclose(stdin);
59
printf("42\n");
6-
usleep(800000);
10+
11+
struct timespec req = {0};
12+
req.tv_nsec = 800000000L; // 0.8 seconds
13+
nanosleep(&req, NULL);
714
}

0 commit comments

Comments
 (0)