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