/src/php-src/ext/standard/ftok.c
Line | Count | Source (jump to first uncovered line) |
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 */ |
31 | | PHP_FUNCTION(ftok) |
32 | 0 | { |
33 | 0 | char *pathname, *proj; |
34 | 0 | size_t pathname_len, proj_len; |
35 | 0 | key_t k; |
36 | |
|
37 | 0 | ZEND_PARSE_PARAMETERS_START(2, 2) |
38 | 0 | Z_PARAM_PATH(pathname, pathname_len) |
39 | 0 | Z_PARAM_STRING(proj, proj_len) |
40 | 0 | ZEND_PARSE_PARAMETERS_END(); |
41 | | |
42 | 0 | if (pathname_len == 0){ |
43 | 0 | zend_argument_must_not_be_empty_error(1); |
44 | 0 | RETURN_THROWS(); |
45 | 0 | } |
46 | | |
47 | 0 | if (proj_len != 1){ |
48 | 0 | zend_argument_value_error(2, "must be a single character"); |
49 | 0 | RETURN_THROWS(); |
50 | 0 | } |
51 | | |
52 | 0 | if (php_check_open_basedir(pathname)) { |
53 | 0 | RETURN_LONG(-1); |
54 | 0 | } |
55 | | |
56 | 0 | k = ftok(pathname, proj[0]); |
57 | 0 | if (k == -1) { |
58 | 0 | php_error_docref(NULL, E_WARNING, "ftok() failed - %s", strerror(errno)); |
59 | 0 | } |
60 | |
|
61 | 0 | RETURN_LONG(k); |
62 | 0 | } |
63 | | /* }}} */ |
64 | | #endif |