OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [uClibc/] [test/] [stat/] [stat.c] - Blame information for rev 1325

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1325 phoenix
#include <stdio.h>
2
#include <fcntl.h>
3
#include <sys/stat.h>
4
 
5
void print_struct_stat(char *msg, struct stat *s)
6
{
7
    printf("%s\n", msg);
8
    /* The casts are because glibc thinks it's cool */
9
    printf("device    : 0x%llx\n",(long long)s->st_dev);
10
    printf("inode     : %lld\n",  (long long)s->st_ino);
11
    printf("mode      : 0x%llx\n",(long long)s->st_mode);
12
    printf("nlink     : %lld\n",  (long long)s->st_nlink);
13
    printf("uid       : %lld\n",  (long long)s->st_uid);
14
    printf("gid       : %lld\n",  (long long)s->st_gid);
15
    printf("rdev      : 0x%llx\n",(long long)s->st_rdev);
16
    printf("size      : %lld\n",  (long long)s->st_size);
17
    printf("blksize   : %lld\n",  (long long)s->st_blksize);
18
    printf("blocks    : %lld\n",  (long long)s->st_blocks);
19
    printf("atime     : %lld\n",  (long long)s->st_atime);
20
    printf("mtime     : %lld\n",  (long long)s->st_mtime);
21
    printf("ctime     : %lld\n",  (long long)s->st_ctime);
22
}
23
 
24
int main(int argc,char **argv)
25
{
26
    int fd, ret;
27
    char *file;
28
    struct stat s;
29
 
30
    if (argc < 2) {
31
        fprintf(stderr, "Usage: stat FILE\n");
32
        exit(1);
33
    }
34
    file = argv[1];
35
 
36
    memset(&s, 0, sizeof(struct stat));
37
    ret = stat(file, &s);
38
    if(ret<0){
39
        perror("stat");
40
        exit(1);
41
    }
42
    print_struct_stat("\nTesting stat:", &s);
43
 
44
    memset(&s, 0, sizeof(struct stat));
45
    ret = lstat(file, &s);
46
    if(ret<0){
47
        perror("lstat");
48
        exit(1);
49
    }
50
    print_struct_stat("\nTesting lstat:", &s);
51
 
52
 
53
    fd = open(file, O_RDONLY);
54
    if(fd<0){
55
        perror("open");
56
        exit(1);
57
    }
58
    memset(&s, 0, sizeof(struct stat));
59
    ret = fstat(fd,&s);
60
    if(ret<0){
61
        perror("fstat");
62
        exit(1);
63
    }
64
    print_struct_stat("\nTesting fstat:", &s);
65
 
66
    exit(0);
67
}
68
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.