00001 00021 #include "util.h" 00022 00023 static char rcsid[] UNUSED = "$Id: datalimit.c,v 1.6 2008/04/25 07:00:55 fabio Exp $"; 00024 00025 #if HAVE_SYS_RESOURCE_H 00026 #if HAVE_SYS_TIME_H 00027 #include <sys/time.h> 00028 #endif 00029 #include <sys/resource.h> 00030 #endif 00031 00032 /*---------------------------------------------------------------------------*/ 00033 /* Type declarations */ 00034 /*---------------------------------------------------------------------------*/ 00035 00036 /*---------------------------------------------------------------------------*/ 00037 /* Structure declarations */ 00038 /*---------------------------------------------------------------------------*/ 00039 00040 /*---------------------------------------------------------------------------*/ 00041 /* Macro declarations */ 00042 /*---------------------------------------------------------------------------*/ 00043 00044 #ifndef RLIMIT_DATA_DEFAULT 00045 #define RLIMIT_DATA_DEFAULT 67108864 /* assume 64MB by default */ 00046 #endif 00047 00048 /*---------------------------------------------------------------------------*/ 00049 /* Variable declarations */ 00050 /*---------------------------------------------------------------------------*/ 00051 00054 /*---------------------------------------------------------------------------*/ 00055 /* Static function prototypes */ 00056 /*---------------------------------------------------------------------------*/ 00057 00060 /*---------------------------------------------------------------------------*/ 00061 /* Definition of exported functions */ 00062 /*---------------------------------------------------------------------------*/ 00063 00071 unsigned long 00072 getSoftDataLimit(void) 00073 { 00074 #if HAVE_SYS_RESOURCE_H && HAVE_GETRLIMIT && defined(RLIMIT_DATA) 00075 struct rlimit rl; 00076 int result; 00077 00078 result = getrlimit(RLIMIT_DATA, &rl); 00079 if (result != 0 || rl.rlim_cur == RLIM_INFINITY) 00080 return((unsigned long) RLIMIT_DATA_DEFAULT); 00081 else 00082 return((unsigned long) rl.rlim_cur); 00083 #else 00084 return((unsigned long) RLIMIT_DATA_DEFAULT); 00085 #endif 00086 00087 } /* end of getSoftDataLimit */ 00088 00089 /*---------------------------------------------------------------------------*/ 00090 /* Definition of internal functions */ 00091 /*---------------------------------------------------------------------------*/ 00092 00093 /*---------------------------------------------------------------------------*/ 00094 /* Definition of static functions */ 00095 /*---------------------------------------------------------------------------*/