Updates to Tomato RAF including NGINX && PHP
[tomato.git] / release / src / router / php / ext / standard / pageinfo.c
blob6add7269cf23cf8015cc303c247bece4dea7db3e
1 /*
2 +----------------------------------------------------------------------+
3 | PHP Version 5 |
4 +----------------------------------------------------------------------+
5 | Copyright (c) 1997-2013 The PHP Group |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
15 | Author: Jim Winstead <jimw@php.net> |
16 +----------------------------------------------------------------------+
19 /* $Id$ */
21 #include "php.h"
22 #include "pageinfo.h"
23 #include "SAPI.h"
25 #include <stdio.h>
26 #include <stdlib.h>
27 #if HAVE_PWD_H
28 #ifdef PHP_WIN32
29 #include "win32/pwd.h"
30 #else
31 #include <pwd.h>
32 #endif
33 #endif
34 #if HAVE_GRP_H
35 # ifdef PHP_WIN32
36 # include "win32/grp.h"
37 # else
38 # include <grp.h>
39 # endif
40 #endif
41 #ifdef PHP_WIN32
42 #undef getgid
43 #define getgroups(a, b) 0
44 #define getgid() 1
45 #define getuid() 1
46 #endif
47 #if HAVE_UNISTD_H
48 #include <unistd.h>
49 #endif
50 #include <sys/stat.h>
51 #include <sys/types.h>
52 #ifdef PHP_WIN32
53 #include <process.h>
54 #endif
56 #include "ext/standard/basic_functions.h"
58 /* {{{ php_statpage
60 PHPAPI void php_statpage(TSRMLS_D)
62 struct stat *pstat;
64 pstat = sapi_get_stat(TSRMLS_C);
66 if (BG(page_uid)==-1 || BG(page_gid)==-1) {
67 if(pstat) {
68 BG(page_uid) = pstat->st_uid;
69 BG(page_gid) = pstat->st_gid;
70 BG(page_inode) = pstat->st_ino;
71 BG(page_mtime) = pstat->st_mtime;
72 } else { /* handler for situations where there is no source file, ex. php -r */
73 BG(page_uid) = getuid();
74 BG(page_gid) = getgid();
78 /* }}} */
80 /* {{{ php_getuid
82 long php_getuid(TSRMLS_D)
84 php_statpage(TSRMLS_C);
85 return (BG(page_uid));
87 /* }}} */
89 long php_getgid(TSRMLS_D)
91 php_statpage(TSRMLS_C);
92 return (BG(page_gid));
95 /* {{{ proto int getmyuid(void)
96 Get PHP script owner's UID */
97 PHP_FUNCTION(getmyuid)
99 long uid;
101 if (zend_parse_parameters_none() == FAILURE) {
102 return;
105 uid = php_getuid(TSRMLS_C);
106 if (uid < 0) {
107 RETURN_FALSE;
108 } else {
109 RETURN_LONG(uid);
112 /* }}} */
114 /* {{{ proto int getmygid(void)
115 Get PHP script owner's GID */
116 PHP_FUNCTION(getmygid)
118 long gid;
120 if (zend_parse_parameters_none() == FAILURE) {
121 return;
124 gid = php_getgid(TSRMLS_C);
125 if (gid < 0) {
126 RETURN_FALSE;
127 } else {
128 RETURN_LONG(gid);
131 /* }}} */
133 /* {{{ proto int getmypid(void)
134 Get current process ID */
135 PHP_FUNCTION(getmypid)
137 int pid;
139 if (zend_parse_parameters_none() == FAILURE) {
140 return;
143 pid = getpid();
144 if (pid < 0) {
145 RETURN_FALSE;
146 } else {
147 RETURN_LONG((long) pid);
150 /* }}} */
152 /* {{{ proto int getmyinode(void)
153 Get the inode of the current script being parsed */
154 PHP_FUNCTION(getmyinode)
156 if (zend_parse_parameters_none() == FAILURE) {
157 return;
160 php_statpage(TSRMLS_C);
161 if (BG(page_inode) < 0) {
162 RETURN_FALSE;
163 } else {
164 RETURN_LONG(BG(page_inode));
167 /* }}} */
169 PHPAPI long php_getlastmod(TSRMLS_D)
171 php_statpage(TSRMLS_C);
172 return BG(page_mtime);
175 /* {{{ proto int getlastmod(void)
176 Get time of last page modification */
177 PHP_FUNCTION(getlastmod)
179 long lm;
181 if (zend_parse_parameters_none() == FAILURE) {
182 return;
185 lm = php_getlastmod(TSRMLS_C);
186 if (lm < 0) {
187 RETURN_FALSE;
188 } else {
189 RETURN_LONG(lm);
192 /* }}} */
194 /*nma
195 * Local variables:
196 * tab-width: 4
197 * c-basic-offset: 4
198 * End:
199 * vim600: sw=4 ts=4 fdm=marker
200 * vim<600: sw=4 ts=4