OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [uClibc/] [libc/] [sysdeps/] [linux/] [common/] [ulimit.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1325 phoenix
/* vi: set sw=4 ts=4: */
2
/*
3
 * Copyright (C) 2003 by Erik Andersen <andersen@codpoet.org>
4
 *
5
 * This program is free software; you can redistribute it and/or modify it
6
 * under the terms of the GNU Library General Public License as published by
7
 * the Free Software Foundation; either version 2 of the License, or (at your
8
 * option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful, but WITHOUT
11
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License
13
 * for more details.
14
 *
15
 * You should have received a copy of the GNU Library General Public License
16
 * along with this program; if not, write to the Free Software Foundation,
17
 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
 *
19
 */
20
 
21
#define _GNU_SOURCE
22
#define _LARGEFILE64_SOURCE
23
#include <features.h>
24
#undef __OPTIMIZE__
25
/* We absolutely do _NOT_ want interfaces silently
26
 *  *  * renamed under us or very bad things will happen... */
27
#ifdef __USE_FILE_OFFSET64
28
# undef __USE_FILE_OFFSET64
29
#endif
30
 
31
 
32
#ifdef __NR_ulimit
33
 
34
#include <sys/types.h>
35
#include <sys/syscall.h>
36
 
37
_syscall2(long, ulimit, int, cmd, int, arg);
38
 
39
#else
40
 
41
#include <stdarg.h>
42
#include <unistd.h>
43
#include <ulimit.h>
44
#include <errno.h>
45
#include <sys/resource.h>
46
 
47
long int ulimit(int cmd, ...)
48
{
49
        va_list va;
50
        struct rlimit limit;
51
        long int result = -1;
52
        va_start (va, cmd);
53
        switch (cmd) {
54
                /* Get limit on file size.  */
55
                case UL_GETFSIZE:
56
                        if (getrlimit(RLIMIT_FSIZE, &limit) == 0)
57
                                result =  limit.rlim_cur / 512; /* bytes to 512 byte blocksize */
58
                        break;
59
                /* Set limit on file size.  */
60
                case UL_SETFSIZE:
61
                        result = va_arg (va, long int);
62
                        if ((rlim_t) result > RLIM_INFINITY / 512) {
63
                                limit.rlim_cur = RLIM_INFINITY;
64
                                limit.rlim_max = RLIM_INFINITY;
65
                        } else {
66
                                limit.rlim_cur = result * 512;
67
                                limit.rlim_max = result * 512;
68
                        }
69
                        result = setrlimit(RLIMIT_FSIZE, &limit);
70
                        break;
71
                case __UL_GETOPENMAX:
72
                        result = sysconf(_SC_OPEN_MAX);
73
                        break;
74
                default:
75
                        __set_errno(EINVAL);
76
        }
77
        va_end (va);
78
        return result;
79
}
80
#endif
81
 

powered by: WebSVN 2.1.0

© copyright 1999-2025 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.