Coverage Report

Created: 2026-06-02 06:39

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