~ubuntu-branches/ubuntu/vivid/emscripten/vivid

« back to all changes in this revision

Viewing changes to tests/unistd/ttyname.c

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2013-09-20 22:44:35 UTC
  • mfrom: (4.1.1 sid)
  • Revision ID: package-import@ubuntu.com-20130920224435-apuwj4fsl3fqv1a6
Tags: 1.5.6~20130920~6010666-1
* New snapshot release
* Update the list of supported architectures to the same as libv8
  (Closes: #723129)
* emlibtool has been removed from upstream.
* Fix warning syntax-error-in-dep5-copyright
* Refresh of the patches

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <assert.h>
 
2
#include <errno.h>
 
3
#include <fcntl.h>
1
4
#include <stdio.h>
2
 
#include <errno.h>
 
5
#include <stdlib.h>
 
6
#include <string.h>
3
7
#include <unistd.h>
4
 
#include <fcntl.h>
5
8
 
6
9
int main() {
 
10
  int err;
 
11
  int stdin, null, dev;
7
12
  char buffer[256];
8
 
  int d = open("/device", O_RDWR);
9
 
  int f = open("/", O_RDONLY);
10
13
  char* result;
11
14
 
 
15
  stdin = open("/dev/stdin", O_RDONLY);
 
16
  null = open("/dev/null", O_RDONLY);
 
17
  dev = open("/dev", O_RDONLY);
 
18
 
12
19
  result = ctermid(buffer);
13
 
  if (result) {
14
 
    printf("ctermid: %s\n", result);
15
 
  } else {
16
 
    printf("ctermid errno: %d\n", errno);
17
 
    errno = 0;
18
 
  }
19
 
 
20
 
  if (ttyname_r(d, buffer, 256) == 0) {
21
 
    printf("ttyname_r(d, ..., 256): %s\n", buffer);
22
 
  } else {
23
 
    printf("ttyname_r(d, ..., 256) errno: %d\n", errno);
24
 
    errno = 0;
25
 
  }
26
 
 
27
 
  if (ttyname_r(d, buffer, 2) == 0) {
28
 
    printf("ttyname_r(d, ..., 2): %s\n", buffer);
29
 
  } else {
30
 
    printf("ttyname_r(d, ..., 2) errno: %d\n", errno);
31
 
    errno = 0;
32
 
  }
33
 
 
34
 
  result = ttyname(d);
35
 
  if (result) {
36
 
    printf("ttyname(d): %s\n", result);
37
 
  } else {
38
 
    printf("ttyname(d) errno: %d\n", errno);
39
 
    errno = 0;
40
 
  }
41
 
 
42
 
  result = ttyname(f);
43
 
  if (result) {
44
 
    printf("ttyname(f): %s\n", result);
45
 
  } else {
46
 
    printf("ttyname(f) errno: %d\n", errno);
47
 
    errno = 0;
48
 
  }
49
 
 
50
 
  return 0;
 
20
  assert(!strcmp(result, "/dev/tty"));
 
21
 
 
22
  // strstr instead of strcmp as native code may
 
23
  // be using a virtual console (e.g. /dev/tty02)
 
24
  err = ttyname_r(stdin, buffer, 256);
 
25
  assert(!err);
 
26
  assert(strstr(buffer, "/dev/tty"));
 
27
 
 
28
  err = ttyname_r(stdin, buffer, 2);
 
29
  assert(err == ERANGE);
 
30
 
 
31
  result = ttyname(stdin);
 
32
  assert(strstr(result, "/dev/tty"));
 
33
 
 
34
  result = ttyname(null);
 
35
  assert(!result);
 
36
 
 
37
  result = ttyname(dev);
 
38
  assert(!result);
 
39
 
 
40
  puts("success");
 
41
 
 
42
  return EXIT_SUCCESS;
51
43
}