summaryrefslogtreecommitdiff
path: root/cpu/sysdeps/unix/sysv/linux/i386/cpu-chown-linux.h
blob: 751877576df6312905ed40e09ec960fe18038d61 (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
/***************************************************************
  CPU-CHOWN-LINUX.H

       This file contains Linux/i386/ILP32 conversion helpers
       for MCPU uid/gid values -> HOST uid_t/gid_t.

       PART OF : CPU - library .

       USAGE   : Internal only .

       Copyright (C) 2026  by Andrew V.Kosteltsev.
       All Rights Reserved.
 ***************************************************************/

#ifndef   __CPU_CHOWN_LINUX_H
#define   __CPU_CHOWN_LINUX_H

#include <errno.h>
#include <sys/types.h>

#include <libmcpu.h>
#include <cpu-sysdeps.h>


static int
__cpu_uid_to_host( __mpu_uint64_t uid, uid_t *host_uid )
{
  uid_t  u;

  if( !host_uid ) return( __MCPU_EINVAL );
  if( uid == __CPU_ID_NO_CHANGE )
  {
    *host_uid = (uid_t)-1;
    return( 0 );
  }

  u = (uid_t)uid;
  if( (__mpu_uint64_t)u != uid ) return( __MCPU_EOVERFLOW );

  *host_uid = u;
  return( 0 );

} /* End of __cpu_uid_to_host() */


static int
__cpu_gid_to_host( __mpu_uint64_t gid, gid_t *host_gid )
{
  gid_t  g;

  if( !host_gid ) return( __MCPU_EINVAL );
  if( gid == __CPU_ID_NO_CHANGE )
  {
    *host_gid = (gid_t)-1;
    return( 0 );
  }

  g = (gid_t)gid;
  if( (__mpu_uint64_t)g != gid ) return( __MCPU_EOVERFLOW );

  *host_gid = g;
  return( 0 );

} /* End of __cpu_gid_to_host() */

#endif /* __CPU_CHOWN_LINUX_H */