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

« back to all changes in this revision

Viewing changes to tests/unistd/truncate.c

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2013-05-02 13:11:51 UTC
  • Revision ID: package-import@ubuntu.com-20130502131151-q8dvteqr1ef2x7xz
Tags: upstream-1.4.1~20130504~adb56cb
ImportĀ upstreamĀ versionĀ 1.4.1~20130504~adb56cb

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <stdio.h>
 
2
#include <errno.h>
 
3
#include <unistd.h>
 
4
#include <fcntl.h>
 
5
#include <sys/stat.h>
 
6
#include <string.h>
 
7
 
 
8
int main() {
 
9
  struct stat s;
 
10
  int f = open("/towrite", O_WRONLY);
 
11
  int f2 = open("/toread", O_RDONLY);
 
12
  printf("f2: %d\n", f2);
 
13
 
 
14
  fstat(f, &s);
 
15
  printf("st_size: %d\n", s.st_size);
 
16
  memset(&s, 0, sizeof s);
 
17
  errno = 0;
 
18
  printf("\n");
 
19
 
 
20
  printf("ftruncate(10): %d\n", ftruncate(f, 10));
 
21
  printf("errno: %d\n", errno);
 
22
  fstat(f, &s);
 
23
  printf("st_size: %d\n", s.st_size);
 
24
  memset(&s, 0, sizeof s);
 
25
  errno = 0;
 
26
  printf("\n");
 
27
 
 
28
  printf("ftruncate(4): %d\n", ftruncate(f, 4));
 
29
  printf("errno: %d\n", errno);
 
30
  fstat(f, &s);
 
31
  printf("st_size: %d\n", s.st_size);
 
32
  memset(&s, 0, sizeof s);
 
33
  errno = 0;
 
34
  printf("\n");
 
35
 
 
36
  printf("ftruncate(-1): %d\n", ftruncate(f, -1));
 
37
  printf("errno: %d\n", errno);
 
38
  fstat(f, &s);
 
39
  printf("st_size: %d\n", s.st_size);
 
40
  memset(&s, 0, sizeof s);
 
41
  errno = 0;
 
42
  printf("\n");
 
43
 
 
44
  printf("truncate(2): %d\n", truncate("/towrite", 2));
 
45
  printf("errno: %d\n", errno);
 
46
  stat("/towrite", &s);
 
47
  printf("st_size: %d\n", s.st_size);
 
48
  memset(&s, 0, sizeof s);
 
49
  errno = 0;
 
50
  printf("\n");
 
51
 
 
52
  printf("truncate(readonly, 2): %d\n", truncate("/toread", 2));
 
53
  printf("errno: %d\n", errno);
 
54
  stat("/toread", &s);
 
55
  printf("st_size: %d\n", s.st_size);
 
56
  memset(&s, 0, sizeof s);
 
57
  errno = 0;
 
58
  printf("\n");
 
59
 
 
60
  printf("ftruncate(readonly, 4): %d\n", ftruncate(f2, 4));
 
61
  printf("errno: %d\n", errno);
 
62
  fstat(f2, &s);
 
63
  printf("st_size: %d\n", s.st_size);
 
64
  memset(&s, 0, sizeof s);
 
65
  errno = 0;
 
66
 
 
67
  return 0;
 
68
}