Back to index

php5  5.3.10
pageinfo.c
Go to the documentation of this file.
00001 /*
00002    +----------------------------------------------------------------------+
00003    | PHP Version 5                                                        |
00004    +----------------------------------------------------------------------+
00005    | Copyright (c) 1997-2012 The PHP Group                                |
00006    +----------------------------------------------------------------------+
00007    | This source file is subject to version 3.01 of the PHP license,      |
00008    | that is bundled with this package in the file LICENSE, and is        |
00009    | available through the world-wide-web at the following url:           |
00010    | http://www.php.net/license/3_01.txt                                  |
00011    | If you did not receive a copy of the PHP license and are unable to   |
00012    | obtain it through the world-wide-web, please send a note to          |
00013    | license@php.net so we can mail you a copy immediately.               |
00014    +----------------------------------------------------------------------+
00015    | Author: Jim Winstead <jimw@php.net>                                  |
00016    +----------------------------------------------------------------------+
00017 */
00018 
00019 /* $Id: pageinfo.c 321634 2012-01-01 13:15:04Z felipe $ */
00020 
00021 #include "php.h"
00022 #include "pageinfo.h"
00023 #include "SAPI.h"
00024 
00025 #include <stdio.h>
00026 #include <stdlib.h>
00027 #if HAVE_PWD_H
00028 #ifdef PHP_WIN32
00029 #include "win32/pwd.h"
00030 #else
00031 #include <pwd.h>
00032 #endif
00033 #endif
00034 #if HAVE_GRP_H
00035 # ifdef PHP_WIN32
00036 #  include "win32/grp.h"
00037 # else
00038 #  include <grp.h>
00039 # endif
00040 #endif
00041 #ifdef PHP_WIN32
00042 #undef getgid
00043 #define getgroups(a, b) 0
00044 #define getgid() 1
00045 #define getuid() 1
00046 #endif
00047 #if HAVE_UNISTD_H
00048 #include <unistd.h>
00049 #endif
00050 #include <sys/stat.h>
00051 #include <sys/types.h>
00052 #ifdef PHP_WIN32
00053 #include <process.h>
00054 #endif
00055 
00056 #include "ext/standard/basic_functions.h"
00057 
00058 /* {{{ php_statpage
00059  */
00060 PHPAPI void php_statpage(TSRMLS_D)
00061 {
00062        struct stat *pstat;
00063 
00064        pstat = sapi_get_stat(TSRMLS_C);
00065 
00066        if (BG(page_uid)==-1 || BG(page_gid)==-1) {
00067               if(pstat) {
00068                      BG(page_uid)   = pstat->st_uid;
00069                      BG(page_gid)   = pstat->st_gid;
00070                      BG(page_inode) = pstat->st_ino;
00071                      BG(page_mtime) = pstat->st_mtime;
00072               } else { /* handler for situations where there is no source file, ex. php -r */
00073                      BG(page_uid) = getuid();
00074                      BG(page_gid) = getgid();
00075               }
00076        }
00077 }
00078 /* }}} */
00079 
00080 /* {{{ php_getuid
00081  */
00082 long php_getuid(void)
00083 {
00084        TSRMLS_FETCH();
00085 
00086        php_statpage(TSRMLS_C);
00087        return (BG(page_uid));
00088 }
00089 /* }}} */
00090 
00091 long php_getgid(void)
00092 {
00093        TSRMLS_FETCH();
00094 
00095        php_statpage(TSRMLS_C);
00096        return (BG(page_gid));
00097 }
00098 
00099 /* {{{ proto int getmyuid(void)
00100    Get PHP script owner's UID */
00101 PHP_FUNCTION(getmyuid)
00102 {
00103        long uid;
00104        
00105        uid = php_getuid();
00106        if (uid < 0) {
00107               RETURN_FALSE;
00108        } else {
00109               RETURN_LONG(uid);
00110        }
00111 }
00112 /* }}} */
00113 
00114 /* {{{ proto int getmygid(void)
00115    Get PHP script owner's GID */
00116 PHP_FUNCTION(getmygid)
00117 {
00118        long gid;
00119        
00120        gid = php_getgid();
00121        if (gid < 0) {
00122               RETURN_FALSE;
00123        } else {
00124               RETURN_LONG(gid);
00125        }
00126 }
00127 /* }}} */
00128 
00129 /* {{{ proto int getmypid(void)
00130    Get current process ID */
00131 PHP_FUNCTION(getmypid)
00132 {
00133        int pid;
00134        
00135        pid = getpid();
00136        if (pid < 0) {
00137               RETURN_FALSE;
00138        } else {
00139               RETURN_LONG((long) pid);
00140        }
00141 }
00142 /* }}} */
00143 
00144 /* {{{ proto int getmyinode(void)
00145    Get the inode of the current script being parsed */
00146 PHP_FUNCTION(getmyinode)
00147 {
00148        php_statpage(TSRMLS_C);
00149        if (BG(page_inode) < 0) {
00150               RETURN_FALSE;
00151        } else {
00152               RETURN_LONG(BG(page_inode));
00153        }
00154 }
00155 /* }}} */
00156 
00157 PHPAPI long php_getlastmod(TSRMLS_D)
00158 {
00159        php_statpage(TSRMLS_C);
00160        return BG(page_mtime);
00161 }
00162 
00163 /* {{{ proto int getlastmod(void)
00164    Get time of last page modification */
00165 PHP_FUNCTION(getlastmod)
00166 {
00167        long lm = php_getlastmod(TSRMLS_C);
00168        if (lm < 0) {
00169               RETURN_FALSE;
00170        } else {
00171               RETURN_LONG(lm);
00172        }
00173 }
00174 /* }}} */
00175 
00176 /*
00177  * Local variables:
00178  * tab-width: 4
00179  * c-basic-offset: 4
00180  * End:
00181  * vim600: sw=4 ts=4 fdm=marker
00182  * vim<600: sw=4 ts=4
00183  */