BSD-Resource
view release on metacpan or search on metacpan
Resource.xs view on Meta::CPAN
/*
* Copyright (c) 1995-2017 Jarkko Hietaniemi. All rights reserved.
* For license see COPYRIGHT and LICENSE in Resource.pm.
*
* Resource.xs
*
*/
#ifdef __cplusplus
extern "C" {
#endif
#define PERL_NO_GET_CONTEXT
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#include "ppport.h"
#ifdef WIN32
# include <time.h>
#else
# include <sys/time.h>
#endif
#ifdef HAS_SELECT
# ifdef I_SYS_SELECT
# include <sys/select.h>
# endif
#endif
#ifdef __cplusplus
}
#endif
#if defined(__hpux) && !defined(_INCLUDE_XOPEN_SOURCE_EXTENDED)
#define _INCLUDE_XOPEN_SOURCE_EXTENDED
#endif
/* If this fails your vendor has failed you and Perl cannot help. */
#include <sys/resource.h>
#if defined(__sun__) && defined(__svr4__) && !defined(SOLARIS_NO_PROCFS)
# define SOLARIS
# define SOLARIS_PROCFS
# ifdef I_SYS_RUSAGE
# include <sys/rusage.h>
/* Some old Solarises have no RUSAGE_* defined in <sys/resource.h>.
* There is <sys/rusage.h> which has but this file is very non-standard.
* More the fun, the file itself warns will not be there for long. */
# define part_of_sec tv_nsec
# endif
/* Solaris uses timerstruc_t in struct rusage. According to the <sys/time.h>
* in old Solarises tv_nsec in the timerstruc_t is nanoseconds (and the name
* also supports that theory) BUT getrusage() seems after all to tick
* microseconds, not nano. */
# define part_in_sec 0.000001
#
/* Newer Solarises (5.5 onwards) have much better support for rusage-kinda
* things via the proc interface. */
# define _STRUCTURED_PROC 1
# include <sys/procfs.h>
# include <fcntl.h>
# ifdef PIOCUSAGE
# undef SOLARIS_STRUCTURED_PROC
# else
# define SOLARIS_STRUCTURED_PROC
# endif
# ifdef SOLARIS_STRUCTURED_PROC
# define Struct_psinfo struct psinfo
# define Struct_pstatus struct pstatus
# else
# define Struct_psinfo struct prpsinfo
# define Struct_pstatus struct prstatus
# endif
#endif
#ifdef SOLARIS_NO_PROCFS
# define SOLARIS
# undef SOLARIS_PROCFS
# define TRY_GETRUSAGE_SYS_SYSCALL
#endif
#ifndef part_of_sec
#define part_of_sec tv_usec
#define part_in_sec 0.000001
#endif
#define IDM ((double)part_in_sec)
#define TV2DS(tv) ((double)tv.tv_sec+(double)tv.part_of_sec*part_in_sec)
#ifndef HAS_GETRUSAGE
# if defined(RUSAGE_SELF) || defined(SOLARIS)
# define HAS_GETRUSAGE
# endif
#endif
#if defined(OS2) && !defined(PRIO_PROCESS)
# define PRIO_PROCESS 0 /* This argument is ignored anyway. */
#endif
#if defined(__hpux) && defined(RLIMIT_NLIMITS)
/* there is getrusage() in HPUX but only as an indirect syscall */
# define TRY_GETRUSAGE_AS_SYSCALL
/* some rlimits exist (but are officially unsupported by HP) */
# ifndef RLIMIT_CPU
# define RLIMIT_CPU 0
# endif
# ifndef RLIMIT_FSIZE
# define RLIMIT_FSIZE 1
# endif
# ifndef RLIMIT_DATA
( run in 0.977 second using v1.01-cache-2.11-cpan-6aa56a78535 )