~ubuntu-branches/ubuntu/wily/apparmor/wily

« back to all changes in this revision

Viewing changes to tests/regression/subdomain/readdir.c

  • Committer: Bazaar Package Importer
  • Author(s): Kees Cook
  • Date: 2011-04-27 10:38:07 UTC
  • mfrom: (5.1.118 natty)
  • Revision ID: james.westby@ubuntu.com-20110427103807-ym3rhwys6o84ith0
Tags: 2.6.1-2
debian/copyright: clarify for some full organization names.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $Id: readdir.c 264 2006-12-04 06:43:42Z steve-beattie $ */
2
 
 
3
 
/*
4
 
 *      Copyright (C) 2002-2006 Novell/SUSE
5
 
 *
6
 
 *      This program is free software; you can redistribute it and/or
7
 
 *      modify it under the terms of the GNU General Public License as
8
 
 *      published by the Free Software Foundation, version 2 of the
9
 
 *      License.
10
 
 */
11
 
 
12
 
#include <stdio.h>
13
 
#include <unistd.h>
14
 
#include <errno.h>
15
 
#include <fcntl.h>
16
 
#include <linux/types.h>
17
 
#include <linux/dirent.h>
18
 
#include <linux/unistd.h>
19
 
#include <string.h>
20
 
#include <sys/syscall.h>
21
 
 
22
 
int main(int argc, char *argv[])
23
 
{
24
 
        int fd;
25
 
        struct dirent dir;
26
 
 
27
 
        if (argc != 2){
28
 
                fprintf(stderr, "usage: %s dir\n",
29
 
                        argv[0]);
30
 
                return 1;
31
 
        }
32
 
 
33
 
        fd = open(argv[1], O_RDONLY, 0);
34
 
        if (fd == -1){
35
 
                printf("FAIL - open  %s\n", strerror(errno));
36
 
                return 1;
37
 
        }
38
 
 
39
 
        /*
40
 
        if (fchdir(fd) == -1){
41
 
                printf("FAIL - fchdir  %s\n", strerror(errno));
42
 
                return 1;
43
 
        }
44
 
        */
45
 
 
46
 
        /* getdents isn't exported by glibc, so must use syscall() */
47
 
        if (syscall(SYS_getdents, fd, &dir, sizeof(struct dirent)) == -1){
48
 
                printf("FAIL - getdents  %s\n", strerror(errno));
49
 
                return 1;
50
 
        }
51
 
 
52
 
        printf("PASS\n");
53
 
 
54
 
        return 0;
55
 
}