Skip to content

Commit dd2dee3

Browse files
committed
Fix prototypes of {g,s}etrlimit/{g,s}etrusage/{g,s}etpriority
For c++, we must not an enum, otherwise code like setrlimit(0,...) will fail with 'invalid conversion from int to enum'. Corresponding types are present already in glibc since 2000
1 parent f204057 commit dd2dee3

File tree

6 files changed

+29
-15
lines changed

6 files changed

+29
-15
lines changed

include/sys/resource.h

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -99,19 +99,33 @@ struct rlimit
9999
*/
100100
};
101101

102+
/* The X/Open standard defines that all the functions below must use
103+
`int' as the type for the first argument. When we are compiling with
104+
GNU extensions we change this slightly to provide better error
105+
checking. */
106+
#if defined __USE_GNU && !defined __cplusplus
107+
typedef enum __rlimit_resource __rlimit_resource_t;
108+
typedef enum __rusage_who __rusage_who_t;
109+
typedef enum __priority_which __priority_which_t;
110+
#else
111+
typedef int __rlimit_resource_t;
112+
typedef int __rusage_who_t;
113+
typedef int __priority_which_t;
114+
#endif
115+
102116
/* Put the soft and hard limits for RESOURCE in *RLIMITS.
103117
Returns 0 if successful, -1 if not (and sets errno). */
104-
extern int getrlimit (enum __rlimit_resource __resource,
118+
extern int getrlimit (__rlimit_resource_t __resource,
105119
struct rlimit *__rlimits) __THROW;
106-
extern int __getrlimit (enum __rlimit_resource __resource,
120+
extern int __getrlimit (__rlimit_resource_t __resource,
107121
struct rlimit *__rlimits) __THROW;
108122

109123
/* Set the soft and hard limits for RESOURCE to *RLIMITS.
110124
Only the super-user can increase hard limits.
111125
Return 0 if successful, -1 if not (and sets errno). */
112-
extern int setrlimit (enum __rlimit_resource __resource,
126+
extern int setrlimit (__rlimit_resource_t __resource,
113127
struct rlimit *__rlimits) __THROW;
114-
extern int __setrlimit (enum __rlimit_resource __resource,
128+
extern int __setrlimit (__rlimit_resource_t __resource,
115129
struct rlimit *__rlimits) __THROW;
116130

117131
/* Possible values for first argument to `getrusage'. */
@@ -127,9 +141,9 @@ enum __rusage_who
127141

128142
/* Return resource usage information on process indicated by WHO
129143
and put it in *USAGE. Returns 0 for success, -1 for failure. */
130-
extern int getrusage (enum __rusage_who __who,
144+
extern int getrusage (__rusage_who_t __who,
131145
struct rusage *__usage) __THROW;
132-
extern int __getrusage (enum __rusage_who __who,
146+
extern int __getrusage (__rusage_who_t __who,
133147
struct rusage *__usage) __THROW;
134148

135149
#if 0
@@ -172,14 +186,14 @@ enum __priority_which
172186
(see above); if WHO is zero, the current process, process group, or user
173187
(as specified by WHO) is used. A lower priority number means higher
174188
priority. Priorities range from PRIO_MIN to PRIO_MAX (above). */
175-
extern int getpriority (enum __priority_which __which, int __who) __THROW;
176-
extern int __getpriority (enum __priority_which __which, int __who) __THROW;
189+
extern int getpriority (__priority_which_t __which, int __who) __THROW;
190+
extern int __getpriority (__priority_which_t __which, int __who) __THROW;
177191

178192
/* Set the priority of all processes specified by WHICH and WHO (see above)
179193
to PRIO. Returns 0 on success, -1 on errors. */
180-
extern int setpriority (enum __priority_which __which, int __who,
194+
extern int setpriority (__priority_which_t __which, int __who,
181195
int __prio) __THROW;
182-
extern int __setpriority (enum __priority_which __which, int __who,
196+
extern int __setpriority (__priority_which_t __which, int __who,
183197
int __prio) __THROW;
184198

185199
/* Increment the priority of the current process by INCREMENT. Return

unix/getpriority.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ static int have_Prenice = 1;
1919
static int have_Pnice = 1;
2020

2121
int
22-
__getpriority (enum __priority_which class, int id)
22+
__getpriority (__priority_which_t class, int id)
2323
{
2424
if (class != PRIO_PROCESS && class != PRIO_PGRP && class != PRIO_USER)
2525
{

unix/getrlimit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
long __sysconf (int var);
1212

1313
int
14-
__getrlimit (enum __rlimit_resource kind, struct rlimit *rl)
14+
__getrlimit (__rlimit_resource_t kind, struct rlimit *rl)
1515
{
1616
long limit;
1717
int mode;

unix/getrusage.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ _add_tval(struct timeval *orig, struct timeval *new)
3535
#endif
3636

3737
int
38-
__getrusage(enum __rusage_who which, struct rusage *data)
38+
__getrusage(__rusage_who_t which, struct rusage *data)
3939
{
4040
long r;
4141
long usage[8];

unix/setpriority.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ static int have_Prenice = 1;
1919
static int have_Pnice = 1;
2020

2121
int
22-
__setpriority (enum __priority_which class, int id, int priority)
22+
__setpriority (__priority_which_t class, int id, int priority)
2323
{
2424
int saved_priority;
2525
int increment;

unix/setrlimit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#include <mint/mintbind.h>
99

1010
int
11-
__setrlimit (enum __rlimit_resource kind, struct rlimit *rl)
11+
__setrlimit (__rlimit_resource_t kind, struct rlimit *rl)
1212
{
1313
unsigned long limit;
1414
int mode;

0 commit comments

Comments
 (0)