File: tcreate.c

package info (click to toggle)
diod 1.0.24-5.2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 29,200 kB
  • sloc: ansic: 33,159; sh: 6,545; makefile: 363; perl: 80
file content (45 lines) | stat: -rw-r--r-- 859 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/* tcreate.c - verify file creation mode */

#if HAVE_CONFIG_H
#include "config.h"
#endif
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>

int
main (int argc, char *argv[])
{
    struct stat sb;
    int mode, nmode;

    umask(0);

    if (argc != 3) {
        fprintf (stderr, "Usage: tcreate file mode\n");
        exit (1);
    }
    mode = strtoul (argv[2], NULL, 0);
    if (creat (argv[1], mode) < 0) {
        perror ("creat");
        exit (1);
    }
    if (stat (argv[1], &sb) < 0) {
        perror ("stat");
        exit (1);
    }
    nmode = sb.st_mode & 0777;
    if (nmode == mode)
        fprintf (stderr, "mode %.4o\n", nmode);
    else
        fprintf (stderr, "mode %.4o != %.4o\n", nmode, mode);
    
    exit (0);
}

/*
 * vi:tabstop=4 shiftwidth=4 expandtab
 */