ftok.c 1.8 KB

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