Ejemplo n.º 1
0
/* _lib7_P_FileSys_fchown : (int * word * word) -> Void
 *                         fd     uid    gid
 *
 * Change owner and group of file given a file descriptor for it.
 */
lib7_val_t _lib7_P_FileSys_fchown (lib7_state_t *lib7_state, lib7_val_t arg)
{
    int	            fd =  REC_SELINT (arg, 0);
    uid_t           uid = REC_SELWORD(arg, 1);
    gid_t           gid = REC_SELWORD(arg, 2);
    int		    status;

    status = fchown (fd, uid, gid);

    CHECK_RETURN_UNIT(lib7_state, status)

} /* end of _lib7_P_FileSys_fchown */
Ejemplo n.º 2
0
/* _ml_P_Process_waitpid : int * word -> int * int * int
 *
 * Wait for child processes to stop or terminate
 */
ml_val_t _ml_P_Process_waitpid (ml_state_t *msp, ml_val_t arg)
{
    int       pid;
    int       status, how, val;
    ml_val_t  r;

    pid = waitpid(REC_SELINT(arg, 0), &status, REC_SELWORD(arg, 1));
    if (pid < 0)
	return RAISE_SYSERR(msp, pid);

    if (WIFEXITED(status)) {
	how = 0;
	val = WEXITSTATUS(status);
    }
    else if (WIFSIGNALED(status)) {
	how = 1;
	val = WTERMSIG(status);
    }
    else if (WIFSTOPPED(status)) {
	how = 2;
	val = WSTOPSIG(status);
    }
    else
	return RAISE_ERROR(msp, "unknown child status");

    REC_ALLOC3(msp, r, INT_CtoML(pid), INT_CtoML(how), INT_CtoML(val));

    return r;

} /* end of _ml_P_Process_waitpid */
Ejemplo n.º 3
0
/* _lib7_P_FileSys_mkdir : (String * word) -> Void
 *                        name     mode
 *
 * Make a directory
 */
lib7_val_t _lib7_P_FileSys_mkdir (lib7_state_t *lib7_state, lib7_val_t arg)
{
    lib7_val_t	    path = REC_SEL(arg, 0);
    mode_t	    mode = REC_SELWORD(arg, 1);
    int		    status;

    status = mkdir (STR_LIB7toC(path), mode);

    CHECK_RETURN_UNIT(lib7_state, status)

} /* end of _lib7_P_FileSys_mkdir */
Ejemplo n.º 4
0
/* _lib7_P_IO_fcntl_sfd : int * word -> Void
 *
 * Set the close-on-exec flag associated with the file descriptor.
 */
lib7_val_t _lib7_P_IO_fcntl_sfd (lib7_state_t *lib7_state, lib7_val_t arg)
{
    int             status;
    int             fd0 = REC_SELINT(arg, 0);
    Word_t          flag = REC_SELWORD(arg, 1);

    /*  do { */	/* Backed out 2010-02-26 CrT: See discussion at bottom of src/runtime/c-libs/lib7-socket/connect.c	*/

    status = fcntl(fd0, F_SETFD, flag);

    /*  } while (status < 0 && errno == EINTR);	*/	/* Restart if interrupted by a SIGALRM or SIGCHLD or whatever.	*/

    CHECK_RETURN_UNIT(lib7_state,status)
}
Ejemplo n.º 5
0
/* _ml_P_FileSys_access : (string * word) -> bool
 *                         name     access_mode
 *
 * Determine accessibility of a file.
 */
ml_val_t _ml_P_FileSys_access (ml_state_t *msp, ml_val_t arg)
{
    ml_val_t	    path = REC_SEL(arg, 0);
    mode_t	    mode = REC_SELWORD(arg, 1);
    int		    sts;

    sts = access (STR_MLtoC(path), mode);

    if (sts == 0)
        return ML_true;
    else
        return ML_false;

} /* end of _ml_P_FileSys_access */