Coverage Report

Created: 2026-07-25 06:39

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/php-src/ext/standard/pageinfo.c
Line
Count
Source
1
/*
2
   +----------------------------------------------------------------------+
3
   | Copyright © The PHP Group and Contributors.                          |
4
   +----------------------------------------------------------------------+
5
   | This source file is subject to the Modified BSD License that is      |
6
   | bundled with this package in the file LICENSE, and is available      |
7
   | through the World Wide Web at <https://www.php.net/license/>.        |
8
   |                                                                      |
9
   | SPDX-License-Identifier: BSD-3-Clause                                |
10
   +----------------------------------------------------------------------+
11
   | Author: Jim Winstead <jimw@php.net>                                  |
12
   +----------------------------------------------------------------------+
13
*/
14
15
#include "php.h"
16
#include "pageinfo.h"
17
#include "SAPI.h"
18
19
#include <stdio.h>
20
#include <stdlib.h>
21
#ifdef HAVE_PWD_H
22
# include <pwd.h>
23
#endif
24
#ifdef HAVE_GRP_H
25
# include <grp.h>
26
#endif
27
#ifdef PHP_WIN32
28
#undef getgid
29
#define getgroups(a, b) 0
30
#define getgid() 1
31
#define getuid() 1
32
#endif
33
#ifdef HAVE_UNISTD_H
34
#include <unistd.h>
35
#endif
36
#include <sys/stat.h>
37
#include <sys/types.h>
38
#ifdef PHP_WIN32
39
#include <process.h>
40
#endif
41
42
#include "ext/standard/basic_functions.h"
43
44
/* {{{ php_statpage */
45
PHPAPI void php_statpage(void)
46
0
{
47
0
  zend_stat_t *pstat = NULL;
48
49
0
  pstat = sapi_get_stat();
50
51
0
  if (BG(page_uid)==-1 || BG(page_gid)==-1) {
52
0
    if(pstat) {
53
0
      BG(page_uid)   = pstat->st_uid;
54
0
      BG(page_gid)   = pstat->st_gid;
55
0
      BG(page_inode) = pstat->st_ino;
56
0
      BG(page_mtime) = pstat->st_mtime;
57
0
    } else { /* handler for situations where there is no source file, ex. php -r */
58
0
      BG(page_uid) = getuid();
59
0
      BG(page_gid) = getgid();
60
0
    }
61
0
  }
62
0
}
63
/* }}} */
64
65
/* {{{ php_getuid */
66
zend_long php_getuid(void)
67
0
{
68
0
  php_statpage();
69
0
  return (BG(page_uid));
70
0
}
71
/* }}} */
72
73
zend_long php_getgid(void)
74
0
{
75
0
  php_statpage();
76
0
  return (BG(page_gid));
77
0
}
78
79
/* {{{ Get PHP script owner's UID */
80
PHP_FUNCTION(getmyuid)
81
0
{
82
0
  zend_long uid;
83
84
0
  ZEND_PARSE_PARAMETERS_NONE();
85
86
0
  uid = php_getuid();
87
0
  if (uid < 0) {
88
0
    RETURN_FALSE;
89
0
  } else {
90
0
    RETURN_LONG(uid);
91
0
  }
92
0
}
93
/* }}} */
94
95
/* {{{ Get PHP script owner's GID */
96
PHP_FUNCTION(getmygid)
97
0
{
98
0
  zend_long gid;
99
100
0
  ZEND_PARSE_PARAMETERS_NONE();
101
102
0
  gid = php_getgid();
103
0
  if (gid < 0) {
104
0
    RETURN_FALSE;
105
0
  } else {
106
0
    RETURN_LONG(gid);
107
0
  }
108
0
}
109
/* }}} */
110
111
/* {{{ Get current process ID */
112
PHP_FUNCTION(getmypid)
113
0
{
114
0
  zend_long pid;
115
116
0
  ZEND_PARSE_PARAMETERS_NONE();
117
118
0
  pid = getpid();
119
0
  if (pid < 0) {
120
0
    RETURN_FALSE;
121
0
  } else {
122
0
    RETURN_LONG(pid);
123
0
  }
124
0
}
125
/* }}} */
126
127
/* {{{ Get the inode of the current script being parsed */
128
PHP_FUNCTION(getmyinode)
129
0
{
130
0
  ZEND_PARSE_PARAMETERS_NONE();
131
132
0
  php_statpage();
133
0
  if (BG(page_inode) < 0) {
134
0
    RETURN_FALSE;
135
0
  } else {
136
0
    RETURN_LONG(BG(page_inode));
137
0
  }
138
0
}
139
/* }}} */
140
141
PHPAPI time_t php_getlastmod(void)
142
0
{
143
0
  php_statpage();
144
0
  return BG(page_mtime);
145
0
}
146
147
/* {{{ Get time of last page modification */
148
PHP_FUNCTION(getlastmod)
149
0
{
150
0
  zend_long lm;
151
152
0
  ZEND_PARSE_PARAMETERS_NONE();
153
154
0
  lm = php_getlastmod();
155
0
  if (lm < 0) {
156
0
    RETURN_FALSE;
157
0
  } else {
158
0
    RETURN_LONG(lm);
159
0
  }
160
0
}
161
/* }}} */