123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458 |
- --TEST--
- Test ftruncate() function : usage variations - truncate when file pointer at EOF
- --SKIPIF--
- <?php
- if (substr(PHP_OS, 0, 3) != 'WIN') {
- die('skip.. only valid for Windows');
- }
- ?>
- --FILE--
- <?php
- /* truncate the file when file pointer is positioned at end of the file */
- // include common file related test functions
- include ("file.inc");
- echo "*** Testing ftruncate() : usage variations ***\n";
- /* test ftruncate with file opened in different modes */
- $file_modes = array("r", "rb", "rt", "r+", "r+b", "r+t",
- "w", "wb", "wt", "w+", "w+b", "w+t",
- "x", "xb", "xt", "x+", "x+b", "x+t",
- "a", "ab", "at", "a+", "a+b", "a+t");
- $file_content_types = array("numeric","text_with_new_line");
- foreach($file_content_types as $file_content_type) {
- echo "\n-- Testing ftruncate() with file having data of type ". $file_content_type ." --\n";
- for($mode_counter = 0; $mode_counter < count($file_modes); $mode_counter++) {
- echo "-- Testing ftruncate() with file opening using $file_modes[$mode_counter] mode --\n";
- // create 1 file with some contents
- $filename = __DIR__."/ftruncate_variation7.tmp";
- if( strstr($file_modes[$mode_counter], "x") || strstr($file_modes[$mode_counter], "w") ) {
- // fopen the file using the $file_modes
- $file_handle = fopen($filename, $file_modes[$mode_counter]);
- fill_file($file_handle, $file_content_type, 1024);
- } else {
- create_files ( __DIR__, 1, $file_content_type, 0755, 1, "w", "ftruncate_variation", 7);
- // fopen the file using the $file_modes
- $file_handle = fopen($filename, $file_modes[$mode_counter]);
- }
- if (!$file_handle) {
- echo "Error: failed to open file $filename!\n";
- exit();
- }
- rewind($file_handle); // file pointer to 0
- echo "-- Testing ftruncate(): File pointer at the end --\n";
- /* try to truncate it to while file pointer at the end */
- fseek($file_handle, 0, SEEK_END);
- $new_size = 200;
- var_dump( filesize($filename) ); // current filesize
- var_dump( ftell($file_handle) );
- var_dump( ftruncate($file_handle, $new_size) ); // truncate it
- var_dump( ftell($file_handle) );
- var_dump( feof($file_handle) );
- fclose($file_handle);
- clearstatcache(); // clear previous size value in cache
- var_dump( filesize($filename) );
- //delete all files created
- delete_file($filename);
- }//end of inner for loop
- }//end of outer foreach loop
- echo "Done\n";
- ?>
- --EXPECT--
- *** Testing ftruncate() : usage variations ***
- -- Testing ftruncate() with file having data of type numeric --
- -- Testing ftruncate() with file opening using r mode --
- -- Testing ftruncate(): File pointer at the end --
- int(1024)
- int(1024)
- bool(false)
- int(1024)
- bool(false)
- int(1024)
- -- Testing ftruncate() with file opening using rb mode --
- -- Testing ftruncate(): File pointer at the end --
- int(1024)
- int(1024)
- bool(false)
- int(1024)
- bool(false)
- int(1024)
- -- Testing ftruncate() with file opening using rt mode --
- -- Testing ftruncate(): File pointer at the end --
- int(1024)
- int(1024)
- bool(false)
- int(1024)
- bool(false)
- int(1024)
- -- Testing ftruncate() with file opening using r+ mode --
- -- Testing ftruncate(): File pointer at the end --
- int(1024)
- int(1024)
- bool(true)
- int(1024)
- bool(false)
- int(200)
- -- Testing ftruncate() with file opening using r+b mode --
- -- Testing ftruncate(): File pointer at the end --
- int(1024)
- int(1024)
- bool(true)
- int(1024)
- bool(false)
- int(200)
- -- Testing ftruncate() with file opening using r+t mode --
- -- Testing ftruncate(): File pointer at the end --
- int(1024)
- int(1024)
- bool(true)
- int(1024)
- bool(false)
- int(200)
- -- Testing ftruncate() with file opening using w mode --
- -- Testing ftruncate(): File pointer at the end --
- int(1024)
- int(1024)
- bool(true)
- int(1024)
- bool(false)
- int(200)
- -- Testing ftruncate() with file opening using wb mode --
- -- Testing ftruncate(): File pointer at the end --
- int(1024)
- int(1024)
- bool(true)
- int(1024)
- bool(false)
- int(200)
- -- Testing ftruncate() with file opening using wt mode --
- -- Testing ftruncate(): File pointer at the end --
- int(1024)
- int(1024)
- bool(true)
- int(1024)
- bool(false)
- int(200)
- -- Testing ftruncate() with file opening using w+ mode --
- -- Testing ftruncate(): File pointer at the end --
- int(1024)
- int(1024)
- bool(true)
- int(1024)
- bool(false)
- int(200)
- -- Testing ftruncate() with file opening using w+b mode --
- -- Testing ftruncate(): File pointer at the end --
- int(1024)
- int(1024)
- bool(true)
- int(1024)
- bool(false)
- int(200)
- -- Testing ftruncate() with file opening using w+t mode --
- -- Testing ftruncate(): File pointer at the end --
- int(1024)
- int(1024)
- bool(true)
- int(1024)
- bool(false)
- int(200)
- -- Testing ftruncate() with file opening using x mode --
- -- Testing ftruncate(): File pointer at the end --
- int(1024)
- int(1024)
- bool(true)
- int(1024)
- bool(false)
- int(200)
- -- Testing ftruncate() with file opening using xb mode --
- -- Testing ftruncate(): File pointer at the end --
- int(1024)
- int(1024)
- bool(true)
- int(1024)
- bool(false)
- int(200)
- -- Testing ftruncate() with file opening using xt mode --
- -- Testing ftruncate(): File pointer at the end --
- int(1024)
- int(1024)
- bool(true)
- int(1024)
- bool(false)
- int(200)
- -- Testing ftruncate() with file opening using x+ mode --
- -- Testing ftruncate(): File pointer at the end --
- int(1024)
- int(1024)
- bool(true)
- int(1024)
- bool(false)
- int(200)
- -- Testing ftruncate() with file opening using x+b mode --
- -- Testing ftruncate(): File pointer at the end --
- int(1024)
- int(1024)
- bool(true)
- int(1024)
- bool(false)
- int(200)
- -- Testing ftruncate() with file opening using x+t mode --
- -- Testing ftruncate(): File pointer at the end --
- int(1024)
- int(1024)
- bool(true)
- int(1024)
- bool(false)
- int(200)
- -- Testing ftruncate() with file opening using a mode --
- -- Testing ftruncate(): File pointer at the end --
- int(1024)
- int(1024)
- bool(true)
- int(1024)
- bool(false)
- int(200)
- -- Testing ftruncate() with file opening using ab mode --
- -- Testing ftruncate(): File pointer at the end --
- int(1024)
- int(1024)
- bool(true)
- int(1024)
- bool(false)
- int(200)
- -- Testing ftruncate() with file opening using at mode --
- -- Testing ftruncate(): File pointer at the end --
- int(1024)
- int(1024)
- bool(true)
- int(1024)
- bool(false)
- int(200)
- -- Testing ftruncate() with file opening using a+ mode --
- -- Testing ftruncate(): File pointer at the end --
- int(1024)
- int(1024)
- bool(true)
- int(1024)
- bool(false)
- int(200)
- -- Testing ftruncate() with file opening using a+b mode --
- -- Testing ftruncate(): File pointer at the end --
- int(1024)
- int(1024)
- bool(true)
- int(1024)
- bool(false)
- int(200)
- -- Testing ftruncate() with file opening using a+t mode --
- -- Testing ftruncate(): File pointer at the end --
- int(1024)
- int(1024)
- bool(true)
- int(1024)
- bool(false)
- int(200)
- -- Testing ftruncate() with file having data of type text_with_new_line --
- -- Testing ftruncate() with file opening using r mode --
- -- Testing ftruncate(): File pointer at the end --
- int(1024)
- int(1024)
- bool(false)
- int(1024)
- bool(false)
- int(1024)
- -- Testing ftruncate() with file opening using rb mode --
- -- Testing ftruncate(): File pointer at the end --
- int(1024)
- int(1024)
- bool(false)
- int(1024)
- bool(false)
- int(1024)
- -- Testing ftruncate() with file opening using rt mode --
- -- Testing ftruncate(): File pointer at the end --
- int(1024)
- int(1024)
- bool(false)
- int(1024)
- bool(false)
- int(1024)
- -- Testing ftruncate() with file opening using r+ mode --
- -- Testing ftruncate(): File pointer at the end --
- int(1024)
- int(1024)
- bool(true)
- int(1024)
- bool(false)
- int(200)
- -- Testing ftruncate() with file opening using r+b mode --
- -- Testing ftruncate(): File pointer at the end --
- int(1024)
- int(1024)
- bool(true)
- int(1024)
- bool(false)
- int(200)
- -- Testing ftruncate() with file opening using r+t mode --
- -- Testing ftruncate(): File pointer at the end --
- int(1024)
- int(1024)
- bool(true)
- int(1024)
- bool(false)
- int(200)
- -- Testing ftruncate() with file opening using w mode --
- -- Testing ftruncate(): File pointer at the end --
- int(1024)
- int(1024)
- bool(true)
- int(1024)
- bool(false)
- int(200)
- -- Testing ftruncate() with file opening using wb mode --
- -- Testing ftruncate(): File pointer at the end --
- int(1024)
- int(1024)
- bool(true)
- int(1024)
- bool(false)
- int(200)
- -- Testing ftruncate() with file opening using wt mode --
- -- Testing ftruncate(): File pointer at the end --
- int(1137)
- int(1137)
- bool(true)
- int(1137)
- bool(false)
- int(200)
- -- Testing ftruncate() with file opening using w+ mode --
- -- Testing ftruncate(): File pointer at the end --
- int(1024)
- int(1024)
- bool(true)
- int(1024)
- bool(false)
- int(200)
- -- Testing ftruncate() with file opening using w+b mode --
- -- Testing ftruncate(): File pointer at the end --
- int(1024)
- int(1024)
- bool(true)
- int(1024)
- bool(false)
- int(200)
- -- Testing ftruncate() with file opening using w+t mode --
- -- Testing ftruncate(): File pointer at the end --
- int(1137)
- int(1137)
- bool(true)
- int(1137)
- bool(false)
- int(200)
- -- Testing ftruncate() with file opening using x mode --
- -- Testing ftruncate(): File pointer at the end --
- int(1024)
- int(1024)
- bool(true)
- int(1024)
- bool(false)
- int(200)
- -- Testing ftruncate() with file opening using xb mode --
- -- Testing ftruncate(): File pointer at the end --
- int(1024)
- int(1024)
- bool(true)
- int(1024)
- bool(false)
- int(200)
- -- Testing ftruncate() with file opening using xt mode --
- -- Testing ftruncate(): File pointer at the end --
- int(1137)
- int(1137)
- bool(true)
- int(1137)
- bool(false)
- int(200)
- -- Testing ftruncate() with file opening using x+ mode --
- -- Testing ftruncate(): File pointer at the end --
- int(1024)
- int(1024)
- bool(true)
- int(1024)
- bool(false)
- int(200)
- -- Testing ftruncate() with file opening using x+b mode --
- -- Testing ftruncate(): File pointer at the end --
- int(1024)
- int(1024)
- bool(true)
- int(1024)
- bool(false)
- int(200)
- -- Testing ftruncate() with file opening using x+t mode --
- -- Testing ftruncate(): File pointer at the end --
- int(1137)
- int(1137)
- bool(true)
- int(1137)
- bool(false)
- int(200)
- -- Testing ftruncate() with file opening using a mode --
- -- Testing ftruncate(): File pointer at the end --
- int(1024)
- int(1024)
- bool(true)
- int(1024)
- bool(false)
- int(200)
- -- Testing ftruncate() with file opening using ab mode --
- -- Testing ftruncate(): File pointer at the end --
- int(1024)
- int(1024)
- bool(true)
- int(1024)
- bool(false)
- int(200)
- -- Testing ftruncate() with file opening using at mode --
- -- Testing ftruncate(): File pointer at the end --
- int(1024)
- int(1024)
- bool(true)
- int(1024)
- bool(false)
- int(200)
- -- Testing ftruncate() with file opening using a+ mode --
- -- Testing ftruncate(): File pointer at the end --
- int(1024)
- int(1024)
- bool(true)
- int(1024)
- bool(false)
- int(200)
- -- Testing ftruncate() with file opening using a+b mode --
- -- Testing ftruncate(): File pointer at the end --
- int(1024)
- int(1024)
- bool(true)
- int(1024)
- bool(false)
- int(200)
- -- Testing ftruncate() with file opening using a+t mode --
- -- Testing ftruncate(): File pointer at the end --
- int(1024)
- int(1024)
- bool(true)
- int(1024)
- bool(false)
- int(200)
- Done
|