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: Andrew Sitnikov <sitnikov@infonet.ee> |
14 +----------------------------------------------------------------------+
15 */
16
17 #include "php.h"
18
19 #include <sys/types.h>
20
21 #ifdef HAVE_SYS_IPC_H
22 #include <sys/ipc.h>
23 #endif
24
25 #ifdef PHP_WIN32
26 #include "win32/ipc.h"
27 #endif
28
29 #ifdef HAVE_FTOK
30 /* {{{ Convert a pathname and a project identifier to a System V IPC key */
PHP_FUNCTION(ftok)31 PHP_FUNCTION(ftok)
32 {
33 char *pathname, *proj;
34 size_t pathname_len, proj_len;
35 key_t k;
36
37 ZEND_PARSE_PARAMETERS_START(2, 2)
38 Z_PARAM_PATH(pathname, pathname_len)
39 Z_PARAM_STRING(proj, proj_len)
40 ZEND_PARSE_PARAMETERS_END();
41
42 if (pathname_len == 0){
43 zend_argument_value_error(1, "cannot be empty");
44 RETURN_THROWS();
45 }
46
47 if (proj_len != 1){
48 zend_argument_value_error(2, "must be a single character");
49 RETURN_THROWS();
50 }
51
52 if (php_check_open_basedir(pathname)) {
53 RETURN_LONG(-1);
54 }
55
56 k = ftok(pathname, proj[0]);
57 if (k == -1) {
58 php_error_docref(NULL, E_WARNING, "ftok() failed - %s", strerror(errno));
59 }
60
61 RETURN_LONG(k);
62 }
63 /* }}} */
64 #endif
65