ftok.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. +----------------------------------------------------------------------+
  3. | PHP Version 7 |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 1997-2018 The PHP Group |
  6. +----------------------------------------------------------------------+
  7. | This source file is subject to version 3.01 of the PHP license, |
  8. | that is bundled with this package in the file LICENSE, and is |
  9. | available through the world-wide-web at the following url: |
  10. | http://www.php.net/license/3_01.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. | Author: Anatol Belski <ab@php.net> |
  16. +----------------------------------------------------------------------+
  17. */
  18. #include "ipc.h"
  19. #include <windows.h>
  20. #include <sys/stat.h>
  21. #include "ioutil.h"
  22. PHP_WIN32_IPC_API key_t
  23. ftok(const char *pathname, int proj_id)
  24. {/*{{{*/
  25. HANDLE fh;
  26. struct _stat st;
  27. BY_HANDLE_FILE_INFORMATION bhfi;
  28. key_t ret;
  29. PHP_WIN32_IOUTIL_INIT_W(pathname)
  30. if (!pathw) {
  31. return (key_t)-1;
  32. }
  33. if (_wstat(pathw, &st) < 0) {
  34. PHP_WIN32_IOUTIL_CLEANUP_W()
  35. return (key_t)-1;
  36. }
  37. if ((fh = CreateFileW(pathw, FILE_GENERIC_READ, PHP_WIN32_IOUTIL_DEFAULT_SHARE_MODE, 0, OPEN_EXISTING, 0, 0)) == INVALID_HANDLE_VALUE) {
  38. PHP_WIN32_IOUTIL_CLEANUP_W()
  39. return (key_t)-1;
  40. }
  41. if (!GetFileInformationByHandle(fh, &bhfi)) {
  42. PHP_WIN32_IOUTIL_CLEANUP_W()
  43. CloseHandle(fh);
  44. return (key_t)-1;
  45. }
  46. ret = (key_t) ((proj_id & 0xff) << 24 | (st.st_dev & 0xff) << 16 | ((bhfi.nFileIndexLow | (__int64)bhfi.nFileIndexHigh << 32) & 0xffff));
  47. CloseHandle(fh);
  48. PHP_WIN32_IOUTIL_CLEANUP_W()
  49. return ret;
  50. }/*}}}*/
  51. /*
  52. * Local variables:
  53. * tab-width: 4
  54. * c-basic-offset: 4
  55. * End:
  56. * vim600: sw=4 ts=4 fdm=marker
  57. * vim<600: sw=4 ts=4
  58. */