⚲
Project
General
Profile
Sign in
Home
Projects
Help
Search
:
DragonFlyBSD
All Projects
DragonFlyBSD
Overview
Activity
Roadmap
Issues
Documents
Files
Repository
Download (1.03 KB)
Bug #3252
ยป tcerror.c
test code -
tonyc
, 10/25/2020 09:35 PM
#include
<termios.h>
#include
<stdio.h>
#include
<fcntl.h>
#include
<stdlib.h>
#include
<errno.h>
int
main
(
void
)
{
struct
termios
ti
;
int
nullfd
=
open
(
"/dev/null"
,
O_RDWR
);
int
termfd
=
fileno
(
stdin
);
/* stdin: intended to be run in a terminal */
int
err
;
if
(
nullfd
<
0
)
{
perror
(
"NA: null open failed"
);
exit
(
1
);
}
errno
=
0
;
if
(
tcgetattr
(
nullfd
,
&
ti
)
<
0
)
{
err
=
errno
;
printf
(
"OK: tcgetattr on /dev/null failed as expected
\n
"
);
if
(
err
!=
ENOTTY
)
{
perror
(
"FAIL: tcgetattr on /dev/null set errno incorrectly"
);
}
}
else
{
printf
(
"FAIL: tcgetattr on /dev/null succeeded
\n
"
);
}
errno
=
0
;
if
(
tcgetattr
(
termfd
,
&
ti
)
<
0
)
{
perror
(
"NA: tcgetattr failed"
);
exit
(
1
);
}
errno
=
0
;
if
(
tcsetattr
(
nullfd
,
TCSADRAIN
,
&
ti
)
==
0
)
{
perror
(
"FAIL: tcsetattr succeeded unexpectedly"
);
exit
(
1
);
}
err
=
errno
;
printf
(
"OK: tcsetattr failed as expected
\n
"
);
if
(
err
!=
ENOTTY
)
{
perror
(
"FAIL: tcsetattr failure set errno incorrectly"
);
exit
(
1
);
}
return
0
;
}
(1-1/1)
Loading...