1 /*
2  * Copyright (c) 2002, Intel Corporation. All rights reserved.
3  * This file is licensed under the GPL license.  For the full content
4  * of this license, see the COPYING file at the top level of this
5  * source tree.
6  *
7  * The fsync() function shall fail if:
8  * [EINVAL] The fildes argument does not refer to a file
9  * on which this operation is possible.
10  *
11  * Test Step:
12  * 1. Create a pipe;
13  * 2. fsync on the pipe, should fail with EINVAL;
14  *
15  */
16 
17 #define _XOPEN_SOURCE 600
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include <unistd.h>
21 #include <sys/mman.h>
22 #include <sys/types.h>
23 #include <sys/stat.h>
24 #include <fcntl.h>
25 #include <string.h>
26 #include <errno.h>
27 #include "posixtest.h"
28 
29 #define TNAME "fsync/7-1.c"
30 
main(void)31 int main(void)
32 {
33 	int fd[2];
34 
35 	if (pipe(fd) == -1) {
36 		printf(TNAME " Test UNRESOLVED: Error at pipe: %s\n",
37 		       strerror(errno));
38 		exit(PTS_UNRESOLVED);
39 	}
40 
41 	if (fsync(fd[1]) == -1 && errno == EINVAL) {
42 		printf("Got EINVAL when fsync on pipe\n");
43 		printf("Test PASSED\n");
44 		close(fd[0]);
45 		close(fd[1]);
46 		exit(PTS_PASS);
47 	} else {
48 		printf(TNAME " Test Fail: Expect EINVAL, get: %s\n",
49 		       strerror(errno));
50 		close(fd[0]);
51 		close(fd[1]);
52 		exit(PTS_FAIL);
53 	}
54 }
55