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

SCM Repository

[smlnj] Diff of /sml/trunk/runtime/c-libs/win32-io/win32-io.c
ViewVC logotype

Diff of /sml/trunk/runtime/c-libs/win32-io/win32-io.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 3467, Thu Dec 10 20:20:54 2009 UTC revision 3468, Sat Dec 12 03:05:05 2009 UTC
# Line 377  Line 377 
377   *   *
378   * generic routine for writing n byes from buf to handle starting at offset   * generic routine for writing n byes from buf to handle starting at offset
379   *   *
380     * A maximum print size is used to avoid exceeding maximum buffer thresholds
381     * with handles corresponding to console output. Technically, we can use
382     * larger values, but this will also support several other devices that have
383     * output limits if we decide to open up the range of supported file handles
384     * through interop.
385   */   */
386    #define MAX_PRINT_SIZE 30000
387  ml_val_t _ml_win32_IO_write_buf(ml_state_t *msp, ml_val_t arg)  ml_val_t _ml_win32_IO_write_buf(ml_state_t *msp, ml_val_t arg)
388  {  {
389    HANDLE h = (HANDLE) WORD_MLtoC(REC_SEL(arg,0));    HANDLE h = (HANDLE) WORD_MLtoC(REC_SEL(arg,0));
390    ml_val_t buf = REC_SEL(arg,1);    ml_val_t buf = REC_SEL(arg,1);
391    size_t nbytes = REC_SELINT(arg,2);    size_t nbytes = REC_SELINT(arg,2);
392    Byte_t *start = (Byte_t *) (STR_MLtoC(buf) + REC_SELINT(arg, 3));    Byte_t *start = (Byte_t *) (STR_MLtoC(buf) + REC_SELINT(arg, 3));
393    DWORD n;    DWORD n, remaining, total;
394      char *buffer = PTR_MLtoC(void,start);
395      int err;
396    
397  #ifdef WIN32_DEBUG  #ifdef WIN32_DEBUG
398    SayDebug("_ml_win32_IO_write_buf: handle is %x\n", (unsigned int) h);    SayDebug("_ml_win32_IO_write_buf: handle is %x\n", (unsigned int) h);
399  #endif  #endif
400    if (WriteFile(h,PTR_MLtoC(void,start),nbytes,&n,NULL)) {  
401      remaining = nbytes;
402      total = 0;
403    
404      while (remaining > 0) {
405          nbytes = min (MAX_PRINT_SIZE, remaining);
406              if (WriteFile(h,buffer,nbytes,&n,NULL)) {
407  #ifdef WIN32_DEBUG  #ifdef WIN32_DEBUG
408      if (n == 0)      if (n == 0)
409        SayDebug("_ml_win32_IO_write_buf: eof on device\n");        SayDebug("_ml_win32_IO_write_buf: eof on device\n");
410  #endif  #endif
411      return INT_CtoML(n);                  total += n;
412    }                  remaining -= n;
413                    buffer += n;
414              } else {
415  #ifdef WIN32_DEBUG  #ifdef WIN32_DEBUG
416    SayDebug("_ml_win32_IO_write_buf: failing\n");    SayDebug("_ml_win32_IO_write_buf: failing\n");
417  #endif  #endif
418    return RAISE_SYSERR(msp,-1);    return RAISE_SYSERR(msp,-1);
419  }  }
420      }
421    
422      return INT_CtoML(total);
423    }
424    
425  ml_val_t _ml_win32_IO_write_vec(ml_state_t *msp, ml_val_t arg)  ml_val_t _ml_win32_IO_write_vec(ml_state_t *msp, ml_val_t arg)
426  {  {

Legend:
Removed from v.3467  
changed lines
  Added in v.3468

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