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

« back to all changes in this revision

Viewing changes to tests/utime/test_utime.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 <signal.h>
 
4
#include <stdio.h>
 
5
#include <stdlib.h>
 
6
#include <string.h>
 
7
#include <unistd.h>
 
8
#include <utime.h>
 
9
#include <sys/stat.h>
 
10
 
 
11
void setup() {
 
12
  mkdir("writeable", 0777);
 
13
  mkdir("unwriteable", 0111);
 
14
}
 
15
 
 
16
void cleanup() {
 
17
  rmdir("writeable");
 
18
  rmdir("unwriteable");
 
19
}
 
20
 
 
21
void test() {
 
22
  struct stat s;
 
23
  // currently, the most recent timestamp is shared for atime,
 
24
  // ctime and mtime. using unique values for each in the test
 
25
  // will fail
 
26
  struct utimbuf t = {1000000000, 1000000000};
 
27
 
 
28
  utime("writeable", &t);
 
29
  assert(!errno);
 
30
  memset(&s, 0, sizeof s);
 
31
  stat("writeable", &s);
 
32
  assert(s.st_atime == t.actime);
 
33
  assert(s.st_mtime == t.modtime);
 
34
 
 
35
  // write permissions aren't checked when setting node
 
36
  // attributes unless the user uid isn't the owner (so
 
37
  // therefor, this should work fine)
 
38
  utime("unwriteable", &t);
 
39
  assert(!errno);
 
40
  memset(&s, 0, sizeof s);
 
41
  stat("unwriteable", &s);
 
42
  assert(s.st_atime == t.actime);
 
43
  assert(s.st_mtime == t.modtime);
 
44
 
 
45
  puts("success");
 
46
}
 
47
 
 
48
int main() {
 
49
  atexit(cleanup);
 
50
  signal(SIGABRT, cleanup);
 
51
  setup();
 
52
  test();
 
53
  return EXIT_SUCCESS;
 
54
}