SPVM-Sys

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN

      shutdown
      socketpair
      setsockopt
      truncate
      flock
      print
      say
      printf
      seek
      utime
      chown
      open
      fdopen
      sysopen
      say
      kill
      pipe
       

0.500 2023-11-17
  [New Features and Incompatible Changes]

Changes  view on Meta::CPAN

      + static method printf : int ($stream, $format : string, $args : object[]);
      + static method read : int ($stream : Sys::IO::FileStream, $buf : mutable string, $count : int, $buf_offset : int = 0);
      + static method rewinddir : void ($dirp : Sys::IO::DirStream);
      + static method readdir : Sys::IO::Dirent ($dirp : Sys::IO::DirStream);
      + static method seek : int ($stream : Sys::IO::FileStream, $offset : long, $whence : int);
      + static method sysseek : long ($fd : int, $offset : long, $whence : int);
      + static method tell : long ($stream : Sys::IO::FileStream);
      + static method telldir : long ($dirp : Sys::IO::DirStream);
      + static method lstat : Sys::IO::Stat ($path : string);
      + static method utime : int ($atime : long, $mtime : long, $filename : string);
      + static method chown : int ($owner : int, $group : int, $path : string);
  [Deprecation]
    * The following methods in the Sys::IO class are deprecated. Use the readline method in the Sys class.
      
      static method readline : string ($stream : Sys::IO::FileStream);
      
0.486 2023-09-06
  [Bug Fix]
    * Some bugs are fixed: The connect, getaddrinfo, and getnameinfo have not return correct return values.
  [New Features]
    * The Sys::Socket::Util class is added.

Changes  view on Meta::CPAN

        [System Error]unlink failed:%s. The \"%s\" file can't be removed"      
  [Test Improvement]
    * Improved tests of Sys::IO::Stat.
  [Incompatible Changes]
    * Removed the readlink method in the Sys class and the readlinkp method in the Sys::IO class because I don't know the Windows/Unix portable way to allocate memory yet.
    * Removed the unlinkp method in the SPVM::Sys::IO class. This logic is moved to the unlink method in the Sys class and fixed the return value.
    * Removed the renamep method in the SPVM::Sys::IO class. This logic is moved to the rename method in the Sys class.
    * Removed the symlinkp method in the SPVM::Sys::IO class. This logic is moved to the symlink method in the Sys class.
    * Removed the readlinkp method in the SPVM::Sys::IO class. This logic is moved to the readlink method in the Sys class.
    * Removed the chmodp method in the SPVM::Sys::IO class. This logic is moved to the chmod method in the Sys class.
    * Removed the chownp method in the SPVM::Sys::IO class. This logic is moved to the chown method in the Sys class.
    * Removed the utimep method in the SPVM::Sys::IO class. This logic is moved to the utime method in the Sys class.
    * Removed the timesp method in the SPVM::Sys::Time class. This logic is moved to the times method in the Sys class.
    * Removed the statp method in the SPVM::Sys::IO::Stat class. This logic is moved to the stat method in the Sys class.
    * Removed the lstatp method in the SPVM::Sys::IO::Stat class. This logic is moved to the lstat method in the Sys class.
    * Remvoed the argument of the new method in the Sys::IO::Stat class.
    * Removed the is_windows method in the Sys class. This is used from the Sys::OS class.
    * Removed the get_osname method in the Sys::OS class.
    * Renamed the get_osname method in the Sys class to osname.
  [New Features]
    * Added the Sys::IO::Windows class.

Changes  view on Meta::CPAN

      - "[System Error]open failed:%s"
      - "[System Error]fopen failed:%s"
      - "[System Error]mkdir failed:%s"
      - "[System Error]rmdir failed:%s"
      - "[System Error]unlink failed:%s"
      - "[System Error]rename failed:%s"
      - "[System Error]realpath failed:%s"
      - "[System Error]_fullpath failed:%s"
      - "[System Error]chdir failed:%s"
      - "[System Error]chmod failed:%s"
      - "[System Error]chown failed:%s"
      - "[System Error]truncate failed:%s"
      - "[System Error]symlink failed:%s"
      - "[System Error]readlink failed:%s"
      - "[System Error]opendir failed:%s"
      - "[System Error]utime failed:%s"
      
      [After]
      + "[System Error]open failed:%s. The \"%s\" file can't be opend"
      + "[System Error]fopen failed:%s. The \"%s\" file can't be opend"
      + "[System Error]mkdir failed:%s. The \"%s\" directory can't be created"
      + "[System Error]rmdir failed:%s. The \"%s\" directory can't be removed"
      + "[System Error]unlink failed:%s. The \"%s\" directory can't be removed"name
      + "[System Error]rename failed:%s. The \"%s\" file can't be renamed to the \"%s\" file"
      + "[System Error]realpath failed:%s. The \"%s\" file can't be resolved"
      + "[System Error]_fullpath failed:%s. The \"%s\" file can't be resolved"
      + "[System Error]chdir failed:%s. The current directory can't be changed to the \"%s\" directory"
      + "[System Error]chmod failed:%s. The permission of the \"%s\" file can't be changed"
      + "[System Error]chown failed:%s. The owner/group of the \"%s\" file can't be changed"
      + "[System Error]truncate failed:%s. The \"%s\" file can't be truncated"
      + "[System Error]symlink failed:%s. The symbolic link from \"%s\" to \"%s\" can't be created"
      + "[System Error]readlink failed:%s. The reading of the symbolic link of the \"%s\" file failed"
      + "[System Error]opendir failed:%s. The \"%s\" directory can't be opened", dir
      + "[System Error]utime failed:%s. The access and modification times of the \"%s\" file can't be changed"
    * Unified an exception message
      [Before]
      in this system
      [After]
      on this system

lib/SPVM/Sys.pm  view on Meta::CPAN

=head2 chmod

C<static method chmod : void ($mode :int, $file : string);>

Changes the permissions of the file $file to the permission $mode.

Exceptions:

Exceptions thrown by L<Sys::IO#chmod|SPVM::Sys::IO/"chmod"> method could be thrown.

=head2 chown

C<static method chown : void ($owner : int, $group : int, $file : string);>

Changes the owner and the group of the file $file to $owner and $group.

Exceptions:

Exceptions thrown by L<Sys::IO#chown|SPVM::Sys::IO/"chown"> method could be thrown.

=head2 readlink

C<static method readlink : int ($file : string);>

Returns the content of the symbolic link file $file.

In Windows thie method calls L<Sys::IO::Windows#readlink|SPVM::Sys::IO::Windows/"readlink"> method , otherwise calls L<Sys::IO#readlink|SPVM::Sys::IO/"readlink"> method .

Exceptions:

lib/SPVM/Sys.spvm  view on Meta::CPAN

  }
  
  static method chdir : void ($dir : string) {
    Sys::IO->chdir($dir);
  }
  
  static method chmod : void ($mode :int, $file : string) {
    Sys::IO->chmod($file, $mode);
  }
  
  static method chown : void ($owner : int, $group : int, $file : string) {
    Sys::IO->chown($file, $owner, $group);
  }
  
  static method opendir : void ($dir_stream_ref : Sys::IO::DirStream[], $dir : string) {
    
    my $dh = Sys::IO->opendir($dir);
    
    $dir_stream_ref->[0] = $dh;
  }
  
  static method closedir : void ($dir_stream : Sys::IO::DirStream) {

lib/SPVM/Sys/IO.c  view on Meta::CPAN

  if (status == -1) {
    env->die(env, stack, "[System Error]chmod() failed:%s. $path is \"%s\".", env->strerror_nolen(env, stack, errno), path, __func__, FILE_NAME, __LINE__);
    return SPVM_NATIVE_C_BASIC_TYPE_ID_ERROR_SYSTEM_CLASS;
  }
  
  stack[0].ival = status;
  
  return 0;
}

int32_t SPVM__Sys__IO__chown(SPVM_ENV* env, SPVM_VALUE* stack) {
  
#if defined(_WIN32)
  env->die(env, stack, "Sys::IO#chown method is not supported in this system(defined(_WIN32)).", __func__, FILE_NAME, __LINE__);
  return SPVM_NATIVE_C_BASIC_TYPE_ID_ERROR_NOT_SUPPORTED_CLASS;
#else
  void* obj_path = stack[0].oval;
  if (!obj_path) {
    return env->die(env, stack, "The path $path must be defined.", __func__, FILE_NAME, __LINE__);
  }
  const char* path = env->get_chars(env, stack, obj_path);
  
  int32_t owner = stack[1].ival;
  
  int32_t group = stack[2].ival;
  
  int32_t status = chown(path, owner, group);
  if (status == -1) {
    env->die(env, stack, "[System Error]chown() failed:%s. $path is \"%s\".", env->strerror_nolen(env, stack, errno), path, __func__, FILE_NAME, __LINE__);
    return SPVM_NATIVE_C_BASIC_TYPE_ID_ERROR_SYSTEM_CLASS;
  }
  
  stack[0].ival = status;
  
  return 0;
#endif
}

int32_t SPVM__Sys__IO__symlink(SPVM_ENV* env, SPVM_VALUE* stack) {

lib/SPVM/Sys/IO.pm  view on Meta::CPAN

Calls the L<chmod|https://linux.die.net/man/2/chmod> function and return its return value.

See L<Sys::IO::Constant|SPVM::Sys::IO::Constant> about constant values given to the mode $mode.

Exceptions:

$path must be defined. Otherwise an exception is thrown.

If the chmod function failed, an exception is thrown with C<eval_error_id> set to the basic type ID of the L<Error::System|SPVM::Error::System> class.

=head2 chown

C<static method chown : int ($path : string, $owner : int, $group : int);>

Calls the L<chown|https://linux.die.net/man/2/chown> and return its return value.

Exceptions:

$path must be defined. Otherwise an exception is thrown.

If the chown function failed, an exception is thrown with C<eval_error_id> set to the basic type ID of the L<Error::System|SPVM::Error::System> class.

=head2 symlink

C<static method symlink : int ($oldpath : string, $newpath : string);>

Calls the L<symlink|https://linux.die.net/man/2/symlink> function and return its return value.

Exceptions:

$oldpath must be defined. Otherwise an exception is thrown.

lib/SPVM/Sys/IO.spvm  view on Meta::CPAN

  native static method _getdcwd : mutable string ($drive : int, $buffer : mutable string, $maxlen : int);
  
  native static method realpath : mutable string ($path : string, $resolved_path : mutable string);
  
  native static method _fullpath : mutable string ($absPath : mutable string, $relPath : string, $maxLength : int);
  
  native static method chdir : int ($path : string);
  
  native static method chmod : int ($path : string, $mode :int);
  
  native static method chown : int ($path : string, $owner : int, $group : int);
  
  native static method symlink : int ($oldpath : string, $newpath : string);
  
  native static method readlink : int ($path : string, $buf : mutable string, $bufsiz : int);
  
  native static method opendir : Sys::IO::DirStream ($dir : string);
  
  native static method closedir : int ($dirp : Sys::IO::DirStream);
  
  native static method readdir : Sys::IO::Dirent ($dirp : Sys::IO::DirStream);

t/Sys-IO.t  view on Meta::CPAN

}

ok(SPVM::TestCase::Sys::IO->chdir);

{
  my $tmp_dir = File::Temp->newdir;
  ok(SPVM::TestCase::Sys::IO->chmod("$tmp_dir"));
}

if ($^O eq 'MSWin32') {
  eval { SPVM::Sys::IO->chown(undef, 0, 0) };
  like($@, qr|not supported|);
}
else {
  my $tmp_dir = File::Temp->newdir;
  ok(SPVM::TestCase::Sys::IO->chown("$tmp_dir"));
}

if ($^O eq 'MSWin32') {
  eval { SPVM::Sys::IO->symlink(undef, undef) };
  like($@, qr|not supported|);
}
else {
  my $tmp_dir = File::Temp->newdir;
  ok(SPVM::TestCase::Sys::IO->symlink("$tmp_dir"));
}

t/lib/SPVM/TestCase/Sys/IO.spvm  view on Meta::CPAN

    {
      eval { Sys::IO->chmod("$file/not_found.txt", 0755); };
      unless (Fn->contains($@, "not_found.txt")) {
        return 0;
      }
    }
    
    return 1;
  }

  static method chown : int ($tmp_dir : string) {
    
    my $test_dir_ftest = &TEST_DIR_FTEST;
    
    {
      my $file = "$tmp_dir/foo.txt";
      my $stream = Sys::IO->fopen($file, "w");
      
      unless (Sys->f($file)) {
        return 0;
      }
      
      Sys::IO->fclose($stream);
      
      my $status = Sys::IO->chown($file, -1, -1);
      
      unless ($status == 0) {
        return 0;
      }
      
      {
        eval { Sys::IO->chown("$file/not_found.txt", -1, -1); };
        unless (Fn->contains($@, "not_found.txt")) {
          return 0;
        }
      }
    }
    
    {
      my $file = "$tmp_dir/foo.txt";
      my $stream = Sys::IO->fopen($file, "w");
      
      unless (Sys->f($file)) {
        return 0;
      }
      
      Sys::IO->fclose($stream);
      
      Sys->chown(-1, -1, $file);
      
      {
        eval { Sys->chown(-1, -1, "$file/not_found.txt"); };
        unless (Fn->contains($@, "not_found.txt")) {
          return 0;
        }
      }
    }
    return 1;
  }

  static method symlink : int ($tmp_dir : string) {
    



( run in 0.928 second using v1.01-cache-2.11-cpan-5511b514fd6 )