blob: b106e3a57c3ec3379271a212ef5a1653c28a889a (
plain)
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
/***************************************************************
SYS-MKDIR.C
This file contains Linux/i386/ILP32 implementation of
__cpu_sys_mkdir().
PART OF : CPU - library .
USAGE : Internal only .
Copyright (C) 2026 by Andrew V.Kosteltsev.
All Rights Reserved.
***************************************************************/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <errno.h>
#include <sys/stat.h>
#include <libmcpu.h>
#include <cpu-sysdeps.h>
static int
__cpu_mkdir_mode( __mpu_uint64_t mode, mode_t *host_mode )
{
mode_t m = 0;
if( !host_mode ) return( __MCPU_EINVAL );
if( mode & ~(__mpu_uint64_t)__CPU_S_SUPPORTED ) return( __MCPU_EINVAL );
if( mode & __CPU_S_ISUID ) m |= S_ISUID;
if( mode & __CPU_S_ISGID ) m |= S_ISGID;
#ifdef S_ISVTX
if( mode & __CPU_S_ISVTX ) m |= S_ISVTX;
#endif
if( mode & __CPU_S_IRUSR ) m |= S_IRUSR;
if( mode & __CPU_S_IWUSR ) m |= S_IWUSR;
if( mode & __CPU_S_IXUSR ) m |= S_IXUSR;
if( mode & __CPU_S_IRGRP ) m |= S_IRGRP;
if( mode & __CPU_S_IWGRP ) m |= S_IWGRP;
if( mode & __CPU_S_IXGRP ) m |= S_IXGRP;
if( mode & __CPU_S_IROTH ) m |= S_IROTH;
if( mode & __CPU_S_IWOTH ) m |= S_IWOTH;
if( mode & __CPU_S_IXOTH ) m |= S_IXOTH;
*host_mode = m;
return( 0 );
} /* End of __cpu_mkdir_mode() */
__mpu_int64_t
__cpu_sys_mkdir( int dirfd, const char *path, __mpu_uint64_t mode )
{
mode_t host_mode;
int error;
if( !path ) return( -(__mpu_int64_t)__MCPU_EFAULT );
error = __cpu_mkdir_mode( mode, &host_mode );
if( error ) return( -(__mpu_int64_t)error );
if( mkdirat( dirfd, path, host_mode ) < 0 ) return( -(__mpu_int64_t)__cpu_errno_from_host( errno ) );
return( 0 );
} /* End of __cpu_sys_mkdir() */
|