~ecryptfs/ecryptfs/trunk

« back to all changes in this revision

Viewing changes to tests/kernel/enospc/test.c

  • Committer: Tyler Hicks
  • Date: 2012-11-05 06:05:54 UTC
  • Revision ID: tyhicks@canonical.com-20121105060554-5ji4q2865a9qk1ct
* autogen.sh:
  - Use the --copy option when invoking intltoolize

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
#include <unistd.h>
28
28
#include <signal.h>
29
29
#include <limits.h>
30
 
#include <inttypes.h>
31
30
 
32
31
#define TEST_PASSED     (0)
33
32
#define TEST_FAILED     (1)
35
34
 
36
35
#define BUFF_SZ         (65536)
37
36
 
38
 
int test_exercise(char *filename, off_t size)
 
37
int test_exercise(char *filename, ssize_t size)
39
38
{
40
39
        int fd;
 
40
        ssize_t i;
 
41
        ssize_t n;
 
42
        struct stat statbuf;
 
43
        ssize_t nbytes = size;
41
44
        int ret = TEST_FAILED;
 
45
 
42
46
        unsigned char buff[BUFF_SZ];
43
47
 
44
48
        unlink(filename);
49
53
 
50
54
        memset(buff, 0, sizeof(buff));
51
55
 
52
 
        while (size > 0) {
 
56
        while (nbytes > 0) {
53
57
                int rc;
 
58
                ssize_t n = (nbytes > BUFF_SZ) ? BUFF_SZ : nbytes;
54
59
 
55
 
                rc = write(fd, buff, (size > BUFF_SZ) ? BUFF_SZ : size);
 
60
                rc = write(fd, buff, n);
56
61
                if (rc < 0) {
57
62
                        if (errno == ENOSPC)
58
63
                                ret = TEST_PASSED;
59
64
                        break;
60
65
                }
61
 
                size -= rc;
 
66
                nbytes -= n;
62
67
        }
63
68
        /* If we got here, we didn't get ENOSPC, so we've failed */
64
69
 
75
80
 
76
81
int main(int argc, char **argv)
77
82
{
78
 
        off_t len;
 
83
        ssize_t len;
79
84
 
80
85
        if (argc < 3) {
81
86
                fprintf(stderr, "Syntax: %s filename size_in_K\n", argv[0]);