fopen_variation19.phpt 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. --TEST--
  2. Test fopen() function : variation: test opening linked files
  3. --CREDITS--
  4. Dave Kelsey <d_kelsey@uk.ibm.com>
  5. --SKIPIF--
  6. <?php
  7. if(substr(PHP_OS, 0, 3) == "WIN")
  8. die("skip Not for Windows");
  9. ?>
  10. --FILE--
  11. <?php
  12. /* Prototype : resource fopen(string filename, string mode [, bool use_include_path [, resource context]])
  13. * Description: Open a file or a URL and return a file pointer
  14. * Source code: ext/standard/file.c
  15. * Alias to functions:
  16. */
  17. $tmpDir = 'fopenVar19.Dir';
  18. $realFilename = __FILE__.'.real';
  19. $sortFilename = __FILE__.'.soft';
  20. $hardFilename = __FILE__.'.hard';
  21. $linkOfLink = __FILE__.'.soft2';
  22. echo "*** Testing fopen() : variation ***\n";
  23. // start the test
  24. mkdir($tmpDir);
  25. chdir($tmpDir);
  26. $h = fopen($realFilename, "w");
  27. fwrite($h, "Hello World");
  28. fclose($h);
  29. symlink($realFilename, $sortFilename);
  30. symlink($sortFilename, $linkOfLink);
  31. link($realFilename, $hardFilename);
  32. echo "*** testing reading of links ***\n";
  33. echo "soft link:";
  34. readFile2($sortFilename);
  35. echo "hard link:";
  36. readFile2($hardFilename);
  37. echo "link of link:";
  38. readFile2($linkOfLink);
  39. echo "*** test appending to links ***\n";
  40. echo "soft link:";
  41. appendFile($sortFilename);
  42. echo "hard link:";
  43. appendFile($hardFilename);
  44. echo "link of link:";
  45. appendFile($linkOfLink);
  46. echo "*** test overwriting links ***\n";
  47. echo "soft link:";
  48. writeFile($sortFilename);
  49. echo "hard link:";
  50. writeFile($hardFilename);
  51. echo "link of link:";
  52. writeFile($linkOfLink);
  53. unlink($linkOfLink);
  54. unlink($sortFilename);
  55. unlink($hardFilename);
  56. unlink($realFilename);
  57. chdir("..");
  58. rmdir($tmpDir);
  59. function readFile2($file) {
  60. $h = fopen($file, 'r');
  61. fpassthru($h);
  62. fclose($h);
  63. echo "\n";
  64. }
  65. function appendFile($file) {
  66. $h = fopen($file, 'a+');
  67. fwrite($h, ' again!');
  68. fseek($h, 0);
  69. fpassthru($h);
  70. fclose($h);
  71. echo "\n";
  72. }
  73. function writeFile($file) {
  74. $h = fopen($file, 'w');
  75. fwrite($h, 'Goodbye World');
  76. fclose($h);
  77. readFile2($file);
  78. }
  79. ?>
  80. ===DONE===
  81. --EXPECT--
  82. *** Testing fopen() : variation ***
  83. *** testing reading of links ***
  84. soft link:Hello World
  85. hard link:Hello World
  86. link of link:Hello World
  87. *** test appending to links ***
  88. soft link:Hello World again!
  89. hard link:Hello World again! again!
  90. link of link:Hello World again! again! again!
  91. *** test overwriting links ***
  92. soft link:Goodbye World
  93. hard link:Goodbye World
  94. link of link:Goodbye World
  95. ===DONE===