SH: ABORT_INSTRUCTION.
[glibc.git] / login / tst-grantpt.c
blob5078dac26c9baf86113d5ad008a5e8d58acfb452
1 #include <sys/types.h>
2 #include <sys/stat.h>
3 #include <fcntl.h>
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <errno.h>
7 #include <string.h>
8 #include <unistd.h>
10 static int
11 test_ebadf (void)
13 int fd, ret, err;
15 fd = posix_openpt (O_RDWR);
16 if (fd == -1)
18 printf ("posix_openpt(O_RDWR) failed\nerrno %d (%s)\n",
19 errno, strerror (errno));
20 /* We don't fail because of this; maybe the system does not have
21 SUS pseudo terminals. */
22 return 0;
24 unlockpt (fd);
25 close (fd);
27 ret = grantpt (fd);
28 err = errno;
29 if (ret != -1 || err != EBADF)
31 printf ("grantpt(): expected: return = %d, errno = %d\n", -1, EBADF);
32 printf (" got: return = %d, errno = %d\n", ret, err);
33 return 1;
35 return 0;
38 static int
39 test_einval (void)
41 int fd, ret, err;
42 const char file[] = "./grantpt-einval";
44 fd = open (file, O_RDWR | O_CREAT, 0600);
45 if (fd == -1)
47 printf ("open(\"%s\", O_RDWR) failed\nerrno %d (%s)\n",
48 file, errno, strerror (errno));
49 return 0;
51 unlink (file);
53 ret = grantpt (fd);
54 err = errno;
55 if (ret != -1 || err != EINVAL)
57 printf ("grantpt(): expected: return = %d, errno = %d\n", -1, EINVAL);
58 printf (" got: return = %d, errno = %d\n", ret, err);
59 ret = 1;
61 else
62 ret = 0;
64 close (fd);
66 return ret;
69 int
70 main (void)
72 int result = 0;
74 result += test_ebadf ();
75 result += test_einval ();
77 return result;