Back to index

php5  5.3.10
ftok.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: Andrew Sitnikov <sitnikov@infonet.ee>                        |
00016    +----------------------------------------------------------------------+
00017 */
00018 
00019 /* $Id: ftok.c 321634 2012-01-01 13:15:04Z felipe $ */
00020 
00021 #include "php.h"
00022 
00023 #include <sys/types.h>                                                                                                        
00024 
00025 #ifdef HAVE_SYS_IPC_H
00026 #include <sys/ipc.h>
00027 #endif
00028 
00029 #if HAVE_FTOK
00030 /* {{{ proto int ftok(string pathname, string proj)
00031    Convert a pathname and a project identifier to a System V IPC key */
00032 PHP_FUNCTION(ftok)
00033 {
00034        char *pathname, *proj;
00035        int pathname_len, proj_len;
00036        key_t k;
00037 
00038        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &pathname, &pathname_len, &proj, &proj_len) == FAILURE) {
00039               return;
00040        }
00041 
00042        if (strlen(pathname) != pathname_len) {
00043               RETURN_FALSE;
00044        }
00045 
00046        if (pathname_len == 0){
00047               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Pathname is invalid");
00048               RETURN_LONG(-1);
00049        }
00050 
00051        if (proj_len != 1){
00052               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Project identifier is invalid");
00053               RETURN_LONG(-1);
00054     }
00055 
00056        if ((PG(safe_mode) && (!php_checkuid(pathname, NULL, CHECKUID_CHECK_FILE_AND_DIR))) || php_check_open_basedir(pathname TSRMLS_CC)) {
00057               RETURN_LONG(-1);
00058        }
00059 
00060        k = ftok(pathname, proj[0]);
00061        if (k == -1) {
00062               php_error_docref(NULL TSRMLS_CC, E_WARNING, "ftok() failed - %s", strerror(errno));
00063        }
00064 
00065        RETURN_LONG(k);
00066 }
00067 /* }}} */
00068 #endif
00069 
00070 /*
00071  * Local variables:
00072  * tab-width: 4
00073  * c-basic-offset: 4
00074  * End:
00075  */