File: umask.c

package info (click to toggle)
darcs 2.12.4-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 5,748 kB
  • sloc: haskell: 42,936; sh: 11,086; ansic: 837; perl: 129; makefile: 8
file content (38 lines) | stat: -rw-r--r-- 616 bytes parent folder | download | duplicates (5)
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
#include <sys/types.h>
#include <sys/stat.h>
#include <stdlib.h>
#include <errno.h>
#include "umask.h"

int
set_umask(char *mask_string)
{
#ifndef WIN32
    int rc;
    unsigned mask;
    char *end;

    mask = strtoul(mask_string, &end, 8);
    if(!end || *end != '\0') {
        errno = EINVAL;
        return -1;
    }

    rc = umask(mask);
    return rc;
#else
    /* umask() has no useful meaning on win32. */
    return 0;
#endif /* #ifndef WIN32 ... else ... */
}

int
reset_umask(int old_mask)
{
#ifndef WIN32
    umask(old_mask);
    return 1;
#else
    return 0;
#endif /* #ifndef WIN32 ... else ... */
}