Home My Page Projects Code Snippets Project Openings SML/NJ
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

SCM Repository

[smlnj] View of /sml/branches/num64/runtime/c-libs/posix-io/fcntl_l_64.c
ViewVC logotype

View of /sml/branches/num64/runtime/c-libs/posix-io/fcntl_l_64.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5219 - (download) (as text) (annotate)
Thu May 30 13:17:43 2019 UTC (2 months, 3 weeks ago) by jhr
File size: 1672 byte(s)
  Switch 64-bit versions of Posix FileSys and IO operations to directly
  pass 64-bit integers to/from the runtime (instead of using two 32-bit
  words).  Have also changed the representation of file timestamps
  to a 64-bit number of nanoseconds (instead of 32-bit seconds).
  The plan is to make these versions the default.
/* fcntl_l_64.c
 *
 *   Using 64-bit position values represented as 32-bit pairs.
 *
 * COPYRIGHT (c) 2019 The Fellowship of SML/NJ (http://www.smlnj.org)
 * All rights reserved.
 */

#include "ml-unixdep.h"
#include <fcntl.h>
#include "ml-base.h"
#include "ml-values.h"
#include "ml-objects.h"
#include "ml-c.h"
#include "cfun-proto-list.h"

/* _ml_P_IO_fcntl_l_64 : int * int * flock_rep -> flock_rep
 *
 * where
 *
 *    flock_rep = int * int * Position.int * Position.int * int
 *
 * Handle record locking.
 */
ml_val_t _ml_P_IO_fcntl_l_64 (ml_state_t *msp, ml_val_t arg)
{
    int              fd = REC_SELINT(arg, 0);
    int              cmd = REC_SELINT(arg, 1);
    ml_val_t         flock_rep = REC_SEL(arg, 2), obj;
    ml_val_t         start = REC_SEL(flock_rep, 2);
    ml_val_t         length = REC_SEL(flock_rep, 3);
    struct flock     flock;
    int              sts;

    flock.l_type = REC_SELINT(flock_rep, 0);
    flock.l_whence = REC_SELINT(flock_rep, 1);
    flock.l_start = (off_t)INT64_MLtoC(start);
    flock.l_len = (off_t)INT64_MLtoC(length);

    sts = fcntl(fd, cmd, &flock);

    if (sts < 0) {
	return RAISE_SYSERR(msp, sts);
    }

  /* allocate the 64-bit start and length values */
    INT64_ALLOC(msp, start, flock.l_start)
    INT64_ALLOC(msp, length, flock.l_len)

    ML_AllocWrite (msp, 0, MAKE_DESC (DTAG_record, 5));
    ML_AllocWrite (msp, 1, INT_CtoML(flock.l_type));
    ML_AllocWrite (msp, 2, INT_CtoML(flock.l_whence));
    ML_AllocWrite (msp, 3, start);
    ML_AllocWrite (msp, 4, length);
    ML_AllocWrite (msp, 5, INT_CtoML(flock.l_pid));
    obj = ML_Alloc (msp, 5);

    return obj;

} /* end of _ml_P_IO_fcntl_l_64 */

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0