# Uid\_t/gid\_t may be bigger than plain 'int' type

**URL:** <https://www.ruby-forum.com/t/uid-t-gid-t-may-be-bigger-than-plain-int-type/85913>\
**Category:** Development\
**Created:** [February 17, 2007, 3:36pm UTC](https://www.ruby-forum.com/t/uid-t-gid-t-may-be-bigger-than-plain-int-type/85913 "2007-02-17T15:36:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![nobu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/e9c0ed/32.png) [@nobu](https://www.ruby-forum.com/u/nobu)\
**Post date:** [February 17, 2007, 3:36pm UTC](https://www.ruby-forum.com/t/uid-t-gid-t-may-be-bigger-than-plain-int-type/85913/1 "2007-02-17T15:36:33Z")

</div>

e$B$J$+$@$G$9!#e(B

e$B$7$P$i$/A0$Ke(B[ruby-core:08897]e$B$GJs9p$5$l$?OC$G$9$,!"e(Buide$B$de(Bgide$B!"e(B  
e$B$D$$$G$Ke(Bpide$B$bI,$:$7$be(Binte$B$G%+%P!\<$G$-$k$H$O$+$.$j$^$;$s!#:#$N$He(B  
e$B$3$me(Bext/etce$B$G$Oe(Buid\_t,gid\_te$B$K$D$$$F$@$1$OBP1~$5$l$F$$$^$9$,!"e(B  
e$B3:Ev$9$kItJ,$Oe(Brb\_pid\_t, rb\_uid\_t,  
rb\_gid\_te$B$r;H$&$Y$-$G$O$J$$$+e(B  
e$B$H;W$$$^$9!#e(B

# Index: intern.h

# — intern.h (revision 11768) +++ intern.h (working copy) @@ -425,11 +425,11 @@ int rb\_proc\_exec(const char\*); VALUE rb\_check\_argv(int, VALUE\*); int rb\_exec(const struct rb\_exec\_arg\*); -int rb\_fork(int\*, int (_)(void_), void\*); +rb\_pid\_t rb\_fork(int\*, int (_)(void_), void\*); VALUE rb\_f\_exec(int,VALUE\*); -int rb\_waitpid(int,int\*,int); -void rb\_syswait(int); -int rb\_spawn(int, VALUE\*); +rb\_pid\_t rb\_waitpid(rb\_pid\_t pid, int _status, int flags); +void rb\_syswait(rb\_pid\_t pid); +rb\_pid\_t rb\_spawn(int, VALUE_); VALUE rb\_proc\_times(VALUE); -VALUE rb\_detach\_process(int); +VALUE rb\_detach\_process(pid\_t pid); /\* range.c \*/ VALUE rb\_range\_new(VALUE, VALUE, int); Index: process.c

— process.c (revision 11768)  
+++ process.c (working copy)  
@@ -107,4 +107,11 @@ static VALUE S\_Tms;  
#endif

+#ifdef BROKEN\_SETREUID  
+#define setreuid ruby\_setreuid  
+#endif  
+#ifdef BROKEN\_SETREGID  
+#define setregid ruby\_setregid  
+#endif  
+  
#if defined(HAVE\_44BSD\_SETUID) || defined( **MacOS\_X** )  
#if !defined(USE\_SETREUID) && !defined(BROKEN\_SETREUID)  
@@ -134,5 +141,5 @@ get\_pid(void)  
{  
rb\_secure(2);

- return INT2FIX(getpid());

- return PIDT2NUM(getpid());  
}

@@ -161,5 +168,5 @@ get\_ppid(void)  
return INT2FIX(0);  
#else

- return INT2FIX(getppid());

- return PIDT2NUM(getppid());  
#endif  
}  
@@ -210,5 +217,5 @@ rb\_last\_status\_set(int status, rb\_pid\_t  
vm-\>last\_status = rb\_obj\_alloc(rb\_cProcStatus);  
rb\_iv\_set(vm-\>last\_status, “status”, INT2FIX(status));

- rb\_iv\_set(vm-\>last\_status, “pid”, INT2FIX(pid));

- rb\_iv\_set(vm-\>last\_status, “pid”, PIDT2NUM(pid));  
}

@@ -563,8 +570,8 @@ static st\_table \*pid\_tbl;  
#endif

-int  
-rb\_waitpid(int pid, int \*st, int flags)  
+rb\_pid\_t  
+rb\_waitpid(rb\_pid\_t pid, int \*st, int flags)  
{

- int result;

- rb\_pid\_t result;  
#ifndef NO\_WAITPID  
int oflags = flags;  
@@ -633,10 +640,10 @@ rb\_waitpid(int pid, int \*st, int flags)  
#ifdef NO\_WAITPID  
struct wait\_data {

- int pid;

- rb\_pid\_t pid;  
int status;  
};

static int  
-wait\_each(int pid, int status, struct wait\_data \*data)  
+wait\_each(rb\_pid\_t pid, int status, struct wait\_data \*data)  
{  
if (data-\>status != -1) return ST\_STOP;  
@@ -648,8 +655,8 @@ wait\_each(int pid, int status, struct wa

static int  
-waitall\_each(int pid, int status, VALUE ary)  
+waitall\_each(rb\_pid\_t pid, int status, VALUE ary)  
{  
rb\_last\_status\_set(status, pid);

- rb\_ary\_push(ary, rb\_assoc\_new(INT2NUM(pid), rb\_last\_status\_get());

- rb\_ary\_push(ary, rb\_assoc\_new(PIDT2NUM(pid), rb\_last\_status\_get());  
return ST\_DELETE;  
}  
@@ -719,5 +726,6 @@ proc\_wait(int argc, VALUE \*argv)  
{  
VALUE vpid, vflags;

- int pid, flags, status;

- rb\_pid\_t pid;

- int flags, status;

- pid = NUM2INT(vpid);

- pid = NUM2PIDT(vpid);  
if (argc == 2 && !NIL\_P(vflags)) {  
flags = NUM2UINT(vflags);  
@@ -739,5 +747,5 @@ proc\_wait(int argc, VALUE \*argv)  
return Qnil;  
}

- return INT2FIX(pid);

- return PIDT2NUM(pid);  
}

@@ -793,5 +801,6 @@ proc\_waitall(void)  
{  
VALUE result;

- int pid, status;

- rb\_pid\_t pid;

- int status;

- rb\_ary\_push(result, rb\_assoc\_new(INT2NUM(pid),  
rb\_last\_status\_get()));

- rb\_ary\_push(result, rb\_assoc\_new(PIDT2NUM(pid),  
rb\_last\_status\_get()));  
}  
#else  
@@ -825,5 +834,5 @@ proc\_waitall(void)  
rb\_sys\_fail(0);  
}

- rb\_ary\_push(result, rb\_assoc\_new(INT2NUM(pid),  
rb\_last\_status\_get()));

- rb\_ary\_push(result, rb\_assoc\_new(PIDT2NUM(pid),  
rb\_last\_status\_get()));  
}  
#endif  
@@ -834,5 +843,6 @@ static VALUE  
detach\_process\_watcher(int \*pid\_p)  
{

- int cpid, status;

- rb\_pid\_t cpid;

- int status;

VALUE  
-rb\_detach\_process(int pid)  
+rb\_detach\_process(rb\_pid\_t pid)  
{  
return rb\_thread\_create(detach\_process\_watcher, (void\*)&pid);  
@@ -900,5 +910,5 @@ proc\_detach(VALUE obj, VALUE pid)  
{  
rb\_secure(2);

- return rb\_detach\_process(NUM2INT(pid));

- return rb\_detach\_process(NUM2PIDT(pid));  
}

@@ -1075,9 +1085,9 @@ rb\_proc\_exec(const char \*str)  
#define proc\_spawn\_v(argv, prog) rb\_w32\_aspawn(P\_NOWAIT, prog, argv)  
#else  
-static int  
+static rb\_pid\_t  
proc\_spawn\_v(char \*\*argv, char \*prog)  
{  
char \*extension;

- int status;

- rb\_pid\_t status;

-static int  
+static rb\_pid\_t  
proc\_spawn\_n(int argc, VALUE \*argv, VALUE prog)  
{  
@@ -1139,10 +1149,10 @@ proc\_spawn\_n(int argc, VALUE \*argv, VALU  
#define proc\_spawn(str) rb\_w32\_spawn(P\_NOWAIT, str, 0)  
#else  
-static int  
+static rb\_pid\_t  
proc\_spawn(char \*str)  
{  
char \*s, \*t;  
char \*\*argv, \*\*a;

- int status;

- rb\_pid\_t status;

- +chfunc+ must not raise any exceptions.  
\*/  
-int  
+rb\_pid\_t  
rb\_fork(int \*status, int (_chfunc)(void_), void \*charg)  
{

- int pid, err, state = 0;

- rb\_pid\_t pid;
- int err, state = 0;  
#ifdef FD\_CLOEXEC  
int ep[2];  
@@ -1418,5 +1429,5 @@ rb\_f\_fork(VALUE obj)  
{  
#ifdef HAVE\_FORK

- int pid;

- rb\_pid\_t pid;

- return INT2FIX(pid);

- return PIDT2NUM(pid);  
}  
#else  
@@ -1493,5 +1504,5 @@ rb\_f\_exit\_bang(int argc, VALUE \*argv, VA

void  
-rb\_syswait(int pid)  
+rb\_syswait(rb\_pid\_t pid)  
{  
static int overriding;  
@@ -1534,8 +1545,8 @@ rb\_syswait(int pid)  
}

-int  
+rb\_pid\_t  
rb\_spawn(int argc, VALUE \*argv)  
{

- int status;

- rb\_pid\_t status;  
VALUE prog;

@@ -1635,10 +1646,10 @@ static VALUE  
rb\_f\_spawn(int argc, VALUE \*argv)  
{

- int pid;

- rb\_pid\_t pid;

- return INT2NUM(pid);

- return PIDT2NUM(pid);  
#else  
return Qnil;  
@@ -1699,5 +1710,5 @@ static VALUE  
proc\_getpgrp(void)  
{

- int pgrp;

- rb\_pid\_t pgrp;

- return INT2FIX(pgrp);

- return PIDT2NUM(pgrp);  
#else

# ifdef HAVE\_GETPGID

```
 pgrp = getpgid(0);
 if (pgrp < 0) rb_sys_fail(0);

```

- return INT2FIX(pgrp);

- return PIDT2NUM(pgrp);

# else

```
 rb_notimplement();

```

@@ -1759,10 +1770,10 @@ proc\_getpgid(VALUE obj, VALUE pid)  
{  
#if defined(HAVE\_GETPGID) && !defined( **CHECKER** )

- int i;

- rb\_pid\_t i;

- i = getpgid(NUM2INT(pid));

- i = getpgid(NUM2PIDT(pid));  
if (i \< 0) rb\_sys\_fail(0);

- return INT2NUM(i);

- return PIDT2NUM(i);  
#else  
rb\_notimplement();  
@@ -1783,9 +1794,9 @@ proc\_setpgid(VALUE obj, VALUE pid, VALUE  
{  
#ifdef HAVE\_SETPGID

- int ipid, ipgrp;

- rb\_pid\_t ipid, ipgrp;

- ipid = NUM2INT(pid);
- ipgrp = NUM2INT(pgrp);

- ipid = NUM2PIDT(pid);

- ipgrp = NUM2PIDT(pgrp);

- int pid;

- rb\_pid\_t pid;

- return INT2FIX(pid);

- return PIDT2NUM(pid);  
#elif defined(HAVE\_SETPGRP) && defined(TIOCNOTTY)

- rb\_pid\_t pid;
- int ret;

- rb\_pid\_t pid;
- int ret;

- rb\_secure(2);
- pid = getpid();

- rb\_secure(2);
- pid = getpid();  
#if defined(SETPGRP\_VOID)

- ret = setpgrp();
- /\* If `pid\_t setpgrp(void)’ is equivalent to setsid(),
- 

```
`ret' will be the same value as `pid', and following open() will 

```

fail.

- 

```
In Linux, `int setpgrp(void)' is equivalent to setpgid(0, 0). */

```

-#else

- ret = setpgrp(0, pid);  
-#endif
- if (ret == -1) rb\_sys\_fail(0);
- 
- if ((fd = open("/dev/tty", O\_RDWR)) \>= 0) {
- ioctl(fd, TIOCNOTTY, NULL);
- close(fd);
- }
- return INT2FIX(pid);

- ret = setpgrp();
- /\* If `pid\_t setpgrp(void)’ is equivalent to setsid(),
- 

```
  `ret' will be the same value as `pid', and following open() will 

```

fail.

- 

```
  In Linux, `int setpgrp(void)' is equivalent to setpgid(0, 0). */

```

+#else

- ret = setpgrp(0, pid);  
+#endif
- if (ret == -1) rb\_sys\_fail(0);
- 
- if ((fd = open("/dev/tty", O\_RDWR)) \>= 0) {
- ioctl(fd, TIOCNOTTY, NULL);
- close(fd);
- }
- return PIDT2NUM(pid);  
#else  
rb\_notimplement();  
@@ -2068,5 +2079,5 @@ p\_sys\_setuid(VALUE obj, VALUE id)  
#if defined HAVE\_SETUID  
check\_uid\_switch();

- if (setuid(NUM2INT(id)) != 0) rb\_sys\_fail(0);

- if (setuid(NUM2UIDT(id)) != 0) rb\_sys\_fail(0);  
#else  
rb\_notimplement();  
@@ -2091,5 +2102,5 @@ p\_sys\_setruid(VALUE obj, VALUE id)  
#if defined HAVE\_SETRUID  
check\_uid\_switch();

- if (setruid(NUM2INT(id)) != 0) rb\_sys\_fail(0);

- if (setruid(NUM2UIDT(id)) != 0) rb\_sys\_fail(0);  
#else  
rb\_notimplement();  
@@ -2113,5 +2124,5 @@ p\_sys\_seteuid(VALUE obj, VALUE id)  
#if defined HAVE\_SETEUID  
check\_uid\_switch();

- if (seteuid(NUM2INT(id)) != 0) rb\_sys\_fail(0);

- if (seteuid(NUM2UIDT(id)) != 0) rb\_sys\_fail(0);  
#else  
rb\_notimplement();  
@@ -2137,5 +2148,5 @@ p\_sys\_setreuid(VALUE obj, VALUE rid, VAL  
#if defined HAVE\_SETREUID  
check\_uid\_switch();

- if (setreuid(NUM2INT(rid),NUM2INT(eid)) != 0) rb\_sys\_fail(0);

- if (setreuid(NUM2UIDT(rid),NUM2UIDT(eid)) != 0) rb\_sys\_fail(0);  
#else  
rb\_notimplement();  
@@ -2161,5 +2172,5 @@ p\_sys\_setresuid(VALUE obj, VALUE rid, VA  
#if defined HAVE\_SETRESUID  
check\_uid\_switch();

- if (setresuid(NUM2INT(rid),NUM2INT(eid),NUM2INT(sid)) != 0)  
rb\_sys\_fail(0);

- if (setresuid(NUM2UIDT(rid),NUM2UIDT(eid),NUM2UIDT(sid)) != 0)  
rb\_sys\_fail(0);  
#else  
rb\_notimplement();  
@@ -2183,6 +2194,6 @@ static VALUE  
proc\_getuid(VALUE obj)  
{

- int uid = getuid();
- return INT2FIX(uid);

- rb\_uid\_t uid = getuid();
- return UIDT2NUM(uid);  
}

@@ -2199,7 +2210,9 @@ static VALUE  
proc\_setuid(VALUE obj, VALUE id)  
{

- int uid = NUM2INT(id);

- rb\_uid\_t uid;

- 
- uid = NUM2UIDT(id);  
#if defined(HAVE\_SETRESUID) && !defined( **CHECKER** )  
if (setresuid(uid, -1, -1) \< 0) rb\_sys\_fail(0);  
@@ -2220,5 +2233,5 @@ proc\_setuid(VALUE obj, VALUE id)  
rb\_notimplement();  
#endif

- return INT2FIX(uid);

- return id;  
}

@@ -2234,5 +2247,5 @@ proc\_setuid(VALUE obj, VALUE id)  
\*/

-static int SAVED\_USER\_ID = -1;  
+static rb\_uid\_t SAVED\_USER\_ID = -1;

#ifdef BROKEN\_SETREUID  
@@ -2267,9 +2280,9 @@ static VALUE  
p\_uid\_change\_privilege(VALUE obj, VALUE id)  
{

- int uid;

- rb\_uid\_t uid;

- uid = NUM2INT(id);

- uid = NUM2UIDT(id);

- return INT2FIX(uid);

- return id;  
}

@@ -2418,5 +2431,5 @@ p\_sys\_setgid(VALUE obj, VALUE id)  
#if defined HAVE\_SETGID  
check\_gid\_switch();

- if (setgid(NUM2INT(id)) != 0) rb\_sys\_fail(0);

- if (setgid(NUM2GIDT(id)) != 0) rb\_sys\_fail(0);  
#else  
rb\_notimplement();  
@@ -2440,5 +2453,5 @@ p\_sys\_setrgid(VALUE obj, VALUE id)  
#if defined HAVE\_SETRGID  
check\_gid\_switch();

- if (setrgid(NUM2INT(id)) != 0) rb\_sys\_fail(0);

- if (setrgid(NUM2GIDT(id)) != 0) rb\_sys\_fail(0);  
#else  
rb\_notimplement();  
@@ -2463,5 +2476,5 @@ p\_sys\_setegid(VALUE obj, VALUE id)  
#if defined HAVE\_SETEGID  
check\_gid\_switch();

- if (setegid(NUM2INT(id)) != 0) rb\_sys\_fail(0);

- if (setegid(NUM2GIDT(id)) != 0) rb\_sys\_fail(0);  
#else  
rb\_notimplement();  
@@ -2487,5 +2500,5 @@ p\_sys\_setregid(VALUE obj, VALUE rid, VAL  
#if defined HAVE\_SETREGID  
check\_gid\_switch();

- if (setregid(NUM2INT(rid),NUM2INT(eid)) != 0) rb\_sys\_fail(0);

- if (setregid(NUM2GIDT(rid),NUM2GIDT(eid)) != 0) rb\_sys\_fail(0);  
#else  
rb\_notimplement();  
@@ -2510,5 +2523,5 @@ p\_sys\_setresgid(VALUE obj, VALUE rid, VA  
#if defined HAVE\_SETRESGID  
check\_gid\_switch();

- if (setresgid(NUM2INT(rid),NUM2INT(eid),NUM2INT(sid)) != 0)  
rb\_sys\_fail(0);

- if (setresgid(NUM2GIDT(rid),NUM2GIDT(eid),NUM2GIDT(sid)) != 0)  
rb\_sys\_fail(0);  
#else  
rb\_notimplement();  
@@ -2561,6 +2574,6 @@ static VALUE  
proc\_getgid(VALUE obj)  
{

- int gid = getgid();
- return INT2FIX(gid);

- rb\_gid\_t gid = getgid();
- return GIDT2NUM(gid);  
}

@@ -2576,7 +2589,9 @@ static VALUE  
proc\_setgid(VALUE obj, VALUE id)  
{

- int gid = NUM2INT(id);

- rb\_gid\_t gid;

- 
- gid = NUM2GIDT(id);  
#if defined(HAVE\_SETRESGID) && !defined( **CHECKER** )  
if (setresgid(gid, -1, -1) \< 0) rb\_sys\_fail(0);  
@@ -2597,5 +2612,5 @@ proc\_setgid(VALUE obj, VALUE id)  
rb\_notimplement();  
#endif

- return INT2FIX(gid);

- return GIDT2NUM(gid);  
}

@@ -2676,5 +2691,5 @@ proc\_setgroups(VALUE obj, VALUE ary)

if (FIXNUM\_P(g)) {

- 

```
 groups[i] = FIX2INT(g);

```

- 

```
 groups[i] = NUM2GIDT(g);

```

}  
else {  
@@ -2682,5 +2697,5 @@ proc\_setgroups(VALUE obj, VALUE ary)

```
 if (NIL_P(tmp)) {

```

- groups[i] = NUM2INT(g);

- groups[i] = NUM2GIDT(g);  
}  
else {  
@@ -2727,5 +2742,5 @@ proc\_initgroups(VALUE obj, VALUE uname,  
{  
#ifdef HAVE\_INITGROUPS

- if (initgroups(StringValuePtr(uname), (rb\_gid\_t)NUM2INT(base\_grp))  
!= 0) {

- if (initgroups(StringValuePtr(uname), NUM2GIDT(base\_grp)) != 0) {  
rb\_sys\_fail(0);  
}  
@@ -2873,9 +2888,9 @@ static VALUE  
p\_gid\_change\_privilege(VALUE obj, VALUE id)  
{

- int gid;

- rb\_gid\_t gid;

- gid = NUM2INT(id);

- gid = NUM2GIDT(id);

- return INT2FIX(gid);

- return id;  
}

@@ -3024,6 +3039,6 @@ static VALUE  
proc\_geteuid(VALUE obj)  
{

- int euid = geteuid();
- return INT2FIX(euid);

- rb\_uid\_t euid = geteuid();
- return NUM2UIDT(euid);  
}

@@ -3040,15 +3055,18 @@ static VALUE  
proc\_seteuid(VALUE obj, VALUE euid)  
{

- rb\_uid\_t uid;
- check\_uid\_switch();
- 
- uid = NUM2UIDT(euid);  
#if defined(HAVE\_SETRESUID) && !defined( **CHECKER** )

- if (setresuid(-1, NUM2INT(euid), -1) \< 0) rb\_sys\_fail(0);

- if (setresuid(-1, uid, -1) \< 0) rb\_sys\_fail(0);  
#elif defined HAVE\_SETREUID

- if (setreuid(-1, NUM2INT(euid)) \< 0) rb\_sys\_fail(0);

- if (setreuid(-1, uid) \< 0) rb\_sys\_fail(0);  
#elif defined HAVE\_SETEUID

- if (seteuid(NUM2INT(euid)) \< 0) rb\_sys\_fail(0);

- if (seteuid(uid) \< 0) rb\_sys\_fail(0);  
#elif defined HAVE\_SETUID

- euid = NUM2INT(euid);
- if (euid == getuid()) {
- if (setuid(euid) \< 0) rb\_sys\_fail(0);

- if (uid == getuid()) {
- if (setuid(uid) \< 0) rb\_sys\_fail(0);  
}  
else {  
@@ -3061,8 +3079,8 @@ proc\_seteuid(VALUE obj, VALUE euid)  
}

-static VALUE  
-rb\_seteuid\_core(int euid)  
+static rb\_uid\_t  
+rb\_seteuid\_core(rb\_uid\_t euid)  
{

- int uid;

- rb\_uid\_t uid;

- return INT2FIX(euid);

- return euid;  
}

@@ -3113,5 +3131,6 @@ static VALUE  
p\_uid\_grant\_privilege(VALUE obj, VALUE id)  
{

- return rb\_seteuid\_core(NUM2INT(id));

- rb\_seteuid\_core(NUM2UIDT(id));
- return id;  
}

@@ -3132,7 +3151,7 @@ static VALUE  
proc\_getegid(VALUE obj)  
{

- int egid = getegid();

- rb\_gid\_t egid = getegid();

- return INT2FIX(egid);

- return GIDT2NUM(egid);  
}

@@ -3149,16 +3168,18 @@ static VALUE  
proc\_setegid(VALUE obj, VALUE egid)  
{

- rb\_gid\_t gid;

- check\_gid\_switch();

- gid = NUM2GIDT(egid);  
#if defined(HAVE\_SETRESGID) && !defined( **CHECKER** )

- if (setresgid(-1, NUM2INT(egid), -1) \< 0) rb\_sys\_fail(0);

- if (setresgid(-1, gid, -1) \< 0) rb\_sys\_fail(0);  
#elif defined HAVE\_SETREGID

- if (setregid(-1, NUM2INT(egid)) \< 0) rb\_sys\_fail(0);

- if (setregid(-1, gid) \< 0) rb\_sys\_fail(0);  
#elif defined HAVE\_SETEGID

- if (setegid(NUM2INT(egid)) \< 0) rb\_sys\_fail(0);

- if (setegid(gid) \< 0) rb\_sys\_fail(0);  
#elif defined HAVE\_SETGID

- egid = NUM2INT(egid);
- if (egid == getgid()) {
- if (setgid(egid) \< 0) rb\_sys\_fail(0);

- if (gid == getgid()) {
- if (setgid(gid) \< 0) rb\_sys\_fail(0);  
}  
else {  
@@ -3171,8 +3192,8 @@ proc\_setegid(VALUE obj, VALUE egid)  
}

-static VALUE  
-rb\_setegid\_core(int egid)  
+static rb\_gid\_t  
+rb\_setegid\_core(rb\_gid\_t egid)  
{

- int gid;

- rb\_gid\_t gid;

- return INT2FIX(egid);

- return egid;  
}

@@ -3223,5 +3244,6 @@ static VALUE  
p\_gid\_grant\_privilege(VALUE obj, VALUE id)  
{

- return rb\_setegid\_core(NUM2INT(id));

- rb\_setegid\_core(NUM2GIDT(id));
- return id;  
}

@@ -3264,5 +3286,5 @@ static VALUE  
p\_uid\_exchange(VALUE obj)  
{

- int uid, euid;

- rb\_uid\_t uid, euid;

- return INT2FIX(uid);

- return UIDT2NUM(uid);  
}

@@ -3321,5 +3343,5 @@ static VALUE  
p\_gid\_exchange(VALUE obj)  
{

- int gid, egid;

- rb\_gid\_t gid, egid;

- return INT2FIX(gid);

- return GIDT2NUM(gid);  
}

@@ -3364,8 +3386,9 @@ p\_uid\_have\_saved\_id(void)  
#if defined(HAVE\_SETRESUID) || defined(HAVE\_SETEUID) ||  
defined(\_POSIX\_SAVED\_IDS)  
static VALUE  
-p\_uid\_sw\_ensure(int id)  
+p\_uid\_sw\_ensure(rb\_uid\_t id)  
{  
under\_uid\_switch = 0;

- return rb\_seteuid\_core(id);

- id = rb\_seteuid\_core(id);
- return UIDT2NUM(id);  
}

@@ -3387,5 +3410,5 @@ static VALUE  
p\_uid\_switch(VALUE obj)  
{

- int uid, euid;

- rb\_uid\_t uid, euid;

- proc\_seteuid(obj, INT2FIX(uid));

- proc\_seteuid(obj, UIDT2NUM(uid));  
if (rb\_block\_given\_p()) {  
under\_uid\_switch = 1;  
return rb\_ensure(rb\_yield, Qnil, p\_uid\_sw\_ensure, SAVED\_USER\_ID);  
} else {

- 

```
 return INT2FIX(euid);

```

- 

```
 return UIDT2NUM(euid);

```

}  
} else if (euid != SAVED\_USER\_ID) {

- proc\_seteuid(obj, INT2FIX(SAVED\_USER\_ID));

- proc\_seteuid(obj, UIDT2NUM(SAVED\_USER\_ID));  
if (rb\_block\_given\_p()) {  
under\_uid\_switch = 1;  
return rb\_ensure(rb\_yield, Qnil, p\_uid\_sw\_ensure, euid);  
} else {

- 

```
 return INT2FIX(uid);

```

- 

```
 return UIDT2NUM(uid);

```

}  
} else {  
@@ -3414,5 +3437,5 @@ p\_uid\_switch(VALUE obj)  
rb\_sys\_fail(0);  
}

- 

+}  
#else  
static VALUE  
@@ -3426,5 +3449,5 @@ static VALUE  
p\_uid\_switch(VALUE obj)  
{

- int uid, euid;

- rb\_uid\_t uid, euid;

- return INT2FIX(euid);

- return UIDT2NUM(euid);  
}  
-#endif  
}  
+#endif

@@ -3471,8 +3494,9 @@ p\_gid\_have\_saved\_id(void)  
#if defined(HAVE\_SETRESGID) || defined(HAVE\_SETEGID) ||  
defined(\_POSIX\_SAVED\_IDS)  
static VALUE  
-p\_gid\_sw\_ensure(int id)  
+p\_gid\_sw\_ensure(rb\_gid\_t id)  
{  
under\_gid\_switch = 0;

- return rb\_setegid\_core(id);

- id = rb\_setegid\_core(id);
- return GIDT2NUM(id);  
}

@@ -3502,18 +3526,18 @@ p\_gid\_switch(VALUE obj)

```
 if (gid != egid) {

```

- proc\_setegid(obj, INT2FIX(gid));

- proc\_setegid(obj, GIDT2NUM(gid));  
if (rb\_block\_given\_p()) {  
under\_gid\_switch = 1;  
return rb\_ensure(rb\_yield, Qnil, p\_gid\_sw\_ensure,  
SAVED\_GROUP\_ID);  
} else {

- 

```
 return INT2FIX(egid);

```

- 

```
 return GIDT2NUM(egid);

```

}  
} else if (egid != SAVED\_GROUP\_ID) {

- proc\_setegid(obj, INT2FIX(SAVED\_GROUP\_ID));

- proc\_setegid(obj, GIDT2NUM(SAVED\_GROUP\_ID));  
if (rb\_block\_given\_p()) {  
under\_gid\_switch = 1;  
return rb\_ensure(rb\_yield, Qnil, p\_gid\_sw\_ensure, egid);  
} else {

- 

```
 return INT2FIX(gid);

```

- 

```
 return GIDT2NUM(gid);

```

}  
} else {  
@@ -3521,4 +3545,5 @@ p\_gid\_switch(VALUE obj)  
rb\_sys\_fail(0);  
}  
+}  
#else  
static VALUE  
@@ -3532,5 +3557,5 @@ static VALUE  
p\_gid\_switch(VALUE obj)  
{

- int gid, egid;

- rb\_gid\_t gid, egid;

- return INT2FIX(egid);

- return GIDT2NUM(egid);  
}  
-#endif  
}  
+#endif

# Index: ruby.h

— ruby.h (revision 11768)  
+++ ruby.h (working copy)  
@@ -188,4 +188,37 @@ VALUE rb\_ull2inum(unsigned LONG\_LONG);  
#endif

# +#if SIZEOF\_PID\_T \> SIZEOF\_LONG && defined(HAVE\_LONG\_LONG) +# define PIDT2NUM(v) LL2NUM(v) +# define NUM2PIDT(v) NUM2LL(v) +#elif SIZEOF\_PID\_T == SIZEOF\_LONG +# define PIDT2NUM(v) LONG2NUM(v) +# define NUM2PIDT(v) NUM2LONG(v) +#else +# define PIDT2NUM(v) INT2NUM(v) +# define NUM2PIDT(v) NUM2INT(v) +#endif + +#if SIZEOF\_UID\_T \> SIZEOF\_LONG && defined(HAVE\_LONG\_LONG) +# define UIDT2NUM(v) LL2NUM(v) +# define NUM2UIDT(v) NUM2LL(v) +#elif SIZEOF\_UID\_T == SIZEOF\_LONG +# define UIDT2NUM(v) LONG2NUM(v) +# define NUM2UIDT(v) NUM2LONG(v) +#else +# define UIDT2NUM(v) INT2NUM(v) +# define NUM2UIDT(v) NUM2INT(v) +#endif + +#if SIZEOF\_GID\_T \> SIZEOF\_LONG && defined(HAVE\_LONG\_LONG) +# define GIDT2NUM(v) LL2NUM(v) +# define NUM2GIDT(v) NUM2LL(v) +#elif SIZEOF\_GID\_T == SIZEOF\_LONG +# define GIDT2NUM(v) LONG2NUM(v) +# define NUM2GIDT(v) NUM2LONG(v) +#else +# define GIDT2NUM(v) INT2NUM(v) +# define NUM2GIDT(v) NUM2INT(v) +#endif + #define FIX2LONG(x) RSHIFT((SIGNED\_VALUE)x,1) #define FIX2ULONG(x) (((VALUE)(x))\>\>1) Index: rubyio.h

— rubyio.h (revision 11768)  
+++ rubyio.h (working copy)  
@@ -25,5 +25,5 @@ typedef struct OpenFile {  
FILE _stdio\_file; /_ stdio ptr for read/write if available _/  
int mode; /_ mode flags \*/

- int pid; /\* child’s pid (for pipes) \*/

- rb\_pid\_t pid; /\* child’s pid (for pipes) _/  
int lineno; /_ number of lines read \*/  
char _path; /_ pathname for file \*/  
Index: ext/etc/etc.c  
===================================================================  
— ext/etc/etc.c (revision 11768)  
+++ ext/etc/etc.c (working copy)  
@@ -77,6 +77,6 @@ setup\_passwd(struct passwd \*pwd)  
safe\_setup\_str(pwd-\>pw\_passwd),  
#endif

- 

```
  PW_UID2VAL(pwd->pw_uid),

```

- 

```
  PW_GID2VAL(pwd->pw_gid),

```

- 

```
  UIDT2NUM(pwd->pw_uid),

```

- 

```
  GIDT2NUM(pwd->pw_gid),

```

#ifdef HAVE\_ST\_PW\_GECOS  
safe\_setup\_str(pwd-\>pw\_gecos),  
@@ -126,5 +126,5 @@ etc\_getpwuid(int argc, VALUE \*argv, VALU  
rb\_secure(4);  
if (rb\_scan\_args(argc, argv, “01”, &id) == 1) {

- uid = PW\_VAL2UID(id);

- uid = NUM2UIDT(id);  
}  
else {  
@@ -302,5 +302,5 @@ setup\_group(struct group \*grp)  
safe\_setup\_str(grp-\>gr\_passwd),  
#endif

- 

```
  PW_GID2VAL(grp->gr_gid),

```

- 

```
  GIDT2NUM(grp->gr_gid),
  mem);

```

# } Index: ext/pty/pty.c

— ext/pty/pty.c (revision 11768)  
+++ ext/pty/pty.c (working copy)  
@@ -148,5 +148,6 @@ static VALUE  
pty\_syswait(struct pty\_info \*info)  
{

- int cpid, status;

- rb\_pid\_t cpid;

- int status;

- rb\_pid\_t pid;  
char \*p,\*getenv();  
struct passwd \*pwent;  
@@ -219,5 +221,5 @@ establishShell(int argc, VALUE \*argv, st

- if((i = fork()) \< 0) {

- if ((pid = fork()) \< 0) {  
close(master);  
close(slave);  
@@ -225,5 +227,5 @@ establishShell(int argc, VALUE \*argv, st  
}

- if(i == 0) { /\* child \*/

- if (pid == 0) { /\* child _/  
/_

```
* Set free from process group and controlling terminal

```

@@ -283,5 +285,5 @@ establishShell(int argc, VALUE \*argv, st  
close(slave);

- info-\>child\_pid = i;

- info-\>child\_pid = pid;  
info-\>fd = master;  
}  
@@ -421,5 +423,5 @@ pty\_getpty(int argc, VALUE \*argv, VALUE  
rb\_ary\_store(res,0,(VALUE)rport);  
rb\_ary\_store(res,1,(VALUE)wport);

- rb\_ary\_store(res,2,INT2FIX(info.child\_pid));

- rb\_ary\_store(res,2,PIDT2NUM(info.child\_pid));

-int  
+rb\_pid\_t  
rb\_w32\_spawn(int mode, const char \*cmd, const char \*prog)  
{  
@@ -878,5 +878,5 @@ rb\_w32\_spawn(int mode, const char \*cmd,  
}

-int  
+rb\_pid\_t  
rb\_w32\_aspawn(int mode, const char \*prog, char \*const \*argv)  
{  
@@ -2953,5 +2953,5 @@ poll\_child\_status(struct ChildRecord \*ch

# rb\_pid\_t -waitpid (rb\_pid\_t pid, int \*stat\_loc, int options) +waitpid(rb\_pid\_t pid, int \*stat\_loc, int options) { DWORD timeout; Index: win32/win32.h

— win32/win32.h (revision 11768)  
+++ win32/win32.h (working copy)  
@@ -230,6 +230,6 @@ extern rb\_pid\_t waitpid (rb\_pid\_t, int \*  
extern int rb\_w32\_argv\_size(char \*const \*);  
extern char \*rb\_w32\_join\_argv(char \*, char \*const \*);  
-extern int rb\_w32\_spawn(int, const char _, const char_);  
-extern int rb\_w32\_aspawn(int, const char \*, char \*const \*);  
+extern rb\_pid\_t rb\_w32\_spawn(int, const char _, const char_);  
+extern rb\_pid\_t rb\_w32\_aspawn(int, const char \*, char \*const \*);  
extern int kill(int, int);  
extern int fcntl(int, int, …);

---

<div class="post-metadata">

**Author:** ![nobu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/e9c0ed/32.png) [@nobu](https://www.ruby-forum.com/u/nobu)\
**Post date:** [February 17, 2007, 4:04pm UTC](https://www.ruby-forum.com/t/uid-t-gid-t-may-be-bigger-than-plain-int-type/85913/2 "2007-02-17T16:04:37Z")

</div>

e$B$^$D$b$He(B e$B$f$-$R$m$G$9e(B

In message “Re: [ruby-dev:30376] uid\_t/gid\_t may be bigger than plain  
‘int’ type”  
on Sat, 17 Feb 2007 23:35:32 +0900, Nobuyoshi N.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) writes:

|e$B$7$P$i$/A0$Ke(B[ruby-core:08897]e$B$GJs9p$5$l$?OC$G$9$,!"e(Buide$B$de(Bgide$B!"e(B  
|e$B$D$$$G$Ke(Bpide$B$bI,$:$7$be(Binte$B$G%+%P!\<$G$-$k$H$O$+$.$j$^$;$s!#:#$N$He(B  
|e$B$3$me(Bext/etce$B$G$Oe(Buid\_t,gid\_te$B$K$D$$$F$@$1$OBP1~$5$l$F$$$^$9$,!"e(B  
|e$B3:Ev$9$kItJ,$Oe(Brb\_pid\_t, rb\_uid\_t, rb\_gid\_te$B$r;H$&$Y$-$G$O$J$$$+e(B  
|e$B$H;W$$$^$9!#e(B

e$B%3%\_%C%H$7$F$/$@$5$$!#e(B
