ftok.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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: Anatol Belski <ab@php.net> |
  14. +----------------------------------------------------------------------+
  15. */
  16. #include "php.h"
  17. #include "ipc.h"
  18. #include <windows.h>
  19. #include <sys/stat.h>
  20. #include "ioutil.h"
  21. PHP_WIN32_IPC_API key_t
  22. ftok(const char *pathname, int proj_id)
  23. {/*{{{*/
  24. HANDLE fh;
  25. struct _stat st;
  26. BY_HANDLE_FILE_INFORMATION bhfi;
  27. key_t ret;
  28. PHP_WIN32_IOUTIL_INIT_W(pathname)
  29. if (!pathw) {
  30. return (key_t)-1;
  31. }
  32. if (_wstat(pathw, &st) < 0) {
  33. PHP_WIN32_IOUTIL_CLEANUP_W()
  34. return (key_t)-1;
  35. }
  36. if ((fh = CreateFileW(pathw, FILE_GENERIC_READ, PHP_WIN32_IOUTIL_DEFAULT_SHARE_MODE, 0, OPEN_EXISTING, 0, 0)) == INVALID_HANDLE_VALUE) {
  37. PHP_WIN32_IOUTIL_CLEANUP_W()
  38. return (key_t)-1;
  39. }
  40. if (!GetFileInformationByHandle(fh, &bhfi)) {
  41. PHP_WIN32_IOUTIL_CLEANUP_W()
  42. CloseHandle(fh);
  43. return (key_t)-1;
  44. }
  45. ret = (key_t) ((proj_id & 0xff) << 24 | (st.st_dev & 0xff) << 16 | ((bhfi.nFileIndexLow | (__int64)bhfi.nFileIndexHigh << 32) & 0xffff));
  46. CloseHandle(fh);
  47. PHP_WIN32_IOUTIL_CLEANUP_W()
  48. return ret;
  49. }/*}}}*/