2 * Copyright 2014 The Native Client Authors. All rights reserved.
3 * Use of this source code is governed by a BSD-style license that can be
4 * found in the LICENSE file.
11 #include "native_client/src/include/nacl_assert.h"
13 void test_getsetfl(const char *test_file) {
14 puts("test for F_GETFL and F_SETFL");
16 int fd = open(test_file, O_WRONLY | O_CREAT | O_TRUNC, 0644);
19 int rc = fcntl(fd, F_SETFL, O_NONBLOCK);
21 rc = fcntl(fd, F_GETFL);
24 * We only test the O_NONBLOCK bit because the user mode qemu does
25 * not return O_WRONLY with O_NONBLOCK.
27 ASSERT_EQ(rc & O_NONBLOCK, O_NONBLOCK);
33 void test_getsetfd(const char *test_file) {
34 puts("test for F_GETFD and F_SETFD");
36 int fd = open(test_file, O_WRONLY | O_CREAT | O_TRUNC, 0644);
39 int rc = fcntl(fd, F_GETFD);
41 rc = fcntl(fd, F_SETFD, FD_CLOEXEC);
43 rc = fcntl(fd, F_GETFD);
44 ASSERT_EQ(rc, FD_CLOEXEC);
50 int main(int argc, char *argv[]) {
52 printf("Please specify the test file name\n");
56 const char *test_file = argv[1];
57 test_getsetfl(test_file);
58 test_getsetfd(test_file);