VaKeR CYBER ARMY
Logo of a company Server : Apache/2.4.41 (Ubuntu)
System : Linux absol.cf 5.4.0-198-generic #218-Ubuntu SMP Fri Sep 27 20:18:53 UTC 2024 x86_64
User : www-data ( 33)
PHP Version : 7.4.33
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Directory :  /usr/share/emscripten/tests/filesystem/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //usr/share/emscripten/tests/filesystem/bad_lookup.cpp
#include <cerrno>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>

#include <fcntl.h>
#include <sys/stat.h>
#include <unistd.h>

using std::endl;

//============================================================================
// :: Helpers

namespace
{
  //--------------------------------------------------------------------------
  // Helper to create an empty file with the given path.
  void touch(const std::string& path, const mode_t mode)
  {
    std::cout
      << "Touching file: " << path << " with mode=" << std::oct << mode
      << std::dec <<  endl;

    const int fd = ::open(path.c_str(), O_CREAT | O_WRONLY, mode);
    if (fd == -1) {
      const int error = errno;
      std::cout
        << "Failed to touch file using open: " << path << "; errno=" << error
        << ";" << std::strerror(error) << endl;
    }
    else {
      ::close(fd);
    }
  }

  //--------------------------------------------------------------------------
  // Stats the given path and prints the mode.  Returns true if the path
  // exists; false otherwise.
  bool exists(const std::string& path)
  {
    struct ::stat path_stat;
    if (::lstat(path.c_str(), &path_stat) != 0) {
      const int error = errno;
      if (error == ENOENT) {
        // Only bother logging if something other than the path not existing
        // went wrong.
        std::cout
          << "Failed to lstat path: " << path << "; errno=" << error << "; "
          << std::strerror(error) << endl;
      }
      return false;
    }

    std::cout
      << std::oct << "Mode for path=" << path << ": " << path_stat.st_mode
      << std::dec << endl;
    return true;
  }
}

//============================================================================
// :: Entry Point

int main()
{
  touch("file1", 0667);
  if (not exists("file1")) {
    std::cout << "Failed to create path: file1" << endl;
    return 1;
  }
  if (exists("file1/dir")) {
    std::cout << "Path should not exists: file1/dir" << endl;
    return 1;
  }

  touch("file2", 0676);
  if (not exists("file2")) {
    std::cout << "Failed to create path: file2" << endl;
    return 1;
  }
  if (exists("file2/dir")) {
    std::cout << "Path should not exists: file2/dir" << endl;
    return 1;
  }

  touch("file3", 0766);
  if (not exists("file3")) {
    std::cout << "Failed to create path: file3" << endl;
    return 1;
  }
  if (exists("file3/dir")) {
    std::cout << "Path should not exists: file3/dir" << endl;
    return 1;
  }

  std::cout << "ok." << endl;
  return 0;
}


VaKeR 2022