簡體   English   中英

文件屬性不起作用

[英]File Attributes doesn't work

我正在嘗試創建一個只讀文件,然后使用“文件屬性”檢查它是否可讀可寫,但是它始終返回可讀且可寫的文件。

我究竟做錯了什么?

  use strict;
  use Fcntl;
  sysopen(DATA, "file.txt", O_CREAT | O_RDONLY );
  print DATA "Bob\n";
  close (DATA); 

  my $file='file.txt';
  my (@description,$size);
  if (-e $file)
   {
    push @description, 'readable' if (-r _);
    push @description, 'writable' if (-w _);
    push @description, (($size = -s _)) ? "$size bytes" : 'empty';
    print "$file is ", join(', ',@description),"\n";
    } 

在這里打印什么:
在此處輸入圖片說明

有人能幫助我嗎?

您的進程的umask值以及默認的PERMS值0666為您提供了可寫文件。 更改umask或向sysopen添加PERMS參數。 例如,要獲取一個只讀文件,默認umask為0022時,您可以執行以下操作:

sysopen(DATA, "file.txt", O_CREAT | O_RDONLY, 0466 );

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM