#include "php.h"
#include "pageinfo.h"
#include "SAPI.h"
#include <stdio.h>
#include <stdlib.h>
#if HAVE_PWD_H
#ifdef PHP_WIN32
#include "win32/pwd.h"
#else
#include <pwd.h>
#endif
#endif
#if HAVE_GRP_H
# ifdef PHP_WIN32
# include "win32/grp.h"
# else
# include <grp.h>
# endif
#endif
#ifdef PHP_WIN32
#undef getgid
#define getgroups(a, b) 0
#define getgid() 1
#define getuid() 1
#endif
#if HAVE_UNISTD_H
#include <unistd.h>
#endif
#include <sys/stat.h>
#include <sys/types.h>
#ifdef PHP_WIN32
#include <process.h>
#endif
#include "ext/standard/basic_functions.h"
PHPAPI void php_statpage(void)
{
zend_stat_t *pstat;
pstat = sapi_get_stat();
if (BG(page_uid)==-1 || BG(page_gid)==-1) {
if(pstat) {
BG(page_uid) = pstat->st_uid;
BG(page_gid) = pstat->st_gid;
BG(page_inode) = pstat->st_ino;
BG(page_mtime) = pstat->st_mtime;
} else {
BG(page_uid) = getuid();
BG(page_gid) = getgid();
}
}
}
zend_long php_getuid(void)
{
php_statpage();
return (BG(page_uid));
}
zend_long php_getgid(void)
{
php_statpage();
return (BG(page_gid));
}
PHP_FUNCTION(getmyuid)
{
zend_long uid;
if (zend_parse_parameters_none() == FAILURE) {
return;
}
uid = php_getuid();
if (uid < 0) {
RETURN_FALSE;
} else {
RETURN_LONG(uid);
}
}
PHP_FUNCTION(getmygid)
{
zend_long gid;
if (zend_parse_parameters_none() == FAILURE) {
return;
}
gid = php_getgid();
if (gid < 0) {
RETURN_FALSE;
} else {
RETURN_LONG(gid);
}
}
PHP_FUNCTION(getmypid)
{
zend_long pid;
if (zend_parse_parameters_none() == FAILURE) {
return;
}
pid = getpid();
if (pid < 0) {
RETURN_FALSE;
} else {
RETURN_LONG(pid);
}
}
PHP_FUNCTION(getmyinode)
{
if (zend_parse_parameters_none() == FAILURE) {
return;
}
php_statpage();
if (BG(page_inode) < 0) {
RETURN_FALSE;
} else {
RETURN_LONG(BG(page_inode));
}
}
PHPAPI time_t php_getlastmod(void)
{
php_statpage();
return BG(page_mtime);
}
PHP_FUNCTION(getlastmod)
{
zend_long lm;
if (zend_parse_parameters_none() == FAILURE) {
return;
}
lm = php_getlastmod();
if (lm < 0) {
RETURN_FALSE;
} else {
RETURN_LONG(lm);
}
}