1997-09-03 07:38:02 -07:00
|
|
|
/***********************************************************************/
|
|
|
|
/* */
|
|
|
|
/* Objective Caml */
|
|
|
|
/* */
|
|
|
|
/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */
|
|
|
|
/* */
|
|
|
|
/* Copyright 1996 Institut National de Recherche en Informatique et */
|
1999-11-17 10:59:06 -08:00
|
|
|
/* en Automatique. All rights reserved. This file is distributed */
|
2001-12-07 05:41:02 -08:00
|
|
|
/* under the terms of the GNU Library General Public License, with */
|
|
|
|
/* the special exception on linking described in file ../../LICENSE. */
|
1997-09-03 07:38:02 -07:00
|
|
|
/* */
|
|
|
|
/***********************************************************************/
|
|
|
|
|
|
|
|
/* $Id$ */
|
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <mlvalues.h>
|
|
|
|
#include <memory.h>
|
|
|
|
#include <signals.h>
|
|
|
|
#include "unixsupport.h"
|
|
|
|
|
2001-08-28 07:47:48 -07:00
|
|
|
CAMLprim value unix_write(value fd, value buf, value vofs, value vlen)
|
1997-09-03 07:38:02 -07:00
|
|
|
{
|
|
|
|
long ofs, len, written;
|
|
|
|
DWORD numbytes, numwritten;
|
|
|
|
BOOL ret;
|
|
|
|
char iobuf[UNIX_BUFFER_SIZE];
|
|
|
|
HANDLE h = Handle_val(fd);
|
|
|
|
|
|
|
|
Begin_root (buf);
|
|
|
|
ofs = Long_val(vofs);
|
|
|
|
len = Long_val(vlen);
|
|
|
|
written = 0;
|
|
|
|
while (len > 0) {
|
|
|
|
numbytes = len > UNIX_BUFFER_SIZE ? UNIX_BUFFER_SIZE : len;
|
2000-11-23 05:45:03 -08:00
|
|
|
memmove (iobuf, &Byte(buf, ofs), numbytes);
|
1997-09-03 07:38:02 -07:00
|
|
|
enter_blocking_section();
|
|
|
|
ret = WriteFile(h, iobuf, numbytes, &numwritten, NULL);
|
|
|
|
leave_blocking_section();
|
|
|
|
if (! ret) {
|
2001-08-28 07:47:48 -07:00
|
|
|
win32_maperr(GetLastError());
|
1997-09-03 07:38:02 -07:00
|
|
|
uerror("write", Nothing);
|
|
|
|
}
|
|
|
|
written += numwritten;
|
|
|
|
ofs += numwritten;
|
|
|
|
len -= numwritten;
|
|
|
|
}
|
|
|
|
End_roots();
|
|
|
|
return Val_long(written);
|
|
|
|
}
|