Skip to content

Commit 39f3075

Browse files
committed
Check in ftok() function by Andrew Sitnikov <sitnikov@infonet.ee>
1 parent 15f0f8a commit 39f3075

File tree

5 files changed

+105
-1
lines changed

5 files changed

+105
-1
lines changed

ext/standard/Makefile.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ LTLIBRARY_SOURCES=\
99
syslog.c type.c uniqid.c url.c url_scanner.c var.c versioning.c assert.c \
1010
strnatcmp.c levenshtein.c incomplete_class.c url_scanner_ex.c \
1111
ftp_fopen_wrapper.c http_fopen_wrapper.c php_fopen_wrapper.c credits.c \
12-
var_unserializer.c
12+
var_unserializer.c ftok.c
1313

1414
include $(top_srcdir)/build/dynlib.mk
1515

ext/standard/basic_functions.c

+7
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,13 @@ function_entry basic_functions[] = {
792792
/* functions from versioning.c */
793793
PHP_FE(version_compare, NULL)
794794

795+
/* functions from ftok.c*/
796+
#if HAVE_SYSVSEM || HAVE_SYSVSHM || HAVE_SHMOP
797+
PHP_FE(ftok, NULL)
798+
#else
799+
PHP_FALIAS(ftok , warn_not_available, NULL)
800+
#endif
801+
795802
{NULL, NULL, NULL}
796803
};
797804

ext/standard/ftok.c

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
+----------------------------------------------------------------------+
3+
| PHP version 4.0 |
4+
+----------------------------------------------------------------------+
5+
| Copyright (c) 1997-2001 The PHP Group |
6+
+----------------------------------------------------------------------+
7+
| This source file is subject to version 2.02 of the PHP license, |
8+
| that is bundled with this package in the file LICENSE, and is |
9+
| available at through the world-wide-web at |
10+
| http://www.php.net/license/2_02.txt. |
11+
| If you did not receive a copy of the PHP license and are unable to |
12+
| obtain it through the world-wide-web, please send a note to |
13+
| license@php.net so we can mail you a copy immediately. |
14+
+----------------------------------------------------------------------+
15+
| Authors: Andrew Sitnikov <sitnikov@infonet.ee |
16+
+----------------------------------------------------------------------+
17+
*/
18+
19+
/* $Id$ */
20+
21+
#include "php.h"
22+
23+
#if HAVE_SYSVSEM || HAVE_SYSVSHM || HAVE_SHMOP
24+
25+
#include <sys/types.h>
26+
#include <sys/ipc.h>
27+
28+
/* {{{ proto int ftok(string pathname, char proj)
29+
convert a pathname and a project identifier to a System V IPC key */
30+
PHP_FUNCTION(ftok)
31+
{
32+
pval **pathname, **proj;
33+
34+
key_t k;
35+
36+
if(ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &pathname, &proj) == FAILURE) {
37+
WRONG_PARAM_COUNT;
38+
}
39+
40+
convert_to_string_ex(pathname);
41+
convert_to_string_ex(proj);
42+
43+
if (Z_STRLEN_PP(pathname)==0){
44+
php_error(E_WARNING, "Invalid argument 1 in ftok");
45+
RETURN_LONG(-1);
46+
}
47+
48+
if (Z_STRLEN_PP(proj)!=1){
49+
php_error(E_WARNING, "Invalid argument 2 in ftok");
50+
RETURN_LONG(-1);
51+
}
52+
53+
k = ftok(Z_STRVAL_PP(pathname),Z_STRVAL_PP(proj)[0]);
54+
55+
RETURN_LONG(k);
56+
}
57+
/* }}} */
58+
59+
#endif
60+
61+
/*
62+
* Local variables:
63+
* tab-width: 4
64+
* c-basic-offset: 4
65+
* End:
66+
*/

ext/standard/php_ftok.h

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
+----------------------------------------------------------------------+
3+
| PHP version 4.0 |
4+
+----------------------------------------------------------------------+
5+
| Copyright (c) 1997-2001 The PHP Group |
6+
+----------------------------------------------------------------------+
7+
| This source file is subject to version 2.02 of the PHP license, |
8+
| that is bundled with this package in the file LICENSE, and is |
9+
| available at through the world-wide-web at |
10+
| http://www.php.net/license/2_02.txt. |
11+
| If you did not receive a copy of the PHP license and are unable to |
12+
| obtain it through the world-wide-web, please send a note to |
13+
| license@php.net so we can mail you a copy immediately. |
14+
+----------------------------------------------------------------------+
15+
| Authors: Andrew Sitnikov <sitnikov@infonet.ee> |
16+
+----------------------------------------------------------------------+
17+
*/
18+
19+
/* $Id$ */
20+
21+
#ifndef PHP_FTOK_H
22+
#define PHP_FTOK_H
23+
24+
#if HAVE_SYSVSEM || HAVE_SYSVSHM || HAVE_SHMOP
25+
26+
PHP_FUNCTION(ftok);
27+
28+
#endif
29+
30+
#endif /* PHP_FTOK_H */

ext/standard/php_standard.h

+1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
#include "php_array.h"
5858
#include "php_assert.h"
5959
#include "php_versioning.h"
60+
#include "php_ftok.h"
6061

6162
#define phpext_standard_ptr basic_functions_module_ptr
6263

0 commit comments

Comments
 (0)