ats_void_type
atslib_mkdir_exn (
  ats_ptr_type path, ats_mode_type mode
) {
  int err = mkdir ((char*)path, mode) ;
  if (err < 0) {
    perror ("mkdir"); ats_exit_errmsg (1, "exit(ATS): [mkdir] failed.\n") ;
  } // end of [if]
  return ;
} /* end of [atslib_mkdir_exn] */
ats_ptr_type
atspre_vsprintf (
  const ats_ptr_type fmt, ats_ref_type ap0
) {
  char *res = (char*)atspre_vsprintf_size (ATSPRE_SPRINTF_GUESS, fmt, ap0) ;
  if (!res) {
    ats_exit_errmsg (1, "exit(ATS): [atspre_vsprintf] failed.\n") ;
  } // end of [if]
  return res ;
} // end of [atspre_vsprintf]
ats_void_type
atslib_chmod_exn (
  ats_ptr_type path, ats_mode_type mode
) {
  int err = chmod ((char*)path, mode) ;
  if (err < 0) {
    perror ("chmod"); ats_exit_errmsg (1, "exit(ATS): [chmod] failed.\n") ;
  } // end of [if]
  return ;
} /* end of [atslib_chmod_exn] */
ats_void_type
atslib_fstat_exn (
  ats_int_type fd, ats_ptr_type buf
) {
  int err ;
  err = fstat (fd, (ats_stat_type*)buf) ;
  if (err < 0) {
    perror ("fstat"); ats_exit_errmsg (1, "exit(ATS): [fstat] failed.\n") ;
  } // end of [if]
  return ;
} /* end of [atslib_fstat_exn] */
ats_void_type
atslib_stat_exn (
  ats_ptr_type name, ats_ptr_type buf
) {
  int err ;
  err = stat ((char*)name, (ats_stat_type*)buf) ;
  if (err < 0) {
    perror ("stat"); ats_exit_errmsg (1, "exit(ATS): [stat] failed.\n") ;
  } // end of [if]
  return ;
} /* end of [atslib_stat_exn] */
ats_void_type
atslib_mpf_inp_str_exn (
  ats_mpf_ptr_type x
, ats_ptr_type file
, ats_int_type base
) {
  size_t n = mpf_inp_str(x, (FILE*)file, base) ;
  if (n == 0) {
    ats_exit_errmsg (1, "exit(ATS): [mpf_inp_str] failed.\n") ;
  } // end of [if]
  return ;
} // end of [atslib_mpf_inp_str_exn]
ats_void_type
atslib_mpq_out_str_exn (
  ats_ptr_type file
, ats_int_type base
, const ats_mpq_ptr_type x
) {
  size_t n = mpq_out_str((FILE*)file, base, (mpq_ptr)x) ;
  if (n == 0) {
    ats_exit_errmsg (1, "exit(ATS): [mpq_out_str] failed.\n") ;
  } // end of [if]
  return ;
} // end of [atslib_mpq_out_str_exn]
ats_void_type
atspre_assert_prerrf (
  ats_bool_type assertion, ats_ptr_type fmt, ...
) {
  int err ;
  va_list ap ;

  if (!assertion) { /* assertion is false */
    va_start(ap, fmt) ;
    err = vfprintf(stderr, (char*)fmt, ap) ;
    va_end(ap) ;
    if (err < 0) {
      ats_exit_errmsg (
        err, "[atspre_assert_prerrf]: prerrf failed\n"
      ) ;
    } else {
      ats_exit_errmsg (1, "[atspre_assert_prerrf]: assert failed\n") ;
    }
  } /* end of [if] */

  return ;
} /* end of [atspre_assert_prerrf] */
示例#9
0
ats_ptr_type
ats_malloc_gc (
  ats_size_type n
) {
  ats_ptr_type *p ;
/*
  fprintf (stderr, "ats_malloc_gc: n = %i\n", n) ;
*/
  p = malloc(n) ;
/*
  fprintf (stderr, "ats_malloc_gc: p = %p(%li)\n", p, p) ;
*/
  if (!p) ats_exit_errmsg(1, "exit(ATS): [ats_malloc_gc] failed.\n") ;
  return p ;
} // end of [ats_malloc_gc]
示例#10
0
ats_ptr_type
ats_realloc_gc (
  const ats_ptr_type p, ats_size_type bsz
) {
  ats_ptr_type p_new ;
/*
  fprintf (stderr, "ats_realloc_gc: p = %p and bsz = %i\n", p, bsz) ;
*/
  p_new = realloc(p, bsz) ;
/*
  fprintf (stderr, "ats_realloc_gc: p_new = %p(%li)\n", p_new, p_new) ;
*/
  if (!p_new) ats_exit_errmsg(1, "exit(ATS): [ats_realloc_gc] failed.\n") ;
  return p_new ;
} // end of [ats_realloc_gc]
ats_int_type
atslib_fork_and_exec_and_wait
  (ats_clo_ptr_type f_child) {
  pid_t pid ;
  int status ;

  pid = fork () ;
  if (pid < 0) {
    ats_exit_errmsg (errno, "Exit: [fork] failed.\n") ;
  }
  if (pid > 0) { wait (&status) ; return status ; }
  /* this is the child */
  ((ats_void_type (*)(ats_clo_ptr_type))f_child->closure_fun)(f_child) ;
  exit (0) ;
} // end of [atslib_fork_and_exec_and_wait]
ats_size_type
atslib_fildes_read_all_exn (ats_int_type arg0, ats_ref_type arg1, ats_size_type arg2) {
/* local vardec */
ATSlocal (ats_size_type, tmp30) ;
ATSlocal (ats_ssize_type, tmp31) ;
ATSlocal (ats_bool_type, tmp32) ;
// ATSlocal_void (tmp33) ;

__ats_lab_atslib_fildes_read_all_exn:
tmp31 = atslib_fildes_read_all_err (arg0, arg1, arg2) ;
tmp32 = atspre_gte_ssize1_int1 (tmp31, 0) ;
if (tmp32) {
tmp30 = ats_castfn_mac(ats_size_type, tmp31) ;
} else {
/* tmp33 = */ atslib_perror (ATSstrcst("read")) ;
/* tmp30 = */ ats_exit_errmsg (EXIT_FAILURE, ATSstrcst("exit(ATS): [read_all] failed\n")) ;
} /* end of [if] */
return (tmp30) ;
} /* end of [atslib_fildes_read_all_exn] */
ats_void_type
atslib_fork_exec_cloptr_exn
  (ats_ptr_type f_child) {
  pid_t pid ;
  pid = fork () ;
//
  if (pid < 0) {
    ats_exit_errmsg (errno, "exit(ATS): [fork] failed.\n") ;
  } // end of [if]
//
  /* this is the parent */
  if (pid > 0) { ATS_FREE (f_child) ; return ; }
//  
  /* this is the child */
  ((ats_void_type (*)(ats_clo_ptr_type))((ats_clo_ptr_type)f_child)->closure_fun)(f_child) ;
  _exit (0) ; /* no need to flush STDIN, STDOUT and STDERR */
//
  return ; /* deadcode */
} /* end of [atslib_fork_exec_cloptr] */
ats_void_type
atslib_fildes_write_all_exn (ats_int_type arg0, ats_ref_type arg1, ats_size_type arg2) {
/* local vardec */
// ATSlocal_void (tmp49) ;
ATSlocal (ats_int_type, tmp50) ;
ATSlocal (ats_ssize_type, tmp51) ;
ATSlocal (ats_bool_type, tmp53) ;
ATSlocal (ats_bool_type, tmp54) ;
ATSlocal (ats_int_type, tmp55) ;
ATSlocal (ats_int_type, tmp56) ;
ATSlocal (ats_bool_type, tmp57) ;
// ATSlocal_void (tmp58) ;

__ats_lab_atslib_fildes_write_all_exn:
/* ats_int_type tmp50 ; */
tmp50 = 0 ;
tmp51 = atslib_fildes_write_all_err (arg0, arg1, arg2) ;
tmp53 = atspre_gte_ssize1_int1 (tmp51, 0) ;
if (tmp53) {
tmp54 = atspre_lt_size1_size1 (ats_castfn_mac(ats_size_type, tmp51), arg2) ;
if (tmp54) {
tmp55 = atspre_iadd (tmp50, 1) ;
tmp50 = tmp55 ;
} else {
/* empty */
} /* end of [if] */
} else {
tmp56 = atspre_iadd (tmp50, 1) ;
tmp50 = tmp56 ;
} /* end of [if] */
tmp57 = atspre_gt_int_int (tmp50, 0) ;
if (tmp57) {
/* tmp58 = */ atslib_perror (ATSstrcst("write")) ;
/* tmp49 = */ ats_exit_errmsg (EXIT_FAILURE, ATSstrcst("exit(ATS): [write_all]: failed\n")) ;
} else {
/* empty */
} /* end of [if] */
return /* (tmp49) */ ;
} /* end of [atslib_fildes_write_all_exn] */
ats_pid_type
atslib_fork_exn () {
/* local vardec */
ATSlocal (ats_pid_type, tmp0) ;
ATSlocal (ats_pid_type, tmp1) ;
ATSlocal (ats_bool_type, tmp2) ;
// ATSlocal_void (tmp3) ;
ATSlocal (ats_int_type, tmp4) ;
// ATSlocal_void (tmp5) ;

__ats_lab_atslib_fork_exn:
tmp1 = atslib_fork_err () ;
tmp2 = atspre_lt_int_int (ats_castfn_mac(ats_int_type, tmp1), 0) ;
if (tmp2) {
tmp4 = atslib_errno_get () ;
/* tmp5 = */ atslib_perror (ATSstrcst("fork")) ;
/* tmp3 = */ ats_exit_errmsg (ats_castfn_mac(ats_int_type, tmp4), ATSstrcst("exit(ATS): [fork] failed.\n")) ;
} else {
/* empty */
} /* end of [if] */
tmp0 = tmp1 ;
return (tmp0) ;
} /* end of [atslib_fork_exn] */
ats_int_type
atslib_fork_exec_and_wait_cloptr_exn
  (ats_ptr_type f_child) {
  pid_t pid ;
  int status ;
//
  pid = fork () ;
//
  if (pid < 0) {
    ats_exit_errmsg (errno, "exit(ATS): [fork] failed.\n") ;
  } // end of [if]
//
  if (pid > 0) {
    ATS_FREE (f_child) ;
    if (wait (&status) < 0) return -1 ;
    return status ;
  } // end of [if]
//
  /* this is the child */
  ((ats_void_type (*)(ats_clo_ptr_type))((ats_clo_ptr_type)f_child)->closure_fun)(f_child) ;
  _exit (0) ; /* no need to flush STDIN, STDOUT and STDERR */
//
  return 0 ; /* deadcode */
} /* atslib_fork_exec_and_wait_cloptr_exn */