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/stat/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //usr/share/emscripten/tests/stat/test_mknod.c
#include <assert.h>
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <utime.h>
#include <sys/stat.h>
#include <sys/types.h>

void setup() {
  mkdir("folder-readonly", 0555);
}

void cleanup() {
  unlink("mknod-file");
  unlink("mknod-device");
  rmdir("folder");
  rmdir("folder-readonly");
}

void test() {
  int err;
  struct stat s;

  //
  // mknod
  // mknod is _extremely_ unportable for anything other
  // than a FIFO. so, the tests are disabled when running
  // natively as they'd be utterly inconsistent.
  //
#ifdef __EMSCRIPTEN__

  // mknod a folder
  err = mknod("mknod-folder", S_IFDIR | 0777, 0);
  assert(err);
  assert(errno == EINVAL);

  // mknod fifo
  err = mknod("mknod-fifo", S_IFIFO | 0777, 0);
  assert(err);
  assert(errno == EPERM);

  // mknod a file
  err = mknod("mknod-file", S_IFREG | 0777, 0);
  assert(!err);
  memset(&s, 0, sizeof s);
  stat("mknod-file", &s);
  assert(S_ISREG(s.st_mode));

  // mknod a character device
  err = mknod("mknod-device", S_IFCHR | 0777, 123);
  assert(!err);
  memset(&s, 0, sizeof s);
  stat("mknod-device", &s);
  assert(S_ISCHR(s.st_mode));

#endif

  //
  // mkdir
  //
  // can't mkdir in a readonly dir
  err = mkdir("folder-readonly/subfolder", 0777);
  assert(err);
  assert(errno == EACCES);

  // regular creation
  err = mkdir("folder", 0777);
  assert(!err);
  memset(&s, 0, sizeof s);
  stat("folder", &s);
  assert(S_ISDIR(s.st_mode));

  // try to re-create the same folder
  err = mkdir("folder", 0777);
  assert(err);
  assert(errno == EEXIST);

  puts("success");
}

int main() {
  atexit(cleanup);
  signal(SIGABRT, cleanup);
  setup();
  test();
  return EXIT_SUCCESS;
}

VaKeR 2022