* process.c (rlimit_resource_name2int): use STRCASECMP to avoid
ALLOCA_N. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29226 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
da47bbd1db
commit
b4ac655acc
@ -1,3 +1,8 @@
|
|||||||
|
Sun Sep 12 04:27:13 2010 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
|
* process.c (rlimit_resource_name2int): use STRCASECMP to avoid
|
||||||
|
ALLOCA_N.
|
||||||
|
|
||||||
Sat Sep 11 16:47:41 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Sat Sep 11 16:47:41 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* hash.c (ruby_setenv): raise if putenv and SetEnvironmentVariable
|
* hash.c (ruby_setenv): raise if putenv and SetEnvironmentVariable
|
||||||
|
66
process.c
66
process.c
@ -3578,79 +3578,95 @@ proc_setpriority(VALUE obj, VALUE which, VALUE who, VALUE prio)
|
|||||||
static int
|
static int
|
||||||
rlimit_resource_name2int(const char *name, int casetype)
|
rlimit_resource_name2int(const char *name, int casetype)
|
||||||
{
|
{
|
||||||
size_t len = strlen(name);
|
int resource;
|
||||||
if (16 < len) return -1;
|
const char *p;
|
||||||
if (casetype == 1) {
|
#define RESCHECK(r) \
|
||||||
size_t i;
|
do { \
|
||||||
char *name2 = ALLOCA_N(char, len+1);
|
if (STRCASECMP(name, #r) == 0) { \
|
||||||
for (i = 0; i < len; i++) {
|
resource = RLIMIT_##r; \
|
||||||
if (!ISLOWER(name[i]))
|
goto found; \
|
||||||
return -1;
|
} \
|
||||||
name2[i] = TOUPPER(name[i]);
|
} while (0)
|
||||||
}
|
|
||||||
name2[len] = '\0';
|
|
||||||
name = name2;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (*name) {
|
switch (TOUPPER(*name)) {
|
||||||
case 'A':
|
case 'A':
|
||||||
#ifdef RLIMIT_AS
|
#ifdef RLIMIT_AS
|
||||||
if (strcmp(name, "AS") == 0) return RLIMIT_AS;
|
RESCHECK(AS);
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'C':
|
case 'C':
|
||||||
#ifdef RLIMIT_CORE
|
#ifdef RLIMIT_CORE
|
||||||
if (strcmp(name, "CORE") == 0) return RLIMIT_CORE;
|
RESCHECK(CORE);
|
||||||
#endif
|
#endif
|
||||||
#ifdef RLIMIT_CPU
|
#ifdef RLIMIT_CPU
|
||||||
if (strcmp(name, "CPU") == 0) return RLIMIT_CPU;
|
RESCHECK(CPU);
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'D':
|
case 'D':
|
||||||
#ifdef RLIMIT_DATA
|
#ifdef RLIMIT_DATA
|
||||||
if (strcmp(name, "DATA") == 0) return RLIMIT_DATA;
|
RESCHECK(DATA);
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'F':
|
case 'F':
|
||||||
#ifdef RLIMIT_FSIZE
|
#ifdef RLIMIT_FSIZE
|
||||||
if (strcmp(name, "FSIZE") == 0) return RLIMIT_FSIZE;
|
RESCHECK(FSIZE);
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'M':
|
case 'M':
|
||||||
#ifdef RLIMIT_MEMLOCK
|
#ifdef RLIMIT_MEMLOCK
|
||||||
if (strcmp(name, "MEMLOCK") == 0) return RLIMIT_MEMLOCK;
|
RESCHECK(MEMLOCK);
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'N':
|
case 'N':
|
||||||
#ifdef RLIMIT_NOFILE
|
#ifdef RLIMIT_NOFILE
|
||||||
if (strcmp(name, "NOFILE") == 0) return RLIMIT_NOFILE;
|
RESCHECK(NOFILE);
|
||||||
#endif
|
#endif
|
||||||
#ifdef RLIMIT_NPROC
|
#ifdef RLIMIT_NPROC
|
||||||
if (strcmp(name, "NPROC") == 0) return RLIMIT_NPROC;
|
RESCHECK(NPROC);
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'R':
|
case 'R':
|
||||||
#ifdef RLIMIT_RSS
|
#ifdef RLIMIT_RSS
|
||||||
if (strcmp(name, "RSS") == 0) return RLIMIT_RSS;
|
RESCHECK(RSS);
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'S':
|
case 'S':
|
||||||
#ifdef RLIMIT_STACK
|
#ifdef RLIMIT_STACK
|
||||||
if (strcmp(name, "STACK") == 0) return RLIMIT_STACK;
|
RESCHECK(STACK);
|
||||||
#endif
|
#endif
|
||||||
#ifdef RLIMIT_SBSIZE
|
#ifdef RLIMIT_SBSIZE
|
||||||
if (strcmp(name, "SBSIZE") == 0) return RLIMIT_SBSIZE;
|
RESCHECK(SBSIZE);
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
found:
|
||||||
|
switch (casetype) {
|
||||||
|
case 0:
|
||||||
|
for (p = name; *p; p++)
|
||||||
|
if (!ISUPPER(*p))
|
||||||
|
return -1;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 1:
|
||||||
|
for (p = name; *p; p++)
|
||||||
|
if (!ISLOWER(*p))
|
||||||
|
return -1;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
rb_bug("unexpected casetype");
|
||||||
|
}
|
||||||
|
return resource;
|
||||||
|
#undef RESCHECK
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
Loading…
x
Reference in New Issue
Block a user