php-internal-docs
8.4.8
Unofficial docs for php/php-src
Loading...
Searching...
No Matches
pageinfo.c
Go to the documentation of this file.
1
/*
2
+----------------------------------------------------------------------+
3
| Copyright (c) The PHP Group |
4
+----------------------------------------------------------------------+
5
| This source file is subject to version 3.01 of the PHP license, |
6
| that is bundled with this package in the file LICENSE, and is |
7
| available through the world-wide-web at the following url: |
8
| https://www.php.net/license/3_01.txt |
9
| If you did not receive a copy of the PHP license and are unable to |
10
| obtain it through the world-wide-web, please send a note to |
11
| license@php.net so we can mail you a copy immediately. |
12
+----------------------------------------------------------------------+
13
| Author: Jim Winstead <jimw@php.net> |
14
+----------------------------------------------------------------------+
15
*/
16
17
#include "
php.h
"
18
#include "
pageinfo.h
"
19
#include "
SAPI.h
"
20
21
#include <stdio.h>
22
#include <stdlib.h>
23
#ifdef HAVE_PWD_H
24
#ifdef PHP_WIN32
25
#include "win32/pwd.h"
26
#else
27
#include <pwd.h>
28
#endif
29
#endif
30
#ifdef HAVE_GRP_H
31
# include <grp.h>
32
#endif
33
#ifdef PHP_WIN32
34
#undef getgid
35
#define getgroups(a, b) 0
36
#define getgid() 1
37
#define getuid() 1
38
#endif
39
#ifdef HAVE_UNISTD_H
40
#include <
unistd.h
>
41
#endif
42
#include <sys/stat.h>
43
#include <sys/types.h>
44
#ifdef PHP_WIN32
45
#include <process.h>
46
#endif
47
48
#include "
ext/standard/basic_functions.h
"
49
50
/* {{{ php_statpage */
51
PHPAPI
void
php_statpage
(
void
)
52
{
53
zend_stat_t
*pstat =
NULL
;
54
55
pstat =
sapi_get_stat
();
56
57
if
(
BG
(page_uid)==-1 ||
BG
(page_gid)==-1) {
58
if
(pstat) {
59
BG
(page_uid) = pstat->st_uid;
60
BG
(page_gid) = pstat->st_gid;
61
BG
(page_inode) = pstat->st_ino;
62
BG
(page_mtime) = pstat->st_mtime;
63
}
else
{
/* handler for situations where there is no source file, ex. php -r */
64
BG
(page_uid) = getuid();
65
BG
(page_gid) = getgid();
66
}
67
}
68
}
69
/* }}} */
70
71
/* {{{ php_getuid */
72
zend_long
php_getuid
(
void
)
73
{
74
php_statpage
();
75
return
(
BG
(page_uid));
76
}
77
/* }}} */
78
79
zend_long
php_getgid
(
void
)
80
{
81
php_statpage
();
82
return
(
BG
(page_gid));
83
}
84
85
/* {{{ Get PHP script owner's UID */
86
PHP_FUNCTION
(
getmyuid
)
87
{
88
zend_long
uid;
89
90
ZEND_PARSE_PARAMETERS_NONE
();
91
92
uid =
php_getuid
();
93
if
(uid < 0) {
94
RETURN_FALSE
;
95
}
else
{
96
RETURN_LONG
(uid);
97
}
98
}
99
/* }}} */
100
101
/* {{{ Get PHP script owner's GID */
102
PHP_FUNCTION
(
getmygid
)
103
{
104
zend_long
gid;
105
106
ZEND_PARSE_PARAMETERS_NONE
();
107
108
gid =
php_getgid
();
109
if
(gid < 0) {
110
RETURN_FALSE
;
111
}
else
{
112
RETURN_LONG
(gid);
113
}
114
}
115
/* }}} */
116
117
/* {{{ Get current process ID */
118
PHP_FUNCTION
(
getmypid
)
119
{
120
zend_long
pid;
121
122
ZEND_PARSE_PARAMETERS_NONE
();
123
124
pid = getpid();
125
if
(pid < 0) {
126
RETURN_FALSE
;
127
}
else
{
128
RETURN_LONG
(pid);
129
}
130
}
131
/* }}} */
132
133
/* {{{ Get the inode of the current script being parsed */
134
PHP_FUNCTION
(
getmyinode
)
135
{
136
ZEND_PARSE_PARAMETERS_NONE
();
137
138
php_statpage
();
139
if
(
BG
(page_inode) < 0) {
140
RETURN_FALSE
;
141
}
else
{
142
RETURN_LONG
(
BG
(page_inode));
143
}
144
}
145
/* }}} */
146
147
PHPAPI
time_t
php_getlastmod
(
void
)
148
{
149
php_statpage
();
150
return
BG
(page_mtime);
151
}
152
153
/* {{{ Get time of last page modification */
154
PHP_FUNCTION
(
getlastmod
)
155
{
156
zend_long
lm;
157
158
ZEND_PARSE_PARAMETERS_NONE
();
159
160
lm =
php_getlastmod
();
161
if
(lm < 0) {
162
RETURN_FALSE
;
163
}
else
{
164
RETURN_LONG
(lm);
165
}
166
}
167
/* }}} */
sapi_get_stat
SAPI_API zend_stat_t * sapi_get_stat(void)
Definition
SAPI.c:1011
SAPI.h
basic_functions.h
BG
#define BG(v)
Definition
basic_functions.h:116
getlastmod
getlastmod()
Definition
basic_functions.stub.php:2206
getmyinode
getmyinode()
Definition
basic_functions.stub.php:2204
getmyuid
getmyuid()
Definition
basic_functions.stub.php:2198
getmygid
getmygid()
Definition
basic_functions.stub.php:2200
getmypid
getmypid()
Definition
basic_functions.stub.php:2202
NULL
#define NULL
Definition
gdcache.h:45
php_getgid
zend_long php_getgid(void)
Definition
pageinfo.c:79
php_getlastmod
PHPAPI time_t php_getlastmod(void)
Definition
pageinfo.c:147
php_getuid
zend_long php_getuid(void)
Definition
pageinfo.c:72
php_statpage
PHPAPI void php_statpage(void)
Definition
pageinfo.c:51
pageinfo.h
php.h
PHP_FUNCTION
#define PHP_FUNCTION
Definition
php.h:364
PHPAPI
#define PHPAPI
Definition
php.h:71
unistd.h
RETURN_FALSE
#define RETURN_FALSE
Definition
zend_API.h:1058
ZEND_PARSE_PARAMETERS_NONE
#define ZEND_PARSE_PARAMETERS_NONE()
Definition
zend_API.h:1623
RETURN_LONG
#define RETURN_LONG(l)
Definition
zend_API.h:1037
zend_long
int32_t zend_long
Definition
zend_long.h:42
zend_stat_t
struct stat zend_stat_t
Definition
zend_stream.h:94
ext
standard
pageinfo.c
Generated on Sat Aug 23 2025 01:46:12 for php-internal-docs by
1.13.2