1--TEST--
2Test umask() function: usage variations - perms from 0351 to 0777
3--SKIPIF--
4<?php
5if (substr(PHP_OS, 0, 3) == 'WIN') {
6    die('skip.. only on Linux');
7}
8?>
9--FILE--
10<?php
11$file_path = __DIR__;
12
13/* Check umask() on file/dir */
14
15echo "*** Testing umask() on file and directory ***\n";
16// temp filename used
17$filename = "$file_path/umask_variation2.tmp";
18// temp dir used
19$dirname = "$file_path/umask_variation2";
20
21for($mask = 0351; $mask <= 0777; $mask++) {
22  echo "-- Setting umask to ";
23  echo sprintf('%03o', $mask);
24  echo " --\n";
25  // setting umask
26  umask($mask);
27
28  /* umasking file */
29  // creating temp file
30  $fp = fopen($filename, "w");
31  fclose($fp);
32  echo "File permission : ";
33  // check file permission
34  echo substr(sprintf('%o', fileperms($filename)), -3);
35  echo "\n";
36  // chmod file to 0777 to enable deletion
37  chmod($filename, 0777);
38  // delete temp file created here
39  unlink($filename);
40
41  /* umasking directory */
42  // create temp dir
43  mkdir($dirname);
44  echo "Directory permission : ";
45  // check $dirname permission
46  echo substr(sprintf('%o', fileperms($dirname)), -3);
47  echo "\n";
48  // chmod 0777 to enable deletion
49  chmod($dirname, 0777);
50  // delete temp dir created
51  rmdir($dirname);
52}
53
54echo "Done\n";
55?>
56--EXPECT--
57*** Testing umask() on file and directory ***
58-- Setting umask to 351 --
59File permission : 426
60Directory permission : 426
61-- Setting umask to 352 --
62File permission : 424
63Directory permission : 425
64-- Setting umask to 353 --
65File permission : 424
66Directory permission : 424
67-- Setting umask to 354 --
68File permission : 422
69Directory permission : 423
70-- Setting umask to 355 --
71File permission : 422
72Directory permission : 422
73-- Setting umask to 356 --
74File permission : 420
75Directory permission : 421
76-- Setting umask to 357 --
77File permission : 420
78Directory permission : 420
79-- Setting umask to 360 --
80File permission : 406
81Directory permission : 417
82-- Setting umask to 361 --
83File permission : 406
84Directory permission : 416
85-- Setting umask to 362 --
86File permission : 404
87Directory permission : 415
88-- Setting umask to 363 --
89File permission : 404
90Directory permission : 414
91-- Setting umask to 364 --
92File permission : 402
93Directory permission : 413
94-- Setting umask to 365 --
95File permission : 402
96Directory permission : 412
97-- Setting umask to 366 --
98File permission : 400
99Directory permission : 411
100-- Setting umask to 367 --
101File permission : 400
102Directory permission : 410
103-- Setting umask to 370 --
104File permission : 406
105Directory permission : 407
106-- Setting umask to 371 --
107File permission : 406
108Directory permission : 406
109-- Setting umask to 372 --
110File permission : 404
111Directory permission : 405
112-- Setting umask to 373 --
113File permission : 404
114Directory permission : 404
115-- Setting umask to 374 --
116File permission : 402
117Directory permission : 403
118-- Setting umask to 375 --
119File permission : 402
120Directory permission : 402
121-- Setting umask to 376 --
122File permission : 400
123Directory permission : 401
124-- Setting umask to 377 --
125File permission : 400
126Directory permission : 400
127-- Setting umask to 400 --
128File permission : 266
129Directory permission : 377
130-- Setting umask to 401 --
131File permission : 266
132Directory permission : 376
133-- Setting umask to 402 --
134File permission : 264
135Directory permission : 375
136-- Setting umask to 403 --
137File permission : 264
138Directory permission : 374
139-- Setting umask to 404 --
140File permission : 262
141Directory permission : 373
142-- Setting umask to 405 --
143File permission : 262
144Directory permission : 372
145-- Setting umask to 406 --
146File permission : 260
147Directory permission : 371
148-- Setting umask to 407 --
149File permission : 260
150Directory permission : 370
151-- Setting umask to 410 --
152File permission : 266
153Directory permission : 367
154-- Setting umask to 411 --
155File permission : 266
156Directory permission : 366
157-- Setting umask to 412 --
158File permission : 264
159Directory permission : 365
160-- Setting umask to 413 --
161File permission : 264
162Directory permission : 364
163-- Setting umask to 414 --
164File permission : 262
165Directory permission : 363
166-- Setting umask to 415 --
167File permission : 262
168Directory permission : 362
169-- Setting umask to 416 --
170File permission : 260
171Directory permission : 361
172-- Setting umask to 417 --
173File permission : 260
174Directory permission : 360
175-- Setting umask to 420 --
176File permission : 246
177Directory permission : 357
178-- Setting umask to 421 --
179File permission : 246
180Directory permission : 356
181-- Setting umask to 422 --
182File permission : 244
183Directory permission : 355
184-- Setting umask to 423 --
185File permission : 244
186Directory permission : 354
187-- Setting umask to 424 --
188File permission : 242
189Directory permission : 353
190-- Setting umask to 425 --
191File permission : 242
192Directory permission : 352
193-- Setting umask to 426 --
194File permission : 240
195Directory permission : 351
196-- Setting umask to 427 --
197File permission : 240
198Directory permission : 350
199-- Setting umask to 430 --
200File permission : 246
201Directory permission : 347
202-- Setting umask to 431 --
203File permission : 246
204Directory permission : 346
205-- Setting umask to 432 --
206File permission : 244
207Directory permission : 345
208-- Setting umask to 433 --
209File permission : 244
210Directory permission : 344
211-- Setting umask to 434 --
212File permission : 242
213Directory permission : 343
214-- Setting umask to 435 --
215File permission : 242
216Directory permission : 342
217-- Setting umask to 436 --
218File permission : 240
219Directory permission : 341
220-- Setting umask to 437 --
221File permission : 240
222Directory permission : 340
223-- Setting umask to 440 --
224File permission : 226
225Directory permission : 337
226-- Setting umask to 441 --
227File permission : 226
228Directory permission : 336
229-- Setting umask to 442 --
230File permission : 224
231Directory permission : 335
232-- Setting umask to 443 --
233File permission : 224
234Directory permission : 334
235-- Setting umask to 444 --
236File permission : 222
237Directory permission : 333
238-- Setting umask to 445 --
239File permission : 222
240Directory permission : 332
241-- Setting umask to 446 --
242File permission : 220
243Directory permission : 331
244-- Setting umask to 447 --
245File permission : 220
246Directory permission : 330
247-- Setting umask to 450 --
248File permission : 226
249Directory permission : 327
250-- Setting umask to 451 --
251File permission : 226
252Directory permission : 326
253-- Setting umask to 452 --
254File permission : 224
255Directory permission : 325
256-- Setting umask to 453 --
257File permission : 224
258Directory permission : 324
259-- Setting umask to 454 --
260File permission : 222
261Directory permission : 323
262-- Setting umask to 455 --
263File permission : 222
264Directory permission : 322
265-- Setting umask to 456 --
266File permission : 220
267Directory permission : 321
268-- Setting umask to 457 --
269File permission : 220
270Directory permission : 320
271-- Setting umask to 460 --
272File permission : 206
273Directory permission : 317
274-- Setting umask to 461 --
275File permission : 206
276Directory permission : 316
277-- Setting umask to 462 --
278File permission : 204
279Directory permission : 315
280-- Setting umask to 463 --
281File permission : 204
282Directory permission : 314
283-- Setting umask to 464 --
284File permission : 202
285Directory permission : 313
286-- Setting umask to 465 --
287File permission : 202
288Directory permission : 312
289-- Setting umask to 466 --
290File permission : 200
291Directory permission : 311
292-- Setting umask to 467 --
293File permission : 200
294Directory permission : 310
295-- Setting umask to 470 --
296File permission : 206
297Directory permission : 307
298-- Setting umask to 471 --
299File permission : 206
300Directory permission : 306
301-- Setting umask to 472 --
302File permission : 204
303Directory permission : 305
304-- Setting umask to 473 --
305File permission : 204
306Directory permission : 304
307-- Setting umask to 474 --
308File permission : 202
309Directory permission : 303
310-- Setting umask to 475 --
311File permission : 202
312Directory permission : 302
313-- Setting umask to 476 --
314File permission : 200
315Directory permission : 301
316-- Setting umask to 477 --
317File permission : 200
318Directory permission : 300
319-- Setting umask to 500 --
320File permission : 266
321Directory permission : 277
322-- Setting umask to 501 --
323File permission : 266
324Directory permission : 276
325-- Setting umask to 502 --
326File permission : 264
327Directory permission : 275
328-- Setting umask to 503 --
329File permission : 264
330Directory permission : 274
331-- Setting umask to 504 --
332File permission : 262
333Directory permission : 273
334-- Setting umask to 505 --
335File permission : 262
336Directory permission : 272
337-- Setting umask to 506 --
338File permission : 260
339Directory permission : 271
340-- Setting umask to 507 --
341File permission : 260
342Directory permission : 270
343-- Setting umask to 510 --
344File permission : 266
345Directory permission : 267
346-- Setting umask to 511 --
347File permission : 266
348Directory permission : 266
349-- Setting umask to 512 --
350File permission : 264
351Directory permission : 265
352-- Setting umask to 513 --
353File permission : 264
354Directory permission : 264
355-- Setting umask to 514 --
356File permission : 262
357Directory permission : 263
358-- Setting umask to 515 --
359File permission : 262
360Directory permission : 262
361-- Setting umask to 516 --
362File permission : 260
363Directory permission : 261
364-- Setting umask to 517 --
365File permission : 260
366Directory permission : 260
367-- Setting umask to 520 --
368File permission : 246
369Directory permission : 257
370-- Setting umask to 521 --
371File permission : 246
372Directory permission : 256
373-- Setting umask to 522 --
374File permission : 244
375Directory permission : 255
376-- Setting umask to 523 --
377File permission : 244
378Directory permission : 254
379-- Setting umask to 524 --
380File permission : 242
381Directory permission : 253
382-- Setting umask to 525 --
383File permission : 242
384Directory permission : 252
385-- Setting umask to 526 --
386File permission : 240
387Directory permission : 251
388-- Setting umask to 527 --
389File permission : 240
390Directory permission : 250
391-- Setting umask to 530 --
392File permission : 246
393Directory permission : 247
394-- Setting umask to 531 --
395File permission : 246
396Directory permission : 246
397-- Setting umask to 532 --
398File permission : 244
399Directory permission : 245
400-- Setting umask to 533 --
401File permission : 244
402Directory permission : 244
403-- Setting umask to 534 --
404File permission : 242
405Directory permission : 243
406-- Setting umask to 535 --
407File permission : 242
408Directory permission : 242
409-- Setting umask to 536 --
410File permission : 240
411Directory permission : 241
412-- Setting umask to 537 --
413File permission : 240
414Directory permission : 240
415-- Setting umask to 540 --
416File permission : 226
417Directory permission : 237
418-- Setting umask to 541 --
419File permission : 226
420Directory permission : 236
421-- Setting umask to 542 --
422File permission : 224
423Directory permission : 235
424-- Setting umask to 543 --
425File permission : 224
426Directory permission : 234
427-- Setting umask to 544 --
428File permission : 222
429Directory permission : 233
430-- Setting umask to 545 --
431File permission : 222
432Directory permission : 232
433-- Setting umask to 546 --
434File permission : 220
435Directory permission : 231
436-- Setting umask to 547 --
437File permission : 220
438Directory permission : 230
439-- Setting umask to 550 --
440File permission : 226
441Directory permission : 227
442-- Setting umask to 551 --
443File permission : 226
444Directory permission : 226
445-- Setting umask to 552 --
446File permission : 224
447Directory permission : 225
448-- Setting umask to 553 --
449File permission : 224
450Directory permission : 224
451-- Setting umask to 554 --
452File permission : 222
453Directory permission : 223
454-- Setting umask to 555 --
455File permission : 222
456Directory permission : 222
457-- Setting umask to 556 --
458File permission : 220
459Directory permission : 221
460-- Setting umask to 557 --
461File permission : 220
462Directory permission : 220
463-- Setting umask to 560 --
464File permission : 206
465Directory permission : 217
466-- Setting umask to 561 --
467File permission : 206
468Directory permission : 216
469-- Setting umask to 562 --
470File permission : 204
471Directory permission : 215
472-- Setting umask to 563 --
473File permission : 204
474Directory permission : 214
475-- Setting umask to 564 --
476File permission : 202
477Directory permission : 213
478-- Setting umask to 565 --
479File permission : 202
480Directory permission : 212
481-- Setting umask to 566 --
482File permission : 200
483Directory permission : 211
484-- Setting umask to 567 --
485File permission : 200
486Directory permission : 210
487-- Setting umask to 570 --
488File permission : 206
489Directory permission : 207
490-- Setting umask to 571 --
491File permission : 206
492Directory permission : 206
493-- Setting umask to 572 --
494File permission : 204
495Directory permission : 205
496-- Setting umask to 573 --
497File permission : 204
498Directory permission : 204
499-- Setting umask to 574 --
500File permission : 202
501Directory permission : 203
502-- Setting umask to 575 --
503File permission : 202
504Directory permission : 202
505-- Setting umask to 576 --
506File permission : 200
507Directory permission : 201
508-- Setting umask to 577 --
509File permission : 200
510Directory permission : 200
511-- Setting umask to 600 --
512File permission : 066
513Directory permission : 177
514-- Setting umask to 601 --
515File permission : 066
516Directory permission : 176
517-- Setting umask to 602 --
518File permission : 064
519Directory permission : 175
520-- Setting umask to 603 --
521File permission : 064
522Directory permission : 174
523-- Setting umask to 604 --
524File permission : 062
525Directory permission : 173
526-- Setting umask to 605 --
527File permission : 062
528Directory permission : 172
529-- Setting umask to 606 --
530File permission : 060
531Directory permission : 171
532-- Setting umask to 607 --
533File permission : 060
534Directory permission : 170
535-- Setting umask to 610 --
536File permission : 066
537Directory permission : 167
538-- Setting umask to 611 --
539File permission : 066
540Directory permission : 166
541-- Setting umask to 612 --
542File permission : 064
543Directory permission : 165
544-- Setting umask to 613 --
545File permission : 064
546Directory permission : 164
547-- Setting umask to 614 --
548File permission : 062
549Directory permission : 163
550-- Setting umask to 615 --
551File permission : 062
552Directory permission : 162
553-- Setting umask to 616 --
554File permission : 060
555Directory permission : 161
556-- Setting umask to 617 --
557File permission : 060
558Directory permission : 160
559-- Setting umask to 620 --
560File permission : 046
561Directory permission : 157
562-- Setting umask to 621 --
563File permission : 046
564Directory permission : 156
565-- Setting umask to 622 --
566File permission : 044
567Directory permission : 155
568-- Setting umask to 623 --
569File permission : 044
570Directory permission : 154
571-- Setting umask to 624 --
572File permission : 042
573Directory permission : 153
574-- Setting umask to 625 --
575File permission : 042
576Directory permission : 152
577-- Setting umask to 626 --
578File permission : 040
579Directory permission : 151
580-- Setting umask to 627 --
581File permission : 040
582Directory permission : 150
583-- Setting umask to 630 --
584File permission : 046
585Directory permission : 147
586-- Setting umask to 631 --
587File permission : 046
588Directory permission : 146
589-- Setting umask to 632 --
590File permission : 044
591Directory permission : 145
592-- Setting umask to 633 --
593File permission : 044
594Directory permission : 144
595-- Setting umask to 634 --
596File permission : 042
597Directory permission : 143
598-- Setting umask to 635 --
599File permission : 042
600Directory permission : 142
601-- Setting umask to 636 --
602File permission : 040
603Directory permission : 141
604-- Setting umask to 637 --
605File permission : 040
606Directory permission : 140
607-- Setting umask to 640 --
608File permission : 026
609Directory permission : 137
610-- Setting umask to 641 --
611File permission : 026
612Directory permission : 136
613-- Setting umask to 642 --
614File permission : 024
615Directory permission : 135
616-- Setting umask to 643 --
617File permission : 024
618Directory permission : 134
619-- Setting umask to 644 --
620File permission : 022
621Directory permission : 133
622-- Setting umask to 645 --
623File permission : 022
624Directory permission : 132
625-- Setting umask to 646 --
626File permission : 020
627Directory permission : 131
628-- Setting umask to 647 --
629File permission : 020
630Directory permission : 130
631-- Setting umask to 650 --
632File permission : 026
633Directory permission : 127
634-- Setting umask to 651 --
635File permission : 026
636Directory permission : 126
637-- Setting umask to 652 --
638File permission : 024
639Directory permission : 125
640-- Setting umask to 653 --
641File permission : 024
642Directory permission : 124
643-- Setting umask to 654 --
644File permission : 022
645Directory permission : 123
646-- Setting umask to 655 --
647File permission : 022
648Directory permission : 122
649-- Setting umask to 656 --
650File permission : 020
651Directory permission : 121
652-- Setting umask to 657 --
653File permission : 020
654Directory permission : 120
655-- Setting umask to 660 --
656File permission : 006
657Directory permission : 117
658-- Setting umask to 661 --
659File permission : 006
660Directory permission : 116
661-- Setting umask to 662 --
662File permission : 004
663Directory permission : 115
664-- Setting umask to 663 --
665File permission : 004
666Directory permission : 114
667-- Setting umask to 664 --
668File permission : 002
669Directory permission : 113
670-- Setting umask to 665 --
671File permission : 002
672Directory permission : 112
673-- Setting umask to 666 --
674File permission : 000
675Directory permission : 111
676-- Setting umask to 667 --
677File permission : 000
678Directory permission : 110
679-- Setting umask to 670 --
680File permission : 006
681Directory permission : 107
682-- Setting umask to 671 --
683File permission : 006
684Directory permission : 106
685-- Setting umask to 672 --
686File permission : 004
687Directory permission : 105
688-- Setting umask to 673 --
689File permission : 004
690Directory permission : 104
691-- Setting umask to 674 --
692File permission : 002
693Directory permission : 103
694-- Setting umask to 675 --
695File permission : 002
696Directory permission : 102
697-- Setting umask to 676 --
698File permission : 000
699Directory permission : 101
700-- Setting umask to 677 --
701File permission : 000
702Directory permission : 100
703-- Setting umask to 700 --
704File permission : 066
705Directory permission : 077
706-- Setting umask to 701 --
707File permission : 066
708Directory permission : 076
709-- Setting umask to 702 --
710File permission : 064
711Directory permission : 075
712-- Setting umask to 703 --
713File permission : 064
714Directory permission : 074
715-- Setting umask to 704 --
716File permission : 062
717Directory permission : 073
718-- Setting umask to 705 --
719File permission : 062
720Directory permission : 072
721-- Setting umask to 706 --
722File permission : 060
723Directory permission : 071
724-- Setting umask to 707 --
725File permission : 060
726Directory permission : 070
727-- Setting umask to 710 --
728File permission : 066
729Directory permission : 067
730-- Setting umask to 711 --
731File permission : 066
732Directory permission : 066
733-- Setting umask to 712 --
734File permission : 064
735Directory permission : 065
736-- Setting umask to 713 --
737File permission : 064
738Directory permission : 064
739-- Setting umask to 714 --
740File permission : 062
741Directory permission : 063
742-- Setting umask to 715 --
743File permission : 062
744Directory permission : 062
745-- Setting umask to 716 --
746File permission : 060
747Directory permission : 061
748-- Setting umask to 717 --
749File permission : 060
750Directory permission : 060
751-- Setting umask to 720 --
752File permission : 046
753Directory permission : 057
754-- Setting umask to 721 --
755File permission : 046
756Directory permission : 056
757-- Setting umask to 722 --
758File permission : 044
759Directory permission : 055
760-- Setting umask to 723 --
761File permission : 044
762Directory permission : 054
763-- Setting umask to 724 --
764File permission : 042
765Directory permission : 053
766-- Setting umask to 725 --
767File permission : 042
768Directory permission : 052
769-- Setting umask to 726 --
770File permission : 040
771Directory permission : 051
772-- Setting umask to 727 --
773File permission : 040
774Directory permission : 050
775-- Setting umask to 730 --
776File permission : 046
777Directory permission : 047
778-- Setting umask to 731 --
779File permission : 046
780Directory permission : 046
781-- Setting umask to 732 --
782File permission : 044
783Directory permission : 045
784-- Setting umask to 733 --
785File permission : 044
786Directory permission : 044
787-- Setting umask to 734 --
788File permission : 042
789Directory permission : 043
790-- Setting umask to 735 --
791File permission : 042
792Directory permission : 042
793-- Setting umask to 736 --
794File permission : 040
795Directory permission : 041
796-- Setting umask to 737 --
797File permission : 040
798Directory permission : 040
799-- Setting umask to 740 --
800File permission : 026
801Directory permission : 037
802-- Setting umask to 741 --
803File permission : 026
804Directory permission : 036
805-- Setting umask to 742 --
806File permission : 024
807Directory permission : 035
808-- Setting umask to 743 --
809File permission : 024
810Directory permission : 034
811-- Setting umask to 744 --
812File permission : 022
813Directory permission : 033
814-- Setting umask to 745 --
815File permission : 022
816Directory permission : 032
817-- Setting umask to 746 --
818File permission : 020
819Directory permission : 031
820-- Setting umask to 747 --
821File permission : 020
822Directory permission : 030
823-- Setting umask to 750 --
824File permission : 026
825Directory permission : 027
826-- Setting umask to 751 --
827File permission : 026
828Directory permission : 026
829-- Setting umask to 752 --
830File permission : 024
831Directory permission : 025
832-- Setting umask to 753 --
833File permission : 024
834Directory permission : 024
835-- Setting umask to 754 --
836File permission : 022
837Directory permission : 023
838-- Setting umask to 755 --
839File permission : 022
840Directory permission : 022
841-- Setting umask to 756 --
842File permission : 020
843Directory permission : 021
844-- Setting umask to 757 --
845File permission : 020
846Directory permission : 020
847-- Setting umask to 760 --
848File permission : 006
849Directory permission : 017
850-- Setting umask to 761 --
851File permission : 006
852Directory permission : 016
853-- Setting umask to 762 --
854File permission : 004
855Directory permission : 015
856-- Setting umask to 763 --
857File permission : 004
858Directory permission : 014
859-- Setting umask to 764 --
860File permission : 002
861Directory permission : 013
862-- Setting umask to 765 --
863File permission : 002
864Directory permission : 012
865-- Setting umask to 766 --
866File permission : 000
867Directory permission : 011
868-- Setting umask to 767 --
869File permission : 000
870Directory permission : 010
871-- Setting umask to 770 --
872File permission : 006
873Directory permission : 007
874-- Setting umask to 771 --
875File permission : 006
876Directory permission : 006
877-- Setting umask to 772 --
878File permission : 004
879Directory permission : 005
880-- Setting umask to 773 --
881File permission : 004
882Directory permission : 004
883-- Setting umask to 774 --
884File permission : 002
885Directory permission : 003
886-- Setting umask to 775 --
887File permission : 002
888Directory permission : 002
889-- Setting umask to 776 --
890File permission : 000
891Directory permission : 001
892-- Setting umask to 777 --
893File permission : 000
894Directory permission : 000
895Done
896