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
49
50/* {{{ php_statpage */
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 */
73{
75 return (BG(page_uid));
76}
77/* }}} */
78
80{
82 return (BG(page_gid));
83}
84
85/* {{{ Get PHP script owner's UID */
87{
88 zend_long uid;
89
91
92 uid = php_getuid();
93 if (uid < 0) {
95 } else {
96 RETURN_LONG(uid);
97 }
98}
99/* }}} */
100
101/* {{{ Get PHP script owner's GID */
103{
104 zend_long gid;
105
107
108 gid = php_getgid();
109 if (gid < 0) {
111 } else {
112 RETURN_LONG(gid);
113 }
114}
115/* }}} */
116
117/* {{{ Get current process ID */
119{
120 zend_long pid;
121
123
124 pid = getpid();
125 if (pid < 0) {
127 } else {
128 RETURN_LONG(pid);
129 }
130}
131/* }}} */
132
133/* {{{ Get the inode of the current script being parsed */
135{
137
138 php_statpage();
139 if (BG(page_inode) < 0) {
141 } else {
142 RETURN_LONG(BG(page_inode));
143 }
144}
145/* }}} */
146
148{
149 php_statpage();
150 return BG(page_mtime);
151}
152
153/* {{{ Get time of last page modification */
155{
156 zend_long lm;
157
159
160 lm = php_getlastmod();
161 if (lm < 0) {
163 } else {
164 RETURN_LONG(lm);
165 }
166}
167/* }}} */
SAPI_API zend_stat_t * sapi_get_stat(void)
Definition SAPI.c:1011
#define BG(v)
#define NULL
Definition gdcache.h:45
zend_long php_getgid(void)
Definition pageinfo.c:79
PHPAPI time_t php_getlastmod(void)
Definition pageinfo.c:147
zend_long php_getuid(void)
Definition pageinfo.c:72
PHPAPI void php_statpage(void)
Definition pageinfo.c:51
#define PHP_FUNCTION
Definition php.h:364
#define PHPAPI
Definition php.h:71
#define RETURN_FALSE
Definition zend_API.h:1058
#define ZEND_PARSE_PARAMETERS_NONE()
Definition zend_API.h:1623
#define RETURN_LONG(l)
Definition zend_API.h:1037
int32_t zend_long
Definition zend_long.h:42
struct stat zend_stat_t
Definition zend_stream.h:94