File: test_fcntl.sl

package info (click to toggle)
slang2 2.3.3-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 11,488 kB
  • sloc: ansic: 101,756; sh: 3,435; makefile: 1,046; pascal: 440
file content (39 lines) | stat: -rw-r--r-- 959 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
% -*- mode: slang; mode: fold -*-

() = evalfile ("./test.sl");

require ("fcntl");

private define test_fcntl (fd)
{
   variable flags = fcntl_getfd (fd);
   if (flags == -1)
     failed ("fcntl_getfd failed: %S", errno_string());

   if (-1 == fcntl_setfd (fd, flags | FD_CLOEXEC))
     failed ("fcntl_setfd failed: %S", errno_string());

   flags = fcntl_getfd (fd);
   if (flags == -1)
     failed ("fcntl_getfd failed: %S", errno_string());

   ifnot (flags & FD_CLOEXEC)
     failed ("FD_CLOEXEC not set");

   if (-1 == fcntl_setfd (fd, flags & ~FD_CLOEXEC))
     failed ("fcntl_setfd failed: %S", errno_string());

   flags = fcntl_getfl (fd);
   if (flags == -1)
     failed ("fcntl_getfl failed: %S", errno_string());
   if (-1 == fcntl_setfl (fd, flags))
     failed ("fcntl_setfl failed: %S", errno_string());
}

define slsh_main ()
{
   testing_module ("fcntl");
   test_fcntl (fileno(stderr));
   test_fcntl (_fileno(stderr));
   end_test ();
}